-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.lua
93 lines (90 loc) · 2.57 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
local current = {
direction = nil,
count = 0,
}
function windowMove(direction)
return function()
local win = hs.window.focusedWindow()
local app = win:application()
local app_name = app:name()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
-- Reset count if direction has changed.
if current.direction ~= direction then
current.count = 0
end
current.count = current.count + 1
current.direction = direction
-- If is the second time (or more) change the direction.
if current.count > 1 then
if current.direction == 'top' then current.direction = 'full'
elseif current.direction == 'down' then current.direction = 'center'
elseif current.direction == 'right' then current.direction = 'right_half'
elseif current.direction == 'left' then current.direction = 'left_half'
end
end
if current.direction == 'center' then
f.x = (max.w / 4)
f.y = (max.h / 4)
f.w = (max.w / 2)
f.h = (max.h / 2)
elseif current.direction == 'left' then
f.x = max.x
f.y = max.y
f.w = (max.w / 2)
f.h = max.h
elseif current.direction == 'left_half' then
f.x = max.x
f.y = (max.h / 3)
f.w = (max.w / 2)
f.h = (max.h / 2)
elseif current.direction == 'right' then
f.x = (max.x + (max.w / 2))
f.y = max.y
f.w = (max.w / 2)
f.h = max.h
elseif current.direction == 'right_half' then
f.x = (max.x + (max.w / 2))
f.y = (max.h / 3)
f.w = (max.w / 2)
f.h = (max.h / 2)
elseif current.direction == 'top' then
f.x = max.x
f.y = max.y
f.w = max.w
f.h = (max.h / 2)
elseif current.direction == 'down' then
f.x = max.x
f.y = (max.h / 2)
f.w = max.w
f.h = (max.h / 2)
elseif current.direction == 'top_right' then
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = (max.w / 2) - 9
f.h = (max.h / 2) - 12
elseif current.direction == 'top_left' then
f.x = max.x
f.y = max.y
f.w = (max.w / 2) - 9
f.h = (max.h / 2) - 12
elseif current.direction == 'down_left' then
f.x = max.x
f.y = (max.h / 2)
f.w = (max.w / 2) - 9
f.h = (max.h / 2) - 12
elseif current.direction == 'down_right' then
f.x = (max.w / 2)
f.y = (max.h / 2)
f.w = (max.w / 2) - 9
f.h = (max.h / 2) - 12
elseif current.direction == 'full' then
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
end
win:setFrame(f, 0.0)
end
end