-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.lua
More file actions
342 lines (288 loc) · 10.4 KB
/
init.lua
File metadata and controls
342 lines (288 loc) · 10.4 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
-- OzzyWM (Ozzy's Window Manager)
local OzzyWM={}
OzzyWM.__index = OzzyWM
-- Metadata
OzzyWM.name = "OzzyWM"
OzzyWM.version = "1.5"
OzzyWM.author = "Özgün Çağrı AYDIN"
OzzyWM.homepage = "https://ozguncagri.com"
OzzyWM.license = "MIT - https://opensource.org/licenses/MIT"
-- 3 modification binder wrapper
OzzyWM.mod3Binder = function(key, operation)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, key, operation)
end
-- 4 modification binder wrapper
OzzyWM.mod4Binder = function(key, operation)
hs.hotkey.bind({"shift", "cmd", "alt", "ctrl"}, key, operation)
end
-- Get current window elements
OzzyWM.currentWindowAndScreenElements = function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local oneCol = max.w / 8
return win, f, screen, max, oneCol
end
-- Move window to left and set width (columnSize) to eight of screen width
OzzyWM.leftColumn = function(columnSize)
return function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
f.x = max.x
f.y = max.y
f.w = oneCol * columnSize
f.h = max.h
win:setFrame(f)
end
end
-- Move window to right and set width (columnSize) to eight of screen width
OzzyWM.rightColumn = function(columnSize)
return function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
f.x = max.x + (max.w - (oneCol * columnSize))
f.y = max.y
f.w = oneCol * columnSize
f.h = max.h
win:setFrame(f)
end
end
OzzyWM.alternateAppSwitcher = function()
-- Alternate application switcher settings
switcher = hs.window.switcher.new()
switcher.ui.onlyActiveApplication = false
switcher.ui.showTitles = false
switcher.ui.showThumbnails = false
switcher.ui.thumbnailSize = 64
switcher.ui.showSelectedThumbnail = true
switcher.ui.selectedThumbnailSize = 256
switcher.ui.showSelectedTitle = false
-- Application switcher : next item binding
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Tab", function()
switcher:next()
end)
-- Application switcher : previous item binding
hs.hotkey.bind({"shift", "cmd", "alt", "ctrl"}, "Tab", function()
switcher:previous()
end)
end
OzzyWM.numericalWindowDocker = function()
-- Expand/Shrink active window to selected column number anchoring to left side of the screen
OzzyWM.mod3Binder("1", OzzyWM.leftColumn(1))
OzzyWM.mod3Binder("2", OzzyWM.leftColumn(2))
OzzyWM.mod3Binder("3", OzzyWM.leftColumn(3))
OzzyWM.mod3Binder("4", OzzyWM.leftColumn(4))
OzzyWM.mod3Binder("5", OzzyWM.leftColumn(5))
OzzyWM.mod3Binder("6", OzzyWM.leftColumn(6))
OzzyWM.mod3Binder("7", OzzyWM.leftColumn(7))
OzzyWM.mod3Binder("8", OzzyWM.leftColumn(8))
-- Expand/Shrink active window to selected column number anchoring to right side of the screen
OzzyWM.mod4Binder("1", OzzyWM.rightColumn(1))
OzzyWM.mod4Binder("2", OzzyWM.rightColumn(2))
OzzyWM.mod4Binder("3", OzzyWM.rightColumn(3))
OzzyWM.mod4Binder("4", OzzyWM.rightColumn(4))
OzzyWM.mod4Binder("5", OzzyWM.rightColumn(5))
OzzyWM.mod4Binder("6", OzzyWM.rightColumn(6))
OzzyWM.mod4Binder("7", OzzyWM.rightColumn(7))
OzzyWM.mod4Binder("8", OzzyWM.rightColumn(8))
end
OzzyWM.windowSlider = function()
-- Slide window to top edge of the screen without resizing it
OzzyWM.mod3Binder("Up", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Move window to one screen up if it's touching top edge of current screen
if f.y == max.y then
local slidedWin = win:moveOneScreenNorth(true, true)
if slidedWin ~= nil then
slidedWin:centerOnScreen()
end
else
f.y = max.y
win:setFrame(f)
end
end)
-- Slide window to right edge of the screen without resizing it
OzzyWM.mod3Binder("Right", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Move window to one screen right if it's touching right edge of current screen
if f.x == (max.x + max.w) - f.w then
local slidedWin = win:moveOneScreenEast(true, true)
if slidedWin ~= nil then
slidedWin:centerOnScreen()
end
else
f.x = (max.x + max.w) - f.w
win:setFrame(f)
end
end)
-- Slide window to bottom edge of the screen without resizing it
OzzyWM.mod3Binder("Down", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Move window to one screen down if it's touching bottom edge of current screen
if f.y == (max.y + max.h) - f.h then
local slidedWin = win:moveOneScreenSouth(true, true)
if slidedWin ~= nil then
slidedWin:centerOnScreen()
end
else
f.y = (max.y + max.h) - f.h
win:setFrame(f)
end
end)
-- Slide window to left edge of the screen without resizing it
OzzyWM.mod3Binder("Left", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Move window to one screen left if it's touching left edge of current screen
if f.x == max.x then
local slidedWin = win:moveOneScreenWest(true, true)
if slidedWin ~= nil then
slidedWin:centerOnScreen()
end
else
f.x = max.x
win:setFrame(f)
end
end)
-- Slide window middle of the screen in x and y axis
OzzyWM.mod3Binder("Space", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
win:centerOnScreen()
end)
end
OzzyWM.windowSnapper = function()
local isWindowSnappedToLeftHalf = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.x == max.x and f.y == max.y and f.w == oneCol * 4 and f.h == max.h
end
local isWindowSnappedToLeftQuarter = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.x == max.x and f.y == max.y and f.w == oneCol * 2 and f.h == max.h
end
local isWindowSnappedToRightHalf = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.x == max.x + (max.w - (oneCol * 4)) and f.y == max.y and f.w == oneCol * 4 and f.h == max.h
end
local isWindowSnappedToRightQuarter = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.x == max.x + (max.w - (oneCol * 2)) and f.y == max.y and f.w == oneCol * 2 and f.h == max.h
end
local isWindowSnappedToTopHalf = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.y == max.y and f.x == max.x and f.w == max.w and f.h == math.floor(max.h / 2)
end
local isWindowSnappedToTopQuarter = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.y == max.y and f.x == max.x and f.w == max.w and f.h == math.floor(max.h / 4)
end
local isWindowSnappedToBottomHalf = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.y == (max.y + max.h) - f.h and f.x == max.x and f.w == max.w and f.h == math.floor(max.h / 2)
end
local isWindowSnappedToBottomQuarter = function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
return f.w == max.w and f.h == math.floor(max.h / 4) and f.y == (math.floor(max.h / 4) * 3) + max.y and f.x == max.x
end
OzzyWM.mod4Binder("Up", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Snap window to top-left or right quarter of current screen
if isWindowSnappedToLeftHalf() or isWindowSnappedToRightHalf() then
f.h = math.floor(max.h / 2)
win:setFrame(f)
return
end
-- Snap window to top quarter or left-right 1/16 of current screen
if isWindowSnappedToTopHalf() or isWindowSnappedToLeftQuarter() or isWindowSnappedToRightQuarter() then
f.h = math.floor(max.h / 4)
win:setFrame(f)
return
end
-- Snap window to top half of current screen
f.y = max.y
f.x = max.x
f.w = max.w
f.h = math.floor(max.h / 2)
win:setFrame(f)
end)
OzzyWM.mod4Binder("Right", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Snap window to top or bottom right quarter of current screen
if isWindowSnappedToTopHalf() or isWindowSnappedToBottomHalf() then
f.x = max.x + (max.w - (oneCol * 4))
f.w = oneCol * 4
win:setFrame(f)
return
end
-- Snap window to right quarter or top-bottom 1/16 of current screen
if isWindowSnappedToRightHalf() or isWindowSnappedToTopQuarter() or isWindowSnappedToBottomQuarter() then
f.x = max.x + (max.w - (oneCol * 2))
f.w = oneCol * 2
win:setFrame(f)
return
end
-- Snap window to right half of current screen
f.x = max.x + (max.w - (oneCol * 4))
f.y = max.y
f.w = oneCol * 4
f.h = max.h
win:setFrame(f)
end)
OzzyWM.mod4Binder("Down", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Snap window to bottom-left or right quarter of current screen
if isWindowSnappedToLeftHalf() or isWindowSnappedToRightHalf() then
f.y = math.floor(max.h / 2) + max.y
f.h = math.floor(max.h / 2)
win:setFrame(f)
return
end
-- Snap window to bottom quarter or left-right 1/16 of current screen
if isWindowSnappedToBottomHalf() or isWindowSnappedToLeftQuarter() or isWindowSnappedToRightQuarter() then
f.h = math.floor(max.h / 4)
f.y = (math.floor(max.h / 4) * 3) + max.y
win:setFrame(f)
return
end
-- Snap window to bottom half of current screen
f.w = max.w
f.h = math.floor(max.h / 2)
f.y = (max.y + max.h) - f.h
f.x = max.x
win:setFrame(f)
end)
OzzyWM.mod4Binder("Left", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
-- Snap window to top or bottom right quarter of current screen
if isWindowSnappedToTopHalf() or isWindowSnappedToBottomHalf() then
f.w = oneCol * 4
win:setFrame(f)
return
end
-- Snap window to left quarter of current screen
if isWindowSnappedToLeftHalf() or isWindowSnappedToTopQuarter() or isWindowSnappedToBottomQuarter() then
f.w = oneCol * 2
win:setFrame(f)
return
end
-- Snap window to left half of current screen
f.x = max.x
f.y = max.y
f.w = oneCol * 4
f.h = max.h
win:setFrame(f)
end)
end
OzzyWM.windowZoomer = function()
-- Toggles the zoom state of the window (this is effectively equivalent to clicking the green maximize/fullscreen button at the top left of a window)
OzzyWM.mod4Binder("Space", function()
local win, f, screen, max, oneCol = OzzyWM.currentWindowAndScreenElements()
win:toggleZoom()
end)
end
function OzzyWM:init()
-- Activate all hotkeys
OzzyWM.alternateAppSwitcher()
OzzyWM.numericalWindowDocker()
OzzyWM.windowSlider()
OzzyWM.windowSnapper()
OzzyWM.windowZoomer()
end
return OzzyWM