-
Notifications
You must be signed in to change notification settings - Fork 1
/
windowhotkeys.lua
98 lines (89 loc) · 2.55 KB
/
windowhotkeys.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
--
-- Key defs
--
local cmdCtrl = {"cmd", "ctrl"}
local cmdAltCtrl = {"cmd", "alt", "ctrl"}
-- Window hints
hs.hotkey.bind(cmdCtrl, "E", hs.hints.windowHints)
-- Grid setup
local marginX = 0
local marginY = 0
local gridWidth = 8
local gridHeight = 4
hs.grid.MARGINX = marginX
hs.grid.MARGINY = marginY
hs.grid.GRIDWIDTH = gridWidth
hs.grid.GRIDHEIGHT = gridHeight
local focusedWindow = function()
return hs.window.focusedWindow()
end
-- Maximize window
hs.hotkey.bind(cmdAltCtrl, "M", function()
hs.grid.maximizeWindow(focusedWindow())
end)
-- center window
hs.hotkey.bind(cmdAltCtrl, "C", function()
focusedWindow():centerOnScreen()
end)
-- left 1/2
hs.hotkey.bind(cmdAltCtrl, "Left", function()
focusedWindow():moveToUnit'[0,0,50,100]'
end)
-- right 1/2
hs.hotkey.bind(cmdAltCtrl, "Right", function()
focusedWindow():moveToUnit'[50,0,100,100]'
end)
-- top 1/2
hs.hotkey.bind(cmdAltCtrl, "Up", function()
focusedWindow():moveToUnit'[0,0,100,50]'
end)
-- bottom 1/2
hs.hotkey.bind(cmdAltCtrl, "Down", function()
focusedWindow():moveToUnit'[0,50,100,100]'
end)
-- top left
hs.hotkey.bind(cmdAltCtrl, "1", function()
focusedWindow():moveToUnit'[0,0,50,50]'
end)
-- top right
hs.hotkey.bind(cmdAltCtrl, "2", function()
focusedWindow():moveToUnit'[50,0,100,50]'
end)
-- bottom left
hs.hotkey.bind(cmdAltCtrl, "3", function()
focusedWindow():moveToUnit'[0,50,50,100]'
end)
-- bottom right
hs.hotkey.bind(cmdAltCtrl, "4", function()
focusedWindow():moveToUnit'[50,50,100,100]'
end)
-- move to previous screen
hs.hotkey.bind(cmdAltCtrl, "P", function()
local win = focusedWindow()
win:moveToScreen(win:screen():previous())
end)
-- move to next screen
hs.hotkey.bind(cmdAltCtrl, "N", function()
local win = focusedWindow()
win:moveToScreen(win:screen():next())
end)
-- resize by grid hints
hs.hotkey.bind(cmdCtrl, "W", hs.grid.toggleShow)
local resizeFocusedWindow = function(increment)
local win = focusedWindow()
local f = win:frame()
f.x = f.x - increment
f.y = f.y - increment
f.w = f.w + increment * 2
f.h = f.h + increment * 2
win:setFrameInScreenBounds(f)
end
local resizeIncrement = 20
-- increase size
hs.hotkey.bind(cmdAltCtrl, "=", function()
resizeFocusedWindow(resizeIncrement)
end)
-- decrease size
hs.hotkey.bind(cmdAltCtrl, "-", function()
resizeFocusedWindow(-resizeIncrement)
end)