-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouseCursor.lua
53 lines (45 loc) · 1.31 KB
/
mouseCursor.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local function mouseCursor(wp)
local function getWindowUnderMouse()
local mousePos = hs.mouse.absolutePosition()
local windows = hs.window.visibleWindows()
for _, window in ipairs(windows) do
local frame = window:frame()
if
(mousePos.x >= frame.x)
and (mousePos.x <= frame.x + frame.w)
and (mousePos.y >= frame.y)
and (mousePos.y <= frame.y + frame.h)
then
return window
end
end
return nil
end
local function focusMouseWindow()
local windowUnderMouse = getWindowUnderMouse()
if windowUnderMouse then
windowUnderMouse:focus()
end
end
local function moveToNextScreen()
local screen = hs.mouse.getCurrentScreen()
local nextScreen = screen:next()
local rect = nextScreen:fullFrame()
local center = hs.geometry.rectMidPoint(rect)
hs.mouse.absolutePosition(center)
focusMouseWindow()
end
local function moveToPreviousScreen()
local screen = hs.mouse.getCurrentScreen()
local nextScreen = screen:previous()
local rect = nextScreen:fullFrame()
local center = hs.geometry.rectMidPoint(rect)
hs.mouse.absolutePosition(center)
focusMouseWindow()
end
return {
moveToNextScreen = moveToNextScreen,
moveToPreviousScreen = moveToPreviousScreen,
}
end
return mouseCursor