-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitchWindow.lua
58 lines (47 loc) · 1.34 KB
/
switchWindow.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
54
55
56
57
58
local function switchWindow(wp)
local currentWindowIndex = 1
local visibleWindows = {}
local function updateVisibleWindows()
local focusedWindow = hs.window.focusedWindow()
if not focusedWindow then
return
end
local currentScreen = focusedWindow:screen()
local allWindows = hs.window.visibleWindows()
visibleWindows = {}
for _, window in ipairs(allWindows) do
if window:isVisible() and not window:isMinimized() and window:screen() == currentScreen then
table.insert(visibleWindows, window)
end
end
end
local function switchWindowForward()
updateVisibleWindows()
if #visibleWindows == 0 then
return
end
currentWindowIndex = currentWindowIndex + 1
if currentWindowIndex > #visibleWindows then
currentWindowIndex = 1
end
local nextWindow = visibleWindows[currentWindowIndex]
nextWindow:focus()
end
local function switchWindowBackward()
updateVisibleWindows()
if #visibleWindows == 0 then
return
end
currentWindowIndex = currentWindowIndex - 1
if currentWindowIndex < 1 then
currentWindowIndex = #visibleWindows
end
local prevWindow = visibleWindows[currentWindowIndex]
prevWindow:focus()
end
return {
forward = switchWindowForward,
backward = switchWindowBackward,
}
end
return switchWindow