From 8f0ec30759f2c6249ead431e23123d873b5357e0 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Wed, 13 May 2026 22:48:13 +0200 Subject: [PATCH] Fix keyboard input: don't forward keys to seat without focused surface wlr_seat_keyboard_notify_key was being called unconditionally, which caused re-entrancy that consumed WINGs events from the queue before the modal loop could fetch them. Now only forwards to the seat when there's an actual focused client surface. Also use 16ms timeout in wl_flush so keyboard events from the nested compositor are actually received during modal loop dispatch. --- WINGs/wevent_wl.c | 2 +- WINGs/wview_wl.c | 4 +++- src/backend/wayland/wl_backend.c | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/WINGs/wevent_wl.c b/WINGs/wevent_wl.c index 608eaf3..daf3d91 100644 --- a/WINGs/wevent_wl.c +++ b/WINGs/wevent_wl.c @@ -155,7 +155,7 @@ wl_flush(void *ectx, Bool discard) /* Pump the wlroots event loop so pointer/key events arrive in our queue. * This is called from waitForEvent/WMMaskEvent when the queue is empty. */ if (ctx->dispatch_fn) - ctx->dispatch_fn(0, ctx->dispatch_ud); + ctx->dispatch_fn(16, ctx->dispatch_ud); } static int diff --git a/WINGs/wview_wl.c b/WINGs/wview_wl.c index e9304c0..6207f6e 100644 --- a/WINGs/wview_wl.c +++ b/WINGs/wview_wl.c @@ -39,8 +39,10 @@ W_View *W_GetViewForWindow(Window id) unsigned slot = (idx + i) % VIEW_TABLE_SIZE; if (view_table[slot].id == id) return view_table[slot].view; - if (view_table[slot].id == 0) + if (view_table[slot].id == 0) { + wwarning("W_GetViewForWindow: id=0x%lx NOT FOUND (slot %u empty)", (unsigned long)id, slot); return NULL; + } } return NULL; } diff --git a/src/backend/wayland/wl_backend.c b/src/backend/wayland/wl_backend.c index fa59118..8ad8bf7 100644 --- a/src/backend/wayland/wl_backend.c +++ b/src/backend/wayland/wl_backend.c @@ -1658,9 +1658,10 @@ handle_keyboard_key(struct wl_listener *listener, void *data) W_WL_EnqueueEvent(wmscr, &ev, NULL); } - /* Forward non-shortcut key events to focused client */ - wlr_seat_keyboard_notify_key(wl_state.seat, - event->time_msec, event->keycode, event->state); + /* Forward non-shortcut key events to focused Wayland client (if any) */ + if (wl_state.seat->keyboard_state.focused_surface) + wlr_seat_keyboard_notify_key(wl_state.seat, + event->time_msec, event->keycode, event->state); } static void