From a09c144b8b5f9d0518e7239a27e2fb86e00644b3 Mon Sep 17 00:00:00 2001 From: Konstantin Pospelov Date: Sun, 17 Feb 2019 19:08:22 +0300 Subject: Implement bindsym --to-code * `bindsym --to-code` enables keysym to keycode translation. * If there are no `xkb_layout` commands in the config file, the translation uses the XKB_DEFAULT_LAYOUT value. * It there is one or more `xkb_layout` command, the translation uses the first one. * If the translation is unsuccessful, a message is logged and the binding is stored as BINDING_KEYSYM. * The binding keysyms are stored and re-translated when a change in the input configuration may affect the translated bindings. --- sway/commands/input.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'sway/commands/input.c') diff --git a/sway/commands/input.c b/sway/commands/input.c index b72bd76b..903d574f 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -39,6 +39,30 @@ static struct cmd_handler input_config_handlers[] = { { "xkb_numlock", input_cmd_xkb_numlock }, }; +/** + * Re-translate keysyms if a change in the input config could affect them. + */ +static void retranslate_keysyms(struct input_config *input_config) { + bool matched = false; + for (int i = 0; i < config->input_configs->length; ++i) { + struct input_config *ic = config->input_configs->items[i]; + matched |= ic->identifier == input_config->identifier; + + // the first configured xkb_layout + if (ic->xkb_layout) { + if (matched) { + translate_keysyms(ic->xkb_layout); + } + + // nothing has changed + return; + } + } + + // no xkb_layout has been set, restore the default + translate_keysyms(getenv("XKB_DEFAULT_LAYOUT")); +} + struct cmd_results *cmd_input(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { @@ -73,6 +97,7 @@ struct cmd_results *cmd_input(int argc, char **argv) { store_input_config(config->handler_context.input_config); input_manager_apply_input_config(ic); + retranslate_keysyms(ic); } else { free_input_config(config->handler_context.input_config); } -- cgit v1.2.3