Add support for keygroups
Repurposes use of `<>` in keybinding strings.
This commit is contained in:
parent
30e6deda89
commit
1e6898e9a5
27
init.lua
27
init.lua
|
@ -56,14 +56,13 @@ end
|
||||||
--
|
--
|
||||||
-- Key definition strings consist of modifier characters and a key separated
|
-- Key definition strings consist of modifier characters and a key separated
|
||||||
-- by hyphens, e.g. "M-S-x" is the combination of Mod4, Shift, and the x key.
|
-- by hyphens, e.g. "M-S-x" is the combination of Mod4, Shift, and the x key.
|
||||||
|
-- If the key is surrounded by <>, it is interpreted as a key group, e.g.
|
||||||
|
-- "M-<numrow>" uses the modifier Mod4 and the key group "numrow".
|
||||||
--
|
--
|
||||||
-- The modifier key strings are: M = Mod4, A = Mod1, S = Shift, C = Control.
|
-- The modifier key strings are: M = Mod4, A = Mod1, S = Shift, C = Control.
|
||||||
--
|
--
|
||||||
-- Key names longer than 1 character must be surrounded by <>,
|
|
||||||
-- e.g. "M-<Return>".
|
|
||||||
--
|
|
||||||
-- @param keydef The key definition string.
|
-- @param keydef The key definition string.
|
||||||
-- @usage local modkeys, key = ez.util.parse_key("M-<Return>")
|
-- @usage local modkeys, key = ez.util.parse_key("M-Return")
|
||||||
-- @return A table of modifiers and the key.
|
-- @return A table of modifiers and the key.
|
||||||
function ez.util.parse_key(keydef)
|
function ez.util.parse_key(keydef)
|
||||||
local modkeys = {}
|
local modkeys = {}
|
||||||
|
@ -71,8 +70,9 @@ function ez.util.parse_key(keydef)
|
||||||
if modifiers[key] ~= nil then
|
if modifiers[key] ~= nil then
|
||||||
table.insert(modkeys, modifiers[key])
|
table.insert(modkeys, modifiers[key])
|
||||||
else
|
else
|
||||||
if #key ~= 1 and string.sub(key, 1, 1) ~= "#" then
|
local group = string.match(key, "<(%w+)>")
|
||||||
key = string.match(key, "<(%w+)>")
|
if group then
|
||||||
|
return modkeys, nil, group
|
||||||
end
|
end
|
||||||
return modkeys, key
|
return modkeys, key
|
||||||
end
|
end
|
||||||
|
@ -109,8 +109,15 @@ end
|
||||||
-- @param cb The callback or table describing the callback.
|
-- @param cb The callback or table describing the callback.
|
||||||
-- @return A table with the key objects.
|
-- @return A table with the key objects.
|
||||||
function ez.key(keydef, cb)
|
function ez.key(keydef, cb)
|
||||||
local modkeys, key = ez.util.parse_key(keydef)
|
local modkeys, key, group = ez.util.parse_key(keydef)
|
||||||
return awful.key.new(modkeys, key, ez.util.cb_from_table(cb))
|
if group then
|
||||||
|
return awful.key {
|
||||||
|
keygroup = group,
|
||||||
|
modifiers = modkeys,
|
||||||
|
on_press = cb,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return awful.key(modkeys, key, ez.util.cb_from_table(cb))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a button binding from a button definition string and callback.
|
--- Create a button binding from a button definition string and callback.
|
||||||
|
@ -132,7 +139,7 @@ function ez.keytable(tbl)
|
||||||
for keydef, cb in pairs(tbl) do
|
for keydef, cb in pairs(tbl) do
|
||||||
table.insert(res, ez.key(keydef, cb))
|
table.insert(res, ez.key(keydef, cb))
|
||||||
end
|
end
|
||||||
return gtable.join(unpack(res))
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create button bindings for elements of a table.
|
--- Create button bindings for elements of a table.
|
||||||
|
@ -144,7 +151,7 @@ function ez.btntable(tbl)
|
||||||
for btndef, cb in pairs(tbl) do
|
for btndef, cb in pairs(tbl) do
|
||||||
table.insert(res, ez.btn(btndef, cb))
|
table.insert(res, ez.btn(btndef, cb))
|
||||||
end
|
end
|
||||||
return gtable.join(unpack(res))
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
return ez
|
return ez
|
||||||
|
|
Loading…
Reference in New Issue