]> git.mdlowis.com Git - proto/labwc.git/commitdiff
keyboard: use 'us' as fallback for XKB_DEFAULT_LAYOUT
authorJohan Malm <jgm323@gmail.com>
Mon, 11 Mar 2024 22:04:52 +0000 (22:04 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 12 Mar 2024 20:59:39 +0000 (20:59 +0000)
...if keymap cannot be created for the provided XKB_DEFAULT_LAYOUT.

If keymap still cannot be created, exit with a helpful message to avoid
crash that is hard to understand.

Fixes: https://github.com/stefonarch/lxqt-labwc-session/issues/7
src/input/keyboard.c
src/seat.c

index 4a68428b005757c7694e4ad1f0c809e3e6cc4c20..0ca6d390d586c773268c9ec1e4f82f9eb205a535 100644 (file)
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#define _POSIX_C_SOURCE 200809L
 #include <assert.h>
+#include <stdlib.h>
 #include <wlr/backend/multi.h>
 #include <wlr/backend/session.h>
 #include <wlr/interfaces/wlr_keyboard.h>
@@ -628,6 +630,8 @@ reset_window_keyboard_layout_groups(struct server *server)
 static void
 set_layout(struct server *server, struct wlr_keyboard *kb)
 {
+       static bool fallback_mode;
+
        struct xkb_rule_names rules = { 0 };
        struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
        struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules,
@@ -639,7 +643,14 @@ set_layout(struct server *server, struct wlr_keyboard *kb)
                }
                xkb_keymap_unref(keymap);
        } else {
-               wlr_log(WLR_ERROR, "Failed to create xkb keymap");
+               wlr_log(WLR_ERROR, "failed to create xkb keymap for layout '%s'",
+                       getenv("XKB_DEFAULT_LAYOUT"));
+               if (!fallback_mode) {
+                       wlr_log(WLR_ERROR, "entering fallback mode with layout 'us'");
+                       fallback_mode = true;
+                       setenv("XKB_DEFAULT_LAYOUT", "us", 1);
+                       set_layout(server, kb);
+               }
        }
        xkb_context_unref(context);
 }
index 4ef175d901527ef27f3ccb78739ac1c89609b9fa..53861edc1908300cdd4f4f556f09f10e29a8fe27 100644 (file)
@@ -296,6 +296,11 @@ new_keyboard(struct seat *seat, struct wlr_input_device *device, bool virtual)
        keyboard->wlr_keyboard = kb;
        keyboard->is_virtual = virtual;
 
+       if (!seat->keyboard_group->keyboard.keymap) {
+               wlr_log(WLR_ERROR, "cannot set keymap");
+               exit(EXIT_FAILURE);
+       }
+
        wlr_keyboard_set_keymap(kb, seat->keyboard_group->keyboard.keymap);
 
        /*