From a8e8c46b56d6a111ea293d45e5bd972debd59e73 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 16 Oct 2019 02:10:15 -0400 Subject: [PATCH] awful.keyboard: Add a method to add a default client key. This is the first commit of a new API to add and remove buttons and keys from clients. The goal is to get rid of the default `rc.lua` "hardcoded" list of client buttons and keys to allow modules to modify the defaults. This is part of the larger effort to make `rc.lua` modular. --- lib/awful/keyboard.lua | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/awful/keyboard.lua b/lib/awful/keyboard.lua index da549c8b3..5c04df89f 100644 --- a/lib/awful/keyboard.lua +++ b/lib/awful/keyboard.lua @@ -6,7 +6,7 @@ -- @inputmodule awful.keyboard --------------------------------------------------------------------------- -local capi = {root = root, awesome = awesome} +local capi = {root = root, awesome = awesome, client = client} local module = {} --- Convert the modifiers into pc105 key names @@ -138,4 +138,39 @@ function module.remove_global_keybinding(key) capi.root._remove_key(key) end + +local default_keys = {} + +--- Add an `awful.key` to the default client keys. +-- +-- @staticfct awful.keyboard.append_client_keybinding +-- @tparam awful.key key The key. +-- @emits client_keybinding::added +-- @emitstparam client_keybinding::added awful.key key The key. +-- @see awful.key + +function module.append_client_keybinding(key) + table.insert(default_keys, key) + + for _, c in ipairs(capi.client.get(nil, false)) do + c:append_keybinding(key) + end + + capi.client.emit_signal("client_keybinding::added", key) +end + +--- Add a `awful.key`s to the default client keys. +-- +-- @staticfct awful.keyboard.append_client_keybindings +-- @tparam table keys A table containing `awful.key` objects. +-- @emits client_keybinding::added +-- @emitstparam client_keybinding::added awful.key key The key. +-- @see awful.key +-- @see awful.keyboard.append_client_keybinding + +function module.append_client_keybindings(keys) + for _, key in ipairs(keys) do + module.append_client_keybinding(key) + end +end return module