From ccf00830d4aa60921d266c343cf4037e9d02ff97 Mon Sep 17 00:00:00 2001 From: Jason Perlow Date: Sun, 25 Oct 2026 17:17:47 -0400 Subject: [PATCH] fix(lockscreen): reset the xkb state with the keymap and report a missing keymap kb_keymap() unreferenced the old xkb_state but left the pointer set. Reset it together with the keymap. Each keymap failure path also returned silently, which left a lock that drew normally but dropped every key; log the reason, and show "Keyboard unavailable" when a key arrives without a keymap. Assisted-by: Claude Code:claude-opus-5-5 AI-Scope: reset the xkb_state with the keymap, added failure logging in kb_keymap and the unavailable status in kb_key in lock_main.c. --- src/lockscreen/lock_main.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/lockscreen/lock_main.c b/src/lockscreen/lock_main.c index c970724..1f5f18f 100644 --- a/src/lockscreen/lock_main.c +++ b/src/lockscreen/lock_main.c @@ -802,20 +802,31 @@ static void keypad_activate(int i) { /* ── Keyboard ───────────────────────────────────────────────────────────── */ static void kb_keymap(void *data, struct wl_keyboard *kb, uint32_t format, int fd, uint32_t size) { - if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { close(fd); return; } + if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { + fprintf(stderr, "lock: unsupported keymap format %u\n", format); + close(fd); + return; + } char *map = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); - if (map == MAP_FAILED) return; + if (map == MAP_FAILED) { + fprintf(stderr, "lock: cannot map the keymap\n"); + return; + } if (xkb_keymap) xkb_keymap_unref(xkb_keymap); if (xkb_state) xkb_state_unref(xkb_state); + xkb_state = NULL; xkb_keymap = xkb_keymap_new_from_string(xkb_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(map, size); - if (xkb_keymap) { - xkb_state = xkb_state_new(xkb_keymap); - loginui_keypad_set_keymap(&keypad, xkb_keymap); - render_all(); + if (!xkb_keymap) { + fprintf(stderr, "lock: cannot compile the keymap\n"); + return; } + xkb_state = xkb_state_new(xkb_keymap); + if (!xkb_state) fprintf(stderr, "lock: cannot create the keyboard state\n"); + loginui_keypad_set_keymap(&keypad, xkb_keymap); + render_all(); } static void kb_enter(void *d, struct wl_keyboard *kb, uint32_t s, struct wl_surface *sf, struct wl_array *keys) {} static void kb_leave(void *d, struct wl_keyboard *kb, uint32_t s, struct wl_surface *sf) {} @@ -827,8 +838,14 @@ static void kb_repeat(void *d, struct wl_keyboard *kb, int32_t rate, int32_t del static void kb_key(void *data, struct wl_keyboard *kb, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { - if (!xkb_state || state != WL_KEYBOARD_KEY_STATE_PRESSED) return; + if (state != WL_KEYBOARD_KEY_STATE_PRESSED) return; if (anim_phase == PHASE_LEAVE) return; + if (!xkb_state) { + snprintf(status_text, sizeof status_text, "%s", "Keyboard unavailable"); + status_error = true; + render_all(); + return; + } xkb_keycode_t kc = key + 8; xkb_keysym_t sym = xkb_state_key_get_one_sym(xkb_state, kc); gesture.last_input = now_s();