diff options
-rw-r--r-- | include/sway/config.h | 4 | ||||
-rw-r--r-- | sway/commands/input.c | 2 | ||||
-rw-r--r-- | sway/config.c | 23 | ||||
-rw-r--r-- | sway/config/input.c | 12 | ||||
-rw-r--r-- | sway/input/keyboard.c | 30 |
5 files changed, 40 insertions, 31 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index db507296..a0a98fb6 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -577,6 +577,8 @@ void merge_input_config(struct input_config *dst, struct input_config *src); | |||
577 | 577 | ||
578 | struct input_config *store_input_config(struct input_config *ic); | 578 | struct input_config *store_input_config(struct input_config *ic); |
579 | 579 | ||
580 | struct xkb_rule_names input_config_get_rule_names(struct input_config *ic); | ||
581 | |||
580 | void free_input_config(struct input_config *ic); | 582 | void free_input_config(struct input_config *ic); |
581 | 583 | ||
582 | int seat_name_cmp(const void *item, const void *data); | 584 | int seat_name_cmp(const void *item, const void *data); |
@@ -655,7 +657,7 @@ void config_update_font_height(bool recalculate); | |||
655 | */ | 657 | */ |
656 | bool translate_binding(struct sway_binding *binding); | 658 | bool translate_binding(struct sway_binding *binding); |
657 | 659 | ||
658 | void translate_keysyms(const char *layout); | 660 | void translate_keysyms(struct input_config *input_config); |
659 | 661 | ||
660 | void binding_add_translated(struct sway_binding *binding, list_t *bindings); | 662 | void binding_add_translated(struct sway_binding *binding, list_t *bindings); |
661 | 663 | ||
diff --git a/sway/commands/input.c b/sway/commands/input.c index 2de07de6..0195082c 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -48,7 +48,7 @@ static void retranslate_keysyms(struct input_config *input_config) { | |||
48 | if (ic->xkb_layout) { | 48 | if (ic->xkb_layout) { |
49 | // this is the first config with xkb_layout | 49 | // this is the first config with xkb_layout |
50 | if (ic->identifier == input_config->identifier) { | 50 | if (ic->identifier == input_config->identifier) { |
51 | translate_keysyms(ic->xkb_layout); | 51 | translate_keysyms(ic); |
52 | } | 52 | } |
53 | 53 | ||
54 | return; | 54 | return; |
diff --git a/sway/config.c b/sway/config.c index 8579e865..fed01eb4 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -34,16 +34,14 @@ | |||
34 | struct sway_config *config = NULL; | 34 | struct sway_config *config = NULL; |
35 | 35 | ||
36 | static struct xkb_state *keysym_translation_state_create( | 36 | static struct xkb_state *keysym_translation_state_create( |
37 | const char *layout) { | 37 | struct xkb_rule_names rules) { |
38 | struct xkb_rule_names rules = { | 38 | struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); |
39 | .layout = layout, | ||
40 | }; | ||
41 | |||
42 | struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names( | 39 | struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names( |
43 | xkb_context_new(XKB_CONTEXT_NO_FLAGS), | 40 | context, |
44 | &rules, | 41 | &rules, |
45 | XKB_KEYMAP_COMPILE_NO_FLAGS); | 42 | XKB_KEYMAP_COMPILE_NO_FLAGS); |
46 | 43 | ||
44 | xkb_context_unref(context); | ||
47 | return xkb_state_new(xkb_keymap); | 45 | return xkb_state_new(xkb_keymap); |
48 | } | 46 | } |
49 | 47 | ||
@@ -339,8 +337,9 @@ static void config_defaults(struct sway_config *config) { | |||
339 | if (!(config->ipc_policies = create_list())) goto cleanup; | 337 | if (!(config->ipc_policies = create_list())) goto cleanup; |
340 | 338 | ||
341 | // The keysym to keycode translation | 339 | // The keysym to keycode translation |
340 | struct xkb_rule_names rules = {}; | ||
342 | config->keysym_translation_state = | 341 | config->keysym_translation_state = |
343 | keysym_translation_state_create(NULL); | 342 | keysym_translation_state_create(rules); |
344 | 343 | ||
345 | return; | 344 | return; |
346 | cleanup: | 345 | cleanup: |
@@ -987,9 +986,12 @@ static void translate_binding_list(list_t *bindings, list_t *bindsyms, | |||
987 | } | 986 | } |
988 | } | 987 | } |
989 | 988 | ||
990 | void translate_keysyms(const char *layout) { | 989 | void translate_keysyms(struct input_config *input_config) { |
991 | keysym_translation_state_destroy(config->keysym_translation_state); | 990 | keysym_translation_state_destroy(config->keysym_translation_state); |
992 | config->keysym_translation_state = keysym_translation_state_create(layout); | 991 | |
992 | struct xkb_rule_names rules = input_config_get_rule_names(input_config); | ||
993 | config->keysym_translation_state = | ||
994 | keysym_translation_state_create(rules); | ||
993 | 995 | ||
994 | for (int i = 0; i < config->modes->length; ++i) { | 996 | for (int i = 0; i < config->modes->length; ++i) { |
995 | struct sway_mode *mode = config->modes->items[i]; | 997 | struct sway_mode *mode = config->modes->items[i]; |
@@ -1007,5 +1009,6 @@ void translate_keysyms(const char *layout) { | |||
1007 | mode->keycode_bindings = bindcodes; | 1009 | mode->keycode_bindings = bindcodes; |
1008 | } | 1010 | } |
1009 | 1011 | ||
1010 | sway_log(SWAY_DEBUG, "Translated keysyms for layout %s", layout); | 1012 | sway_log(SWAY_DEBUG, "Translated keysyms using config for device '%s'", |
1013 | input_config->identifier); | ||
1011 | } | 1014 | } |
diff --git a/sway/config/input.c b/sway/config/input.c index aa581431..595aa029 100644 --- a/sway/config/input.c +++ b/sway/config/input.c | |||
@@ -212,6 +212,18 @@ struct input_config *store_input_config(struct input_config *ic) { | |||
212 | return ic; | 212 | return ic; |
213 | } | 213 | } |
214 | 214 | ||
215 | struct xkb_rule_names input_config_get_rule_names(struct input_config *ic) { | ||
216 | struct xkb_rule_names rules = { | ||
217 | .layout = ic->xkb_layout, | ||
218 | .model = ic->xkb_model, | ||
219 | .options = ic->xkb_options, | ||
220 | .rules = ic->xkb_rules, | ||
221 | .variant = ic->xkb_variant, | ||
222 | }; | ||
223 | |||
224 | return rules; | ||
225 | } | ||
226 | |||
215 | void free_input_config(struct input_config *ic) { | 227 | void free_input_config(struct input_config *ic) { |
216 | if (!ic) { | 228 | if (!ic) { |
217 | return; | 229 | return; |
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 5a965185..04b8b0ce 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -477,39 +477,31 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | |||
477 | } | 477 | } |
478 | 478 | ||
479 | void sway_keyboard_configure(struct sway_keyboard *keyboard) { | 479 | void sway_keyboard_configure(struct sway_keyboard *keyboard) { |
480 | struct xkb_rule_names rules; | ||
481 | memset(&rules, 0, sizeof(rules)); | ||
482 | struct input_config *input_config = | 480 | struct input_config *input_config = |
483 | input_device_get_config(keyboard->seat_device->input_device); | 481 | input_device_get_config(keyboard->seat_device->input_device); |
484 | struct wlr_input_device *wlr_device = | 482 | struct wlr_input_device *wlr_device = |
485 | keyboard->seat_device->input_device->wlr_device; | 483 | keyboard->seat_device->input_device->wlr_device; |
486 | 484 | ||
487 | if (input_config && input_config->xkb_layout) { | 485 | struct xkb_rule_names rules; |
488 | rules.layout = input_config->xkb_layout; | 486 | if (input_config) { |
487 | rules = input_config_get_rule_names(input_config); | ||
489 | } else { | 488 | } else { |
489 | memset(&rules, 0, sizeof(rules)); | ||
490 | } | ||
491 | |||
492 | if (!rules.layout) { | ||
490 | rules.layout = getenv("XKB_DEFAULT_LAYOUT"); | 493 | rules.layout = getenv("XKB_DEFAULT_LAYOUT"); |
491 | } | 494 | } |
492 | if (input_config && input_config->xkb_model) { | 495 | if (!rules.model) { |
493 | rules.model = input_config->xkb_model; | ||
494 | } else { | ||
495 | rules.model = getenv("XKB_DEFAULT_MODEL"); | 496 | rules.model = getenv("XKB_DEFAULT_MODEL"); |
496 | } | 497 | } |
497 | 498 | if (!rules.options) { | |
498 | if (input_config && input_config->xkb_options) { | ||
499 | rules.options = input_config->xkb_options; | ||
500 | } else { | ||
501 | rules.options = getenv("XKB_DEFAULT_OPTIONS"); | 499 | rules.options = getenv("XKB_DEFAULT_OPTIONS"); |
502 | } | 500 | } |
503 | 501 | if (!rules.rules) { | |
504 | if (input_config && input_config->xkb_rules) { | ||
505 | rules.rules = input_config->xkb_rules; | ||
506 | } else { | ||
507 | rules.rules = getenv("XKB_DEFAULT_RULES"); | 502 | rules.rules = getenv("XKB_DEFAULT_RULES"); |
508 | } | 503 | } |
509 | 504 | if (!rules.variant) { | |
510 | if (input_config && input_config->xkb_variant) { | ||
511 | rules.variant = input_config->xkb_variant; | ||
512 | } else { | ||
513 | rules.variant = getenv("XKB_DEFAULT_VARIANT"); | 505 | rules.variant = getenv("XKB_DEFAULT_VARIANT"); |
514 | } | 506 | } |
515 | 507 | ||