-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.lua
87 lines (69 loc) · 2.04 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
-- Setup load paths.
local function scriptPath()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)")
end
local rootDir = scriptPath()
package.path = rootDir .. "lib/?.lua;" .. package.path
-----------------------------------------
local newclass = require('HyperKey.utils.yaci')
local onModifierHold = require('HyperKey.utils.on_modifier_hold')
local bindings = require('HyperKey.bindings')
local Overlay = require('HyperKey.overlay')
----------------------------------------------------------------
local HyperKey = newclass("HyperKey")
HyperKey.author = "David Balatero <d@balatero.com>"
HyperKey.homepage = "https://github.com/dbalatero/HyperKey.spoon"
HyperKey.license = "MIT"
HyperKey.name = "HyperKey"
HyperKey.version = "1.0.0"
HyperKey.spoonPath = rootDir
function HyperKey:init(hyperMods, options)
options = options or {}
self.overlayTimeoutMs = options.overlayTimeoutMs or 250
self.hyperMods = hyperMods
self.bindings = {}
self.overlay = Overlay:new(self.bindings)
self.holdTap = self:_createOverlayTap()
end
function HyperKey:bind(displayedKey, bindKey)
bindKey = bindKey or displayedKey
return {
toApplication = function(_, applicationName)
return self:_bind(
displayedKey,
bindKey,
bindings.ApplicationBinding:new(applicationName)
)
end,
toFunction = function(_, name, fn)
return self:_bind(
displayedKey,
bindKey,
bindings.FunctionBinding:new(name, fn)
)
end
}
end
function HyperKey:_bind(key, bindKey, binding)
table.insert(self.bindings, {
key = string.upper(key),
bindKey = bindKey,
binding = binding
})
self.overlay = Overlay:new(self.bindings)
hs.hotkey.bind(self.hyperMods, bindKey, function()
binding:launch()
end)
return self
end
function HyperKey:_createOverlayTap()
local onHold = function()
self.overlay:show()
end
local onRelease = function()
self.overlay:hide()
end
return onModifierHold(self.hyperMods, self.overlayTimeoutMs, onHold, onRelease)
end
return HyperKey