forked from sloria/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
window.lua
80 lines (65 loc) · 2.24 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
-- window management
-- define window movement/resize operation mappings
local arrowMap = {
Up = { half = { 0, 0, 1,.5}, movement = { 0,-20}, complement = "Left", resize = "Shorter" },
Down = { half = { 0,.5, 1,.5}, movement = { 0, 20}, complement = "Right", resize = "Taller" },
Left = { half = { 0, 0,.5, 1}, movement = {-20, 0}, complement = "Down", resize = "Thinner" },
Right = { half = {.5, 0,.5, 1}, movement = { 20, 0}, complement = "Up", resize = "Wider" },
}
-- compose screen quadrants from halves
local function quadrant(t1, t2)
return {t1[1] + t2[1], t1[2] + t2[2], .5, .5}
end
-- move and/or resize windows
local function rect(rect)
return function()
undo:push()
local win = fw()
if win then win:move(rect) end
end
end
-- center and enlarge current window; hold to maximize
bind(hyper, "space", rect({1/8, 1/8, 3/4, 3/4}), nil, rect({0, 0, 1, 1}))
-- arrow-based window movement/resize operations
hs.fnutils.each({"Left", "Right", "Up", "Down"}, function(arrow)
bind(hyper, arrow, -- set to screen halves; hold for quadrants
rect(arrowMap[arrow].half),
nil,
rect(quadrant(arrowMap[arrow].half, arrowMap[arrowMap[arrow].complement].half))
)
bind({"ctrl", "cmd"}, arrow, -- move windows incrementally
rect(arrowMap[arrow].movement),
nil,
rect(arrowMap[arrow].movement)
)
bind({"ctrl", "alt"}, arrow, -- move windows by grid increments
function() undo:push(); hs.grid['pushWindow'..arrow](fw()) end
)
bind({"ctrl", "alt", "shift"}, arrow, -- resize windows by grid increments
function() undo:push(); hs.grid['resizeWindow'..arrowMap[arrow].resize](fw()) end
)
end)
-- window grid configuration
hs.grid.setGrid("6x4")
hs.grid.setMargins({0, 0})
bind(hyper, '/', function()
local gridSize = hs.grid.getGrid()
hs.grid.setGrid("3x3")
hs.grid.show(function() hs.grid.setGrid(gridSize) end)
end)
-- undo for window operations
undo = {}
function undo:push()
local win = fw()
if win and not undo[win:id()] then
self[win:id()] = win:frame()
end
end
function undo:pop()
local win = fw()
if win and self[win:id()] then
win:setFrame(self[win:id()])
self[win:id()] = nil
end
end
bind({"ctrl", "alt"}, "z", function() undo:pop() end)