aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2024-03-05 08:44:04 +0100
committerLibravatar Simon Zeni <simon@bl4ckb0ne.ca>2024-03-06 11:14:50 -0500
commitfd9ab9ee0659d5b4c2bd148e25b8bc6378f604d6 (patch)
treed1a47057fb3a56a192a10425fe88c9da59bfdbc7 /sway
parentcommands/move: do not force focus on the moved container (diff)
downloadsway-fd9ab9ee0659d5b4c2bd148e25b8bc6378f604d6.tar.gz
sway-fd9ab9ee0659d5b4c2bd148e25b8bc6378f604d6.tar.zst
sway-fd9ab9ee0659d5b4c2bd148e25b8bc6378f604d6.zip
config: error out on keysym translation XKB state failure
If we can't create the XKB keymap used for keysym translation, gracefully error out instead of crashing. This can happen if the XKB_DEFAULT_LAYOUT is set to an invalid value, for instance. Closes: https://github.com/swaywm/sway/issues/7789
Diffstat (limited to 'sway')
-rw-r--r--sway/config.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/sway/config.c b/sway/config.c
index 568c8b53..d46b81ee 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -43,13 +43,20 @@ static struct xkb_state *keysym_translation_state_create(
43 context, 43 context,
44 &rules, 44 &rules,
45 XKB_KEYMAP_COMPILE_NO_FLAGS); 45 XKB_KEYMAP_COMPILE_NO_FLAGS);
46
47 xkb_context_unref(context); 46 xkb_context_unref(context);
47 if (xkb_keymap == NULL) {
48 sway_log(SWAY_ERROR, "Failed to compile keysym translation XKB keymap");
49 return NULL;
50 }
51
48 return xkb_state_new(xkb_keymap); 52 return xkb_state_new(xkb_keymap);
49} 53}
50 54
51static void keysym_translation_state_destroy( 55static void keysym_translation_state_destroy(
52 struct xkb_state *state) { 56 struct xkb_state *state) {
57 if (state == NULL) {
58 return;
59 }
53 xkb_keymap_unref(xkb_state_get_keymap(state)); 60 xkb_keymap_unref(xkb_state_get_keymap(state));
54 xkb_state_unref(state); 61 xkb_state_unref(state);
55} 62}
@@ -339,6 +346,9 @@ static void config_defaults(struct sway_config *config) {
339 struct xkb_rule_names rules = {0}; 346 struct xkb_rule_names rules = {0};
340 config->keysym_translation_state = 347 config->keysym_translation_state =
341 keysym_translation_state_create(rules); 348 keysym_translation_state_create(rules);
349 if (config->keysym_translation_state == NULL) {
350 goto cleanup;
351 }
342 352
343 return; 353 return;
344cleanup: 354cleanup:
@@ -987,6 +997,11 @@ void translate_keysyms(struct input_config *input_config) {
987 input_config_fill_rule_names(input_config, &rules); 997 input_config_fill_rule_names(input_config, &rules);
988 config->keysym_translation_state = 998 config->keysym_translation_state =
989 keysym_translation_state_create(rules); 999 keysym_translation_state_create(rules);
1000 if (config->keysym_translation_state == NULL) {
1001 sway_log(SWAY_ERROR, "Failed to create keysym translation XKB state "
1002 "for device '%s'", input_config->identifier);
1003 return;
1004 }
990 1005
991 for (int i = 0; i < config->modes->length; ++i) { 1006 for (int i = 0; i < config->modes->length; ++i) {
992 struct sway_mode *mode = config->modes->items[i]; 1007 struct sway_mode *mode = config->modes->items[i];