From 6cfdf69ecca3381a90e629bd042318a57d0bbf6a Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 11 Mar 2024 22:04:52 +0000 Subject: [PATCH] keyboard: use 'us' as fallback for XKB_DEFAULT_LAYOUT ...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 | 13 ++++++++++++- src/seat.c | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/input/keyboard.c b/src/input/keyboard.c index 4a68428b00..0ca6d390d5 100644 --- a/src/input/keyboard.c +++ b/src/input/keyboard.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only +#define _POSIX_C_SOURCE 200809L #include +#include #include #include #include @@ -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); } diff --git a/src/seat.c b/src/seat.c index 4ef175d901..53861edc19 100644 --- a/src/seat.c +++ b/src/seat.c @@ -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); /*