-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindow.lua
148 lines (128 loc) · 3.29 KB
/
window.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
dofile (zwm.spoonPath.."utilities.lua")
-- Returns a table of all the applications, minus corner cases
function get_applications()
local applications = hs.application.runningApplications()
local not_applications = {}
local n=#applications
-- Certain apps show up after the filter but should not.
local edge_cases = {"Notification Center", "Finder", "Übersicht", "Hammerspoon"}
-- Finder glitching
for k, v in pairs(applications) do
local win = v:allWindows()
if table_count(win) < 1 then
not_applications[k] = true
elseif string_match(v:name(), edge_cases) then
not_applications[k] = true
end
end
for i=1,n do
if not_applications[i] then
applications[i]=nil
end
end
local ordered = {}
local i = 1
for k, v in pairs(applications) do
ordered [i] = v
i = i+1
end
return ordered
end
-- Tiles all windows according to the tiling setting
function window_tile()
local tile = config["window_management"]["mode"]
local win = hs.window.focusedWindow()
local f = win:frame()
local gap = config["window_management"]["gap"]
local screen = hs.screen.mainScreen():frame()
local bar_offset = config["bar"]["height"]
bar_offset = 0
if tile == "monocle" then
local new_frame = hs.geometry.rect(screen._x + gap, screen._y + gap + bar_offset, screen._w - (2 * gap), screen._h - (2 * gap) - bar_offset)
if new_frame ~= f then
win:setFrame(new_frame, 0)
end
end
end
-- Switches to the next application and then tiles if necessary
function application_next(front)
-- monocle
current_app = hs.application.frontmostApplication()
local next = {}
local applications = get_applications()
for i, v in ipairs(applications) do
if v:name() == current_app:name() then
if i == table_count(applications) then
if front then
next = applications[1]
break
else
next = applications[i - 1]
break
end
elseif i == 1 then
if front then
next = applications[i + 1]
break
else
next = applications[table_count(applications)]
break
end
else
if front then
next = applications[i + 1]
break
else
next = applications[i - 1]
break
end
end
end
end
next:activate()
window_tile()
end
-- Switches to the next window for the frontMost application
-- TODO: next window of any application, duplicate windows alt-tab
function window_next(front)
current_app = hs.application.frontmostApplication()
local win = current_app:focusedWindow()
local current_windows = current_app:allWindows()
local new_win = nil
local desktop = hs.window.desktop()
if current_app:name() == "Finder" then
-- remove desktop from list of windows
for i in ipairs(current_windows) do
if current_windows[i] == desktop then
current_windows[i] = nil
print("removed")
end
end
end
local count = table_count(current_windows)
for i in ipairs(current_windows) do
if win == current_windows[i] then
if i == count then
if front then
new_win = current_windows[1]
else
new_win = current_windows[i - 1]
end
elseif i == 1 then
if front then
new_win = current_windows[i + 1]
else
new_win = current_windows[count]
end
else
if front then
new_win = current_windows[i + 1]
else
new_win = current_windows[i - 1]
end
end
end
end
new_win:focus()
window_tile()
end