aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-05-13 23:56:59 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-05-21 10:16:17 -0400
commitb8f12b478335868a12466363b22095e2b93c02af (patch)
tree24dc0c936cb2a232378c3863cc4a5654fb00fab6
parentconfig/output: fix typo in merge_id_on_name (diff)
downloadsway-b8f12b478335868a12466363b22095e2b93c02af.tar.gz
sway-b8f12b478335868a12466363b22095e2b93c02af.tar.zst
sway-b8f12b478335868a12466363b22095e2b93c02af.zip
input/keyboard: attempt default keymap on failure
This attempts to use the default keymap when the one defined in the input config fails to compile. The goal is to make it so the keyboard is always in a usable state, even if it is not the user's requested settings as usability is more important. This also removes the calls to `getenv` for the `XKB_DEFAULT_*` family of environment variables. The reasoning is libxkbcommon will fallback to using those (and then the system defaults) when any of the rule names are `NULL` or an empty string anyway so there is no need for sway to duplicate the efforts.
-rw-r--r--include/sway/input/keyboard.h2
-rw-r--r--sway/input/keyboard.c50
2 files changed, 23 insertions, 29 deletions
diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h
index 0c8ada0f..b8622053 100644
--- a/include/sway/input/keyboard.h
+++ b/include/sway/input/keyboard.h
@@ -65,6 +65,8 @@ struct sway_keyboard {
65 struct sway_binding *repeat_binding; 65 struct sway_binding *repeat_binding;
66}; 66};
67 67
68struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic);
69
68struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, 70struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
69 struct sway_seat_device *device); 71 struct sway_seat_device *device);
70 72
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 396cc865..78e8fa0c 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -476,45 +476,38 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
476 return keyboard; 476 return keyboard;
477} 477}
478 478
479void sway_keyboard_configure(struct sway_keyboard *keyboard) { 479struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic) {
480 struct input_config *input_config =
481 input_device_get_config(keyboard->seat_device->input_device);
482 struct wlr_input_device *wlr_device =
483 keyboard->seat_device->input_device->wlr_device;
484
485 struct xkb_rule_names rules = {0}; 480 struct xkb_rule_names rules = {0};
486 if (input_config) { 481 if (ic) {
487 input_config_fill_rule_names(input_config, &rules); 482 input_config_fill_rule_names(ic, &rules);
488 }
489
490 if (!rules.layout) {
491 rules.layout = getenv("XKB_DEFAULT_LAYOUT");
492 }
493 if (!rules.model) {
494 rules.model = getenv("XKB_DEFAULT_MODEL");
495 }
496 if (!rules.options) {
497 rules.options = getenv("XKB_DEFAULT_OPTIONS");
498 }
499 if (!rules.rules) {
500 rules.rules = getenv("XKB_DEFAULT_RULES");
501 }
502 if (!rules.variant) {
503 rules.variant = getenv("XKB_DEFAULT_VARIANT");
504 } 483 }
505 484
506 struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); 485 struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
507 if (!sway_assert(context, "cannot create XKB context")) { 486 if (!sway_assert(context, "cannot create XKB context")) {
508 return; 487 return NULL;
509 } 488 }
510 489
511 struct xkb_keymap *keymap = 490 struct xkb_keymap *keymap =
512 xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); 491 xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
492 xkb_context_unref(context);
493 return keymap;
494}
495
496void sway_keyboard_configure(struct sway_keyboard *keyboard) {
497 struct input_config *input_config =
498 input_device_get_config(keyboard->seat_device->input_device);
499 struct wlr_input_device *wlr_device =
500 keyboard->seat_device->input_device->wlr_device;
513 501
502 struct xkb_keymap *keymap = sway_keyboard_compile_keymap(input_config);
514 if (!keymap) { 503 if (!keymap) {
515 sway_log(SWAY_DEBUG, "cannot configure keyboard: keymap does not exist"); 504 sway_log(SWAY_ERROR, "Failed to compile keymap. Attempting defaults");
516 xkb_context_unref(context); 505 keymap = sway_keyboard_compile_keymap(NULL);
517 return; 506 if (!keymap) {
507 sway_log(SWAY_ERROR,
508 "Failed to compile default keymap. Aborting configure");
509 return;
510 }
518 } 511 }
519 512
520 xkb_keymap_unref(keyboard->keymap); 513 xkb_keymap_unref(keyboard->keymap);
@@ -557,7 +550,6 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
557 wlr_keyboard_set_repeat_info(wlr_device->keyboard, repeat_rate, 550 wlr_keyboard_set_repeat_info(wlr_device->keyboard, repeat_rate,
558 repeat_delay); 551 repeat_delay);
559 552
560 xkb_context_unref(context);
561 struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat; 553 struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
562 wlr_seat_set_keyboard(seat, wlr_device); 554 wlr_seat_set_keyboard(seat, wlr_device);
563 555