-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbind.lua
98 lines (98 loc) · 2.08 KB
/
bind.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
91
92
93
94
95
96
97
98
local abutton = require("awful.button")
local akey = require("awful.key")
local gtable = require("gears.table")
local modifiers = {
["M"] = "Mod4",
["A"] = "Mod1",
["S"] = "Shift",
["C"] = "Control"
}
local split
split = function(s, sep)
sep = sep or "%s"
local _accum_0 = { }
local _len_0 = 1
for m in s:gmatch(string.format("([^%s]+)", sep)) do
_accum_0[_len_0] = m
_len_0 = _len_0 + 1
end
return _accum_0
end
local parse_key
parse_key = function(s)
local res = split(s, "-")
return (function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #res do
local k = res[_index_0]
if modifiers[k] then
_accum_0[_len_0] = modifiers[k]
_len_0 = _len_0 + 1
end
end
return _accum_0
end)(), res[#res]
end
local parse_btn
parse_btn = function(s)
if type(s) == "number" then
return { }, s
end
local res = split(s, "-")
return (function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #res do
local k = res[_index_0]
if modifiers[k] then
_accum_0[_len_0] = modifiers[k]
_len_0 = _len_0 + 1
end
end
return _accum_0
end)(), tonumber(res[#res])
end
local mkkey
mkkey = function(keydef, arg)
local mods, key = parse_key(keydef)
return akey(mods, key, arg.cb, {
description = arg.desc,
group = arg.group
})
end
local mkbtn
mkbtn = function(btndef, arg)
local mods, btn = parse_btn(btndef)
return abutton(mods, btn, arg)
end
local keytable
keytable = function(tbl)
return gtable.join(table.unpack((function()
local _accum_0 = { }
local _len_0 = 1
for k, a in pairs(tbl) do
_accum_0[_len_0] = mkkey(k, a)
_len_0 = _len_0 + 1
end
return _accum_0
end)()))
end
local btntable
btntable = function(tbl)
return gtable.join(table.unpack((function()
local _accum_0 = { }
local _len_0 = 1
for b, a in pairs(tbl) do
_accum_0[_len_0] = mkbtn(b, a)
_len_0 = _len_0 + 1
end
return _accum_0
end)()))
end
return {
mkkey = mkkey,
keytable = keytable,
mkbtn = mkbtn,
btntable = btntable
}