-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
158 lines (137 loc) · 4.19 KB
/
init.lua
File metadata and controls
158 lines (137 loc) · 4.19 KB
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
155
156
157
158
--- === WindowManager ===
---
local m = {}
m.log = hs.logger.new("WindowManager")
m.name = "WindowManager"
m.version = "1.0.0"
m.author = "Michael Perrotte <mike@mikecorp.ca>"
m.license = "MIT <https://opensource.org/licenses/MIT>"
m.homepage = "https://github.com/mikemimik/WindowManager.spoon"
--- WindowManager:init() -> {}
--- Method
--- WindowsManager initialization.
---
--- Returns:
--- * self
function m:init()
-- Defaults
hs.window.animationDuration = 0.00
hs.grid.setMargins(hs.geometry.point(0.0, 0.0))
m.ROWS = 2
m.MENU_HEIGHT = 25.0
m.POSITIONS = {}
m.cache = dofile(hs.spoons.resourcePath("cache.lua"))(self)
local positions = dofile(hs.spoons.resourcePath("positions.lua"))(self)
local allScreens = hs.screen.allScreens()
for index=1, #allScreens do
-- Manage Screen Size
local screen = allScreens[index]
local screenName = screen:name()
local frame = screen:frame();
if (m.POSITIONS[screenName] == nil) then m.POSITIONS[screenName] = {} end
if (screenName == "Built-in Retina Display") then
m.COLUMNS = 2
positions:configure(screen, frame)
m.POSITIONS[screenName] = positions:generate(frame)
else
m.COLUMNS = 4
positions:configure(screen, frame)
m.POSITIONS[screenName] = positions:generate(frame)
end
end
return self
end
--- WindowManager:start() -> {}
--- Method
--- Starts the WindowsManager.
---
--- Returns:
--- * self
function m:start()
return self
end
--- WindowManager:stop() -> {}
--- Method
--- Stops the WindowsManager.
---
--- Returns:
--- * self
function m:stop()
return self
end
--- WindowManager:bindHotKeys(table) -> {}
--- Method
--- Expects a config table in the form of {}
---
--- Returns:
--- * self
function m:bindHotKeys(mapping)
local utils = dofile(hs.spoons.resourcePath("utils.lua"))(self)
local tableKeys = {
"moveLeft",
"moveLeftTop",
"moveLeftBottom",
"moveRight",
"moveRightTop",
"moveRightBottom",
"moveCenter",
"moveFull",
"undo",
}
local handlers = {
moveLeft = function() utils:moveHandler("left") end,
moveLeftTop = function() utils:moveHandler("row0left", "top left") end,
moveLeftBottom = function() utils:moveHandler("row1left", "bottom left") end,
moveRight = function() utils:moveHandler("right") end,
moveRightTop = function() utils:moveHandler("row0right", "top right") end,
moveRightBottom = function() utils:moveHandler("row1right", "bottom right") end,
moveCenter = function()
self.log.d("handle shift - center")
local win = utils:findWindow()
local screenName = win:screen():name()
local curFrame = utils:findCurrentFrame(win)
local xAdjusted = m.POSITIONS[screenName]["center"].x - (curFrame.w / 2)
local yAdjusted = m.POSITIONS[screenName]["center"].y - (curFrame.h / 2)
local centerPosition = hs.geometry.rect(xAdjusted, yAdjusted, curFrame.w, curFrame.h)
utils:shiftWindow(win, centerPosition)
self.log.d("done shift")
end,
moveFull = function()
self.log.d("handle shift - full")
local win = utils:findWindow()
local screenName = win:screen():name()
-- local curFrame = findCurrentFrame(win)
local fullFrame = m.POSITIONS[screenName]["full"]
utils:shiftWindow(win, fullFrame)
self.log.d("done shift")
end,
undo = function()
local win = utils:findWindow()
local prevFrame = self.cache.frames[win:id()];
utils:shiftWindow(win, prevFrame)
self.log.d("done unshift")
end,
}
local defaults = {
moveLeft = { {"cmd", "alt"}, "left" },
moveLeftTop = { {"cmd", "ctrl", "shift"}, "left" },
moveLeftBottom = { {"cmd", "ctrl"}, "left" },
moveRight = { {"cmd", "alt"}, "right" },
moveRightTop = { {"cmd", "ctrl", "shift"}, "right" },
moveRightBottom = { {"cmd", "ctrl"}, "right" },
moveCenter = { {"cmd", "alt"}, "c" },
moveFull = { {"cmd", "alt"}, "f" },
undo = { {"cmd", "ctrl"}, "u" },
}
local merged = {}
for _,k in pairs(tableKeys) do
merged[k] = mapping[k] or defaults[k]
table.insert(merged[k], handlers[k])
end
for _,v in pairs(merged) do
local mod, key, func = table.unpack(v)
hs.hotkey.bind(mod, key, func)
end
return self
end
return m