-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
65 lines (52 loc) · 1.61 KB
/
init.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
local wp = {}
wp.__index = wp
wp.name = "WindowPilot"
wp.version = "1.0"
wp.author = "Mário Carneiro"
wp.license = "MIT - https://opensource.org/licenses/MIT"
wp.homepage = "https://github.com/ticklemynausea/WindowPilot.spoon"
function wp:initialize(configuration)
local resourcePath = hs.spoons.resourcePath("")
package.path = resourcePath .. "/?.lua;" .. package.path
wp.hotkeys = {}
wp.configuration = {
windowMargin = 6,
}
for key, value in pairs(configuration) do
wp.configuration[key] = value
end
print("[WindowPilot] Configured")
wp.commands = {
switchWindow = require("switchWindow")(wp),
mouseCursor = require("mouseCursor")(wp),
windowLayout = require("windowLayout")(wp),
windowMovement = require("windowMovement")(wp),
}
require("menuItem")(wp)
print("[WindowPilot] Initialized")
end
function wp:bindKeys(mapping, prefix)
for key, value in pairs(mapping) do
local actionPath = prefix and (prefix .. "." .. key) or key
if type(value[1]) == "table" then
local command = wp.commands
for part in actionPath:gmatch("[^.]+") do
command = command and command[part]
end
if type(command) == "function" then
if wp.hotkeys[actionPath] then
wp.hotkeys[actionPath]:delete()
end
wp.hotkeys[actionPath] = hs.hotkey.bind(value[1], value[2], function()
command(wp)
end)
print("[WindowPilot] Bound key for " .. actionPath)
else
print("[WindowPilot] Error: Command not found for " .. actionPath)
end
else
self:bindKeys(value, actionPath)
end
end
end
return wp