aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2024-03-05 08:44:04 +0100
committerFurkan Sahin <furkan-dev@proton.me>2024-03-05 08:44:04 +0100
commit0b67633770d4be2329c8eccd09ad7fb902405f68 (patch)
treed1a47057fb3a56a192a10425fe88c9da59bfdbc7
parent6a1a2c508eb76b73122b0cfd4ad51dd56c8c747f (diff)
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
-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(
context,
&rules,
XKB_KEYMAP_COMPILE_NO_FLAGS);
-
xkb_context_unref(context);
+ if (xkb_keymap == NULL) {
+ sway_log(SWAY_ERROR, "Failed to compile keysym translation XKB keymap");
+ return NULL;
+ }
+
return xkb_state_new(xkb_keymap);
}
static void keysym_translation_state_destroy(
struct xkb_state *state) {
+ if (state == NULL) {
+ return;
+ }
xkb_keymap_unref(xkb_state_get_keymap(state));
xkb_state_unref(state);
}
@@ -339,6 +346,9 @@ static void config_defaults(struct sway_config *config) {
struct xkb_rule_names rules = {0};
config->keysym_translation_state =
keysym_translation_state_create(rules);
+ if (config->keysym_translation_state == NULL) {
+ goto cleanup;
+ }
return;
cleanup:
@@ -987,6 +997,11 @@ void translate_keysyms(struct input_config *input_config) {
input_config_fill_rule_names(input_config, &rules);
config->keysym_translation_state =
keysym_translation_state_create(rules);
+ if (config->keysym_translation_state == NULL) {
+ sway_log(SWAY_ERROR, "Failed to create keysym translation XKB state "
+ "for device '%s'", input_config->identifier);
+ return;
+ }
for (int i = 0; i < config->modes->length; ++i) {
struct sway_mode *mode = config->modes->items[i];