Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to enabled/disable the behaviour #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/MouseFollowsFocus.spoon/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
"items": [
{
"def": "MouseFollowsFocus:configure(configuration)",
"desc": "Configures the spoon. There is currently nothing to configure.",
"doc": "Configures the spoon. There is currently nothing to configure.\n\nParameters:\n * configuration - :",
"desc": "Configures the spoon.",
"doc": "Configures the spoon.\n\nParameters:\n * configuration - a table containing the settings for onWindowMoved or onChangeOfScreenOnly:",
"name": "configure",
"parameters": [
" * configuration - :"
" * configuration - a table containing the settings for onWindowMoved or onChangeOfScreenOnly:"
],
"signature": "MouseFollowsFocus:configure(configuration)",
"stripped_doc": "",
Expand Down
20 changes: 16 additions & 4 deletions Source/MouseFollowsFocus.spoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ obj.version = "0.1"
obj.author = "Jason Felice <[email protected]>"
obj.homepage = "https://github.com/Hammerspoon/Spoons"
obj.license = "MIT - https://opensource.org/licenses/MIT"
obj.onChangeOfScreenOnly = false
obj.onWindowMoved = false
obj.currentWindowScreen = nil

--- MouseFollowsFocus.logger
--- Variable
Expand All @@ -25,11 +28,17 @@ obj.logger = hs.logger.new('MouseFollowsFocus')

--- MouseFollowsFocus:configure(configuration)
--- Method
--- Configures the spoon. There is currently nothing to configure.
--- Configures the spoon.
---
--- Parameters:
--- * configuration - :
--- * configuration - a table containing the settings for onWindowMoved or onChangeOfScreenOnly:
function obj:configure(configuration)
if configuration['onChangeOfScreenOnly'] then
self.onChangeOfScreenOnly = configuration['onChangeOfScreenOnly']
end
if configuration['onWindowMoved'] then
self.onWindowMoved = configuration['onWindowMoved']
end
end

--- MouseFollowsFocus:start()
Expand All @@ -46,12 +55,15 @@ function obj:start()
})
self.window_filter:subscribe({
hs.window.filter.windowFocused
}, function(window)
self:updateMouse(window)
}, function(window)
if self.onChangeOfScreenOnly and self.currentWindowScreen and self.currentWindowScreen:id() == window:screen():id() then return end
self:updateMouse(window)
self.currentWindowScreen = window:screen()
end)
self.window_filter:subscribe({
hs.window.filter.windowMoved
}, function(window)
if not self.onWindowMoved then return end
if window ~= hs.window.focusedWindow() then return end
if #hs.mouse.getButtons() ~= 0 then return end
self:updateMouse(window)
Expand Down