-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.lua
90 lines (81 loc) · 3.17 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
-----------------------------------------------
-- Set hyper to cmd + alt
-----------------------------------------------
local hyper = {"cmd", "alt"}
local hyperCtrl = {"cmd", "alt", "ctrl"}
-----------------------------------------------
-- flexible resize function
-----------------------------------------------
function tolerance(a, b) return math.abs(a - b) < 32 end
function resize(x, y, w, h)
local win = hs.window.focusedWindow()
local f = win:frame()
local max = win:screen():frame()
local ww = max.w / w
local hh = max.h / h
local xx = max.x + (x * ww)
local yy = max.y + (y * hh)
if ischatmode and x == 0 then
xx = xx + CHAT_MODE_WIDTH
ww = ww - CHAT_MODE_WIDTH
end
if tolerance(f.x, xx) and tolerance(f.y, yy) and tolerance(f.w, ww) and tolerance(f.h, hh) then
if w > h then
x = (x + 1) % w
elseif h > w then
y = (y + 1) % h
else
x = (x == 0) and 0.9999 or 0
y = (y == 0) and 0.9999 or 0
end
return resize(x, y, w, h)
end
f.x = xx
f.y = yy
f.w = ww
f.h = hh
return win:setFrame(f)
end
-----------------------------------------------
-- hyper 1, 2 for diagonal quarter window
-----------------------------------------------
hs.hotkey.bind(hyper, "1", function() resize(0, 0, 2, 2) end)
hs.hotkey.bind(hyper, "2", function() resize(1, 0, 2, 2) end)
-----------------------------------------------
-- hyper left, right for half window
-----------------------------------------------
top50 = { x = 0.00, y = 0.00, w = 1.00, h = 0.50 }
bottom50 = { x = 0.00, y = 0.50, w = 1.00, h = 0.50 }
hs.hotkey.bind(hyper, "left", function() hs.window.focusedWindow():moveToUnit(hs.layout.left50) end)
hs.hotkey.bind(hyper, "right", function() hs.window.focusedWindow():moveToUnit(hs.layout.right50) end)
hs.hotkey.bind(hyperCtrl, "up", function() hs.window.focusedWindow():moveToUnit(top50) end)
hs.hotkey.bind(hyperCtrl, "down", function() hs.window.focusedWindow():moveToUnit(bottom50) end)
-----------------------------------------------
-- move between monitors
-----------------------------------------------
hs.hotkey.bind(hyperCtrl, "right", function()
local win = hs.window.focusedWindow()
local screen = win:screen()
win:move(win:frame():toUnitRect(screen:frame()), screen:previous(), true, 0)
end)
hs.hotkey.bind(hyperCtrl, "left", function()
local win = hs.window.focusedWindow()
local screen = win:screen()
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
-----------------------------------------------
-- Hyper n to show window hints
-----------------------------------------------
hs.hotkey.bind(hyper, "n", function() hs.hints.windowHints() end)
-----------------------------------------------
-- hyper f for fullscreen, c for center
-----------------------------------------------
hs.hotkey.bind(hyper, "c", function() hs.window.focusedWindow():centerOnScreen() end)
hs.hotkey.bind(hyper, "f", function()
local w = hs.window.focusedWindow()
if w:application():name() == "Emacs" then
hs.eventtap.keyStroke({"alt"}, "F10")
else
w:maximize(0)
end
end)