Skip to content

Commit

Permalink
Added options to enabled/disable the behaviour when a window moved or…
Browse files Browse the repository at this point in the history
… the screen changes (#308)
  • Loading branch information
morja authored Aug 7, 2024
1 parent 8c1667e commit 9256098
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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

0 comments on commit 9256098

Please sign in to comment.