diff options
author | Konstantin Pospelov <kupospelov@gmail.com> | 2019-02-17 19:08:22 +0300 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-04-26 20:56:48 +0300 |
commit | a09c144b8b5f9d0518e7239a27e2fb86e00644b3 (patch) | |
tree | acce9b57c319496e9f5dd194e22e49b0b6fcbfdf /sway/commands/input.c | |
parent | ci: enable all features (diff) | |
download | sway-a09c144b8b5f9d0518e7239a27e2fb86e00644b3.tar.gz sway-a09c144b8b5f9d0518e7239a27e2fb86e00644b3.tar.zst sway-a09c144b8b5f9d0518e7239a27e2fb86e00644b3.zip |
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.
Diffstat (limited to 'sway/commands/input.c')
-rw-r--r-- | sway/commands/input.c | 25 |
1 files changed, 25 insertions, 0 deletions
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[] = { | |||
39 | { "xkb_numlock", input_cmd_xkb_numlock }, | 39 | { "xkb_numlock", input_cmd_xkb_numlock }, |
40 | }; | 40 | }; |
41 | 41 | ||
42 | /** | ||
43 | * Re-translate keysyms if a change in the input config could affect them. | ||
44 | */ | ||
45 | static void retranslate_keysyms(struct input_config *input_config) { | ||
46 | bool matched = false; | ||
47 | for (int i = 0; i < config->input_configs->length; ++i) { | ||
48 | struct input_config *ic = config->input_configs->items[i]; | ||
49 | matched |= ic->identifier == input_config->identifier; | ||
50 | |||
51 | // the first configured xkb_layout | ||
52 | if (ic->xkb_layout) { | ||
53 | if (matched) { | ||
54 | translate_keysyms(ic->xkb_layout); | ||
55 | } | ||
56 | |||
57 | // nothing has changed | ||
58 | return; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | // no xkb_layout has been set, restore the default | ||
63 | translate_keysyms(getenv("XKB_DEFAULT_LAYOUT")); | ||
64 | } | ||
65 | |||
42 | struct cmd_results *cmd_input(int argc, char **argv) { | 66 | struct cmd_results *cmd_input(int argc, char **argv) { |
43 | struct cmd_results *error = NULL; | 67 | struct cmd_results *error = NULL; |
44 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { | 68 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { |
@@ -73,6 +97,7 @@ struct cmd_results *cmd_input(int argc, char **argv) { | |||
73 | store_input_config(config->handler_context.input_config); | 97 | store_input_config(config->handler_context.input_config); |
74 | 98 | ||
75 | input_manager_apply_input_config(ic); | 99 | input_manager_apply_input_config(ic); |
100 | retranslate_keysyms(ic); | ||
76 | } else { | 101 | } else { |
77 | free_input_config(config->handler_context.input_config); | 102 | free_input_config(config->handler_context.input_config); |
78 | } | 103 | } |