Skip to content

Commit

Permalink
keyboard: use 'us' as fallback for XKB_DEFAULT_LAYOUT
Browse files Browse the repository at this point in the history
...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: stefonarch/lxqt-labwc-session#7
  • Loading branch information
johanmalm authored and txgk committed Apr 19, 2024
1 parent f58a8c2 commit 6cfdf69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/input/keyboard.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand Down

0 comments on commit 6cfdf69

Please sign in to comment.