-
Notifications
You must be signed in to change notification settings - Fork 0
/
push-window.lua
79 lines (62 loc) · 2.07 KB
/
push-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
-- Push window left or right
------------------------------------------------------------------------------
local exports = {}
function push(left, div)
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local screenFrame = screen:frame()
-- Move to closest third.
local oneThirdPixelWidth = screenFrame.w / div
local windowOffsetFromScreenX = f.x - screenFrame.x
local snapNumber
if left then
snapNumber = math.floor(windowOffsetFromScreenX / oneThirdPixelWidth)
else
snapNumber = math.ceil(windowOffsetFromScreenX / oneThirdPixelWidth) + 1
snapNumber = math.min(snapNumber, div - 1)
end
print(snapNumber)
local targetX = snapNumber / div
local g = hs.geometry.unitrect(targetX, 0, 1 / div, 1)
hs.window.focusedWindow():moveToUnit(g)
end
exports.pushLeft = function()
hs.window.focusedWindow():moveToUnit(hs.layout.left50)
end
exports.pushRight = function()
hs.window.focusedWindow():moveToUnit(hs.layout.right50)
end
exports.twoThirdsLeft = function()
local g = hs.geometry.unitrect(0,0,0.6,1)
hs.window.focusedWindow():moveToUnit(g)
end
exports.twoThirdsRight = function()
-- 0.66:
-- Means github.com with repo tree view extension fits perfectly.
-- Also, it allows you to see IntelliJ with slim project tool window open and 80 char editor width.
-- Only slightly cuts into it.
local width = 0.66
local g = hs.geometry.unitrect(1-width,0,width,1)
hs.window.focusedWindow():moveToUnit(g)
end
local oneThirdWidth = 0.333
exports.oneThirdLeft = function()
local g = hs.geometry.unitrect(0, 0, oneThirdWidth, 1)
hs.window.focusedWindow():moveToUnit(g)
end
exports.oneThirdMiddle = function()
local g = hs.geometry.unitrect(oneThirdWidth * 1, 0, oneThirdWidth, 1)
hs.window.focusedWindow():moveToUnit(g)
end
exports.oneThirdRight = function()
local g = hs.geometry.unitrect(oneThirdWidth * 2, 0, oneThirdWidth, 1)
hs.window.focusedWindow():moveToUnit(g)
end
exports.pushOneThirdLeft = function()
push(true, 3)
end
exports.pushOneThirdRight = function()
push(false, 3)
end
return exports