keygrabber: Add :remove_keybinding().

It was possible to add new keys, but not remove existing ones.
This commit is contained in:
Emmanuel Lepage Vallee 2022-09-05 15:57:23 -07:00
parent f0a7f904f9
commit c391fc7fe4

View file

@ -549,6 +549,7 @@ end
-- @tparam awful.key key The key.
-- @tparam string description.group The keybinding group
-- @noreturn
-- @see remove_keybinding
function keygrabber:add_keybinding(key, keycode, callback, description)
local mods = not key._is_awful_key and key or nil
@ -581,6 +582,27 @@ function keygrabber:add_keybinding(key, keycode, callback, description)
end
end
--- Remove a keybinding from the keygrabber.
--
-- @method remove_keybinding
-- @treturn boolean `true` if removed, `false` if not found.
-- @see add_keybinding
function keygrabber:remove_keybinding(key)
for idx, obj in ipairs(self._private.keybindings[key.key]) do
if obj == key then
table.remove(self._private.keybindings[key.key], idx)
if #self._private.keybindings[key.key] == 0 then
self._private.keybindings[key.key] = nil
end
return true
end
end
return false
end
function keygrabber:set_root_keybindings(keys)
local real_keys = {}