aboutsummaryrefslogtreecommitdiffstats
path: root/window.lua
blob: 3a43d60c06d034a958f9f690a97c7f8daa03f1cc (plain)
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
units = {
	up_small    = { x = 0,  y = -5 },
	right_small = { x = 5,  y = 0 },
	down_small  = { x = 0,  y = 5 },
	left_small  = { x = -5, y = 0 },

	up_med    = { x = 0,   y = -20 },
	right_med = { x = 20,  y = 0 },
	down_med  = { x = 0,   y = 20 },
	left_med  = { x = -20, y = 0 },

	increase_right = { w = 5, h = 0 },
	increase_down  = { w = 0, h = 5 },

	decrease_up   = { w = 0,  h = -5 },
	decrease_left = { w = -5, h = 0 },

	increase_right_med = { w = 20, h = 0 },
	increase_down_med  = { w = 0,  h = 20 },

	decrease_up_med   = { w = 0,   h = -20 },
	decrease_left_med = { w = -20,  h = 0 },

	maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }
}

window = {}
function window.up_small()
	hs.window.focusedWindow():move(units.up_small, nil, false, 0)
end

function window.right_small()
	hs.window.focusedWindow():move(units.right_small, nil, false, 0)
end

function window.down_small()
	hs.window.focusedWindow():move(units.down_small, nil, false, 0)
end

function window.left_small()
	hs.window.focusedWindow():move(units.left_small, nil, false, 0)
end

function window.up_med()
	hs.window.focusedWindow():move(units.up_med, nil, false, 0)
end

function window.right_med()
	hs.window.focusedWindow():move(units.right_med, nil, false, 0)
end

function window.down_med()
	hs.window.focusedWindow():move(units.down_med, nil, false, 0)
end

function window.left_med()
	hs.window.focusedWindow():move(units.left_med, nil, false, 0)
end


function window.relative_size(window, relative_size)
	local size = window:size()
	size.w = size.w + relative_size.w
	size.h = size.h + relative_size.h

	return size
end

function window.increase_right()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.increase_right)
	)
end

function window.increase_down()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.increase_down)
	)
end

function window.decrease_up()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.decrease_up)
	)
end

function window.decrease_left()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.decrease_left)
	)
end

function window.increase_right_med()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.increase_right_med)
	)
end

function window.increase_down_med()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.increase_down_med)
	)
end

function window.decrease_up_med()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.decrease_up_med)
	)
end

function window.decrease_left_med()
	hs.window.focusedWindow():setSize(
		window.relative_size(hs.window.focusedWindow(), units.decrease_left_med)
	)
end


function window.move_to_top()
	local position = hs.window.focusedWindow():topLeft()
	position.y = 0

	hs.window.focusedWindow():setTopLeft(position)
end


window_mode = hs.hotkey.modal.new({'ctrl', 'option', 'shift'}, 'w', 'Window')
window_mode:bind({'ctrl', 'option', 'shift'}, 'w', 'Window Off', function()
	window_mode:exit()
end)

window_mode:bind({'shift'}, 'k', window.up_small,    nil, window.up_small)
window_mode:bind({'shift'}, 'l', window.right_small, nil, window.right_small)
window_mode:bind({'shift'}, 'j', window.down_small,  nil, window.down_small)
window_mode:bind({'shift'}, 'h', window.left_small,  nil, window.left_small)

window_mode:bind({}, 'k', window.up_med,    nil, window.up_med)
window_mode:bind({}, 'l', window.right_med, nil, window.right_med)
window_mode:bind({}, 'j', window.down_med,  nil, window.down_med)
window_mode:bind({}, 'h', window.left_med,  nil, window.left_med)

window_mode:bind({}, 'i', window.move_to_top,  nil, window.move_to_top)

window_mode:bind({}, ']', function() hs.window.focusedWindow():moveOneScreenEast(true, false, 0) end)
window_mode:bind({}, '[', function() hs.window.focusedWindow():moveOneScreenWest(true, false, 0) end)

window_mode:bind({'shift'}, 'e', window.decrease_up,    nil, window.decrease_up)
window_mode:bind({'shift'}, 'd', window.increase_down,  nil, window.increase_down)
window_mode:bind({'shift'}, 'f', window.increase_right, nil, window.increase_right)
window_mode:bind({'shift'}, 's', window.decrease_left,  nil, window.decrease_left)

window_mode:bind({}, 'e', window.decrease_up_med,    nil, window.decrease_up_med)
window_mode:bind({}, 'd', window.increase_down_med,  nil, window.increase_down_med)
window_mode:bind({}, 'f', window.increase_right_med, nil, window.increase_right_med)
window_mode:bind({}, 's', window.decrease_left_med,  nil, window.decrease_left_med)