aboutsummaryrefslogtreecommitdiff
path: root/sway/input
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-05-13 23:56:59 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-14 08:23:26 -0600
commit23c64ab22da0067f2718b822ec1a14a8bb0a3199 (patch)
treee35980a339b14da7f6dbb38dfed66d7eaa5e5a0f /sway/input
parented2e553b8d0dff3e74eeaa80a2586458271b2565 (diff)
downloadsway-23c64ab22da0067f2718b822ec1a14a8bb0a3199.tar.xz
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.
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/keyboard.c50
1 files changed, 21 insertions, 29 deletions
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,
return keyboard;
}
-void sway_keyboard_configure(struct sway_keyboard *keyboard) {
- struct input_config *input_config =
- input_device_get_config(keyboard->seat_device->input_device);
- struct wlr_input_device *wlr_device =
- keyboard->seat_device->input_device->wlr_device;
-
+struct xkb_keymap *sway_keyboard_compile_keymap(struct input_config *ic) {
struct xkb_rule_names rules = {0};
- if (input_config) {
- input_config_fill_rule_names(input_config, &rules);
- }
-
- if (!rules.layout) {
- rules.layout = getenv("XKB_DEFAULT_LAYOUT");
- }
- if (!rules.model) {
- rules.model = getenv("XKB_DEFAULT_MODEL");
- }
- if (!rules.options) {
- rules.options = getenv("XKB_DEFAULT_OPTIONS");
- }
- if (!rules.rules) {
- rules.rules = getenv("XKB_DEFAULT_RULES");
- }
- if (!rules.variant) {
- rules.variant = getenv("XKB_DEFAULT_VARIANT");
+ if (ic) {
+ input_config_fill_rule_names(ic, &rules);
}
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!sway_assert(context, "cannot create XKB context")) {
- return;
+ return NULL;
}
struct xkb_keymap *keymap =
xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
+ xkb_context_unref(context);
+ return keymap;
+}
+
+void sway_keyboard_configure(struct sway_keyboard *keyboard) {
+ struct input_config *input_config =
+ input_device_get_config(keyboard->seat_device->input_device);
+ struct wlr_input_device *wlr_device =
+ keyboard->seat_device->input_device->wlr_device;
+ struct xkb_keymap *keymap = sway_keyboard_compile_keymap(input_config);
if (!keymap) {
- sway_log(SWAY_DEBUG, "cannot configure keyboard: keymap does not exist");
- xkb_context_unref(context);
- return;
+ sway_log(SWAY_ERROR, "Failed to compile keymap. Attempting defaults");
+ keymap = sway_keyboard_compile_keymap(NULL);
+ if (!keymap) {
+ sway_log(SWAY_ERROR,
+ "Failed to compile default keymap. Aborting configure");
+ return;
+ }
}
xkb_keymap_unref(keyboard->keymap);
@@ -557,7 +550,6 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
wlr_keyboard_set_repeat_info(wlr_device->keyboard, repeat_rate,
repeat_delay);
- xkb_context_unref(context);
struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
wlr_seat_set_keyboard(seat, wlr_device);