diff options
-rw-r--r-- | include/sway/config.h | 10 | ||||
-rw-r--r-- | sway/commands/bind.c | 5 | ||||
-rw-r--r-- | sway/config.c | 26 |
3 files changed, 15 insertions, 26 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 392f6538..db507296 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -408,14 +408,6 @@ enum alignment { | |||
408 | }; | 408 | }; |
409 | 409 | ||
410 | /** | 410 | /** |
411 | * The keysym to keycode translation. | ||
412 | */ | ||
413 | struct keysym_translation_data { | ||
414 | struct xkb_keymap *xkb_keymap; | ||
415 | struct xkb_state *xkb_state; | ||
416 | }; | ||
417 | |||
418 | /** | ||
419 | * The configuration struct. The result of loading a config file. | 411 | * The configuration struct. The result of loading a config file. |
420 | */ | 412 | */ |
421 | struct sway_config { | 413 | struct sway_config { |
@@ -518,7 +510,7 @@ struct sway_config { | |||
518 | list_t *ipc_policies; | 510 | list_t *ipc_policies; |
519 | 511 | ||
520 | // The keysym to keycode translation | 512 | // The keysym to keycode translation |
521 | struct keysym_translation_data keysym_translation; | 513 | struct xkb_state *keysym_translation_state; |
522 | 514 | ||
523 | // Context for command handlers | 515 | // Context for command handlers |
524 | struct { | 516 | struct { |
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index e5fd4433..ea8179bb 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -604,7 +604,7 @@ struct keycode_matches { | |||
604 | static void find_keycode(struct xkb_keymap *keymap, | 604 | static void find_keycode(struct xkb_keymap *keymap, |
605 | xkb_keycode_t keycode, void *data) { | 605 | xkb_keycode_t keycode, void *data) { |
606 | xkb_keysym_t keysym = xkb_state_key_get_one_sym( | 606 | xkb_keysym_t keysym = xkb_state_key_get_one_sym( |
607 | config->keysym_translation.xkb_state, keycode); | 607 | config->keysym_translation_state, keycode); |
608 | 608 | ||
609 | if (keysym == XKB_KEY_NoSymbol) { | 609 | if (keysym == XKB_KEY_NoSymbol) { |
610 | return; | 610 | return; |
@@ -627,7 +627,8 @@ static struct keycode_matches get_keycode_for_keysym(xkb_keysym_t keysym) { | |||
627 | .count = 0, | 627 | .count = 0, |
628 | }; | 628 | }; |
629 | 629 | ||
630 | xkb_keymap_key_for_each(config->keysym_translation.xkb_keymap, | 630 | xkb_keymap_key_for_each( |
631 | xkb_state_get_keymap(config->keysym_translation_state), | ||
631 | find_keycode, &matches); | 632 | find_keycode, &matches); |
632 | return matches; | 633 | return matches; |
633 | } | 634 | } |
diff --git a/sway/config.c b/sway/config.c index 45d16758..c5d892f3 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -33,7 +33,7 @@ | |||
33 | 33 | ||
34 | struct sway_config *config = NULL; | 34 | struct sway_config *config = NULL; |
35 | 35 | ||
36 | static struct keysym_translation_data new_keysym_translation_data( | 36 | static struct xkb_state *keysym_translation_state_create( |
37 | const char *layout) { | 37 | const char *layout) { |
38 | struct xkb_rule_names rules = { | 38 | struct xkb_rule_names rules = { |
39 | .layout = layout, | 39 | .layout = layout, |
@@ -44,18 +44,13 @@ static struct keysym_translation_data new_keysym_translation_data( | |||
44 | &rules, | 44 | &rules, |
45 | XKB_KEYMAP_COMPILE_NO_FLAGS); | 45 | XKB_KEYMAP_COMPILE_NO_FLAGS); |
46 | 46 | ||
47 | struct keysym_translation_data result = { | 47 | return xkb_state_new(xkb_keymap); |
48 | .xkb_keymap = xkb_keymap, | ||
49 | .xkb_state = xkb_state_new(xkb_keymap), | ||
50 | }; | ||
51 | |||
52 | return result; | ||
53 | } | 48 | } |
54 | 49 | ||
55 | static void free_keysym_translation_data( | 50 | static void keysym_translation_state_destroy( |
56 | struct keysym_translation_data config) { | 51 | struct xkb_state *state) { |
57 | xkb_state_unref(config.xkb_state); | 52 | xkb_keymap_unref(xkb_state_get_keymap(state)); |
58 | xkb_keymap_unref(config.xkb_keymap); | 53 | xkb_state_unref(state); |
59 | } | 54 | } |
60 | 55 | ||
61 | static void free_mode(struct sway_mode *mode) { | 56 | static void free_mode(struct sway_mode *mode) { |
@@ -171,7 +166,7 @@ void free_config(struct sway_config *config) { | |||
171 | free(config->swaynag_command); | 166 | free(config->swaynag_command); |
172 | free((char *)config->current_config_path); | 167 | free((char *)config->current_config_path); |
173 | free((char *)config->current_config); | 168 | free((char *)config->current_config); |
174 | free_keysym_translation_data(config->keysym_translation); | 169 | keysym_translation_state_destroy(config->keysym_translation_state); |
175 | free(config); | 170 | free(config); |
176 | } | 171 | } |
177 | 172 | ||
@@ -344,7 +339,8 @@ static void config_defaults(struct sway_config *config) { | |||
344 | if (!(config->ipc_policies = create_list())) goto cleanup; | 339 | if (!(config->ipc_policies = create_list())) goto cleanup; |
345 | 340 | ||
346 | // The keysym to keycode translation | 341 | // The keysym to keycode translation |
347 | config->keysym_translation = new_keysym_translation_data(getenv("XKB_DEFAULT_LAYOUT")); | 342 | config->keysym_translation_state = |
343 | keysym_translation_state_create(getenv("XKB_DEFAULT_LAYOUT")); | ||
348 | 344 | ||
349 | return; | 345 | return; |
350 | cleanup: | 346 | cleanup: |
@@ -992,8 +988,8 @@ static void translate_binding_list(list_t *bindings, list_t *bindsyms, | |||
992 | } | 988 | } |
993 | 989 | ||
994 | void translate_keysyms(const char *layout) { | 990 | void translate_keysyms(const char *layout) { |
995 | free_keysym_translation_data(config->keysym_translation); | 991 | keysym_translation_state_destroy(config->keysym_translation_state); |
996 | config->keysym_translation = new_keysym_translation_data(layout); | 992 | config->keysym_translation_state = keysym_translation_state_create(layout); |
997 | 993 | ||
998 | for (int i = 0; i < config->modes->length; ++i) { | 994 | for (int i = 0; i < config->modes->length; ++i) { |
999 | struct sway_mode *mode = config->modes->items[i]; | 995 | struct sway_mode *mode = config->modes->items[i]; |