Compare commits

...

2 Commits

Author SHA1 Message Date
Simon Ser
59f6292383 config: add fallback without env vars for keysym translation XKB keymap 2024-03-06 11:14:50 -05:00
Simon Ser
fd9ab9ee06 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
2024-03-06 11:14:50 -05:00

View File

@ -37,19 +37,26 @@
struct sway_config *config = NULL;
static struct xkb_state *keysym_translation_state_create(
struct xkb_rule_names rules) {
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_SECURE_GETENV);
struct xkb_rule_names rules, uint32_t context_flags) {
struct xkb_context *context = xkb_context_new(context_flags | XKB_CONTEXT_NO_SECURE_GETENV);
struct xkb_keymap *xkb_keymap = xkb_keymap_new_from_names(
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);
}
@ -337,8 +344,14 @@ static void config_defaults(struct sway_config *config) {
// The keysym to keycode translation
struct xkb_rule_names rules = {0};
config->keysym_translation_state =
keysym_translation_state_create(rules);
config->keysym_translation_state = keysym_translation_state_create(rules, 0);
if (config->keysym_translation_state == NULL) {
config->keysym_translation_state = keysym_translation_state_create(rules,
XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
}
if (config->keysym_translation_state == NULL) {
goto cleanup;
}
return;
cleanup:
@ -985,8 +998,12 @@ void translate_keysyms(struct input_config *input_config) {
struct xkb_rule_names rules = {0};
input_config_fill_rule_names(input_config, &rules);
config->keysym_translation_state =
keysym_translation_state_create(rules);
config->keysym_translation_state = keysym_translation_state_create(rules, 0);
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];