From d748dc78bc0e50a5ae6abf366f19b36d02303585 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Tue, 2 Dec 2025 13:33:07 -0500 Subject: [PATCH] xwayland: flush XCB connection to mitigate race between Raise and input --- include/xwayland.h | 2 ++ src/view.c | 12 ++++++++++++ src/xwayland.c | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/xwayland.h b/include/xwayland.h index 5fa20e11..bbb9fa1c 100644 --- a/include/xwayland.h +++ b/include/xwayland.h @@ -77,5 +77,7 @@ void xwayland_update_workarea(struct server *server); void xwayland_reset_cursor(struct server *server); +void xwayland_flush(struct server *server); + #endif /* HAVE_XWAYLAND */ #endif /* LABWC_XWAYLAND_H */ diff --git a/src/view.c b/src/view.c index bd8f0a64..c439b443 100644 --- a/src/view.c +++ b/src/view.c @@ -35,6 +35,7 @@ #if HAVE_XWAYLAND #include +#include "xwayland.h" #endif struct view * @@ -2247,6 +2248,17 @@ view_move_to_front(struct view *view) move_to_front(view); } +#if HAVE_XWAYLAND + /* + * view_move_to_front() is typically called on each mouse press + * via Raise action. This means we are restacking windows just + * about at the same time we send the mouse press input to the + * X server, and creates a race where the mouse press could go + * to an incorrect X window depending on timing. To mitigate the + * race, perform an explicit flush after restacking. + */ + xwayland_flush(view->server); +#endif cursor_update_focus(view->server); desktop_update_top_layer_visibility(view->server); } diff --git a/src/xwayland.c b/src/xwayland.c index 0fd2168e..564fa3e2 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -1438,3 +1438,13 @@ xwayland_update_workarea(struct server *server) }; wlr_xwayland_set_workareas(server->xwayland, &workarea, 1); } + +void +xwayland_flush(struct server *server) +{ + if (!server->xwayland || !server->xwayland->xwm) { + return; + } + + xcb_flush(wlr_xwayland_get_xwm_connection(server->xwayland)); +}