diff --git a/Source/MouseFollowsFocus.spoon/init.lua b/Source/MouseFollowsFocus.spoon/init.lua index a6646483..7fdb813a 100644 --- a/Source/MouseFollowsFocus.spoon/init.lua +++ b/Source/MouseFollowsFocus.spoon/init.lua @@ -55,7 +55,7 @@ function obj:start() }) self.window_filter:subscribe({ hs.window.filter.windowFocused - }, function(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() @@ -91,6 +91,13 @@ function obj:updateMouse(window) local current_pos = hs.geometry(hs.mouse.absolutePosition()) local frame = window:frame() if not current_pos:inside(frame) then + local current_screen = hs.mouse.getCurrentScreen() + local window_screen = window:screen() + if current_screen and window_screen and current_screen ~= window_screen then + -- avoid getting the mouse stuck on a screen corner by moving through the center of each screen + hs.mouse.absolutePosition(current_screen:frame().center) + hs.mouse.absolutePosition(window_screen:frame().center) + end hs.mouse.absolutePosition(frame.center) end end diff --git a/Spoons/MouseFollowsFocus.spoon.zip b/Spoons/MouseFollowsFocus.spoon.zip index 8903c115..4e7eeea6 100644 Binary files a/Spoons/MouseFollowsFocus.spoon.zip and b/Spoons/MouseFollowsFocus.spoon.zip differ