]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xwayland: flush XCB connection to mitigate race between Raise and input
authorJohn Lindgren <john@jlindgren.net>
Tue, 2 Dec 2025 18:33:07 +0000 (13:33 -0500)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 2 Dec 2025 18:50:03 +0000 (19:50 +0100)
include/xwayland.h
src/view.c
src/xwayland.c

index 5fa20e116e9a19ec0b2148548a2c384fcb297494..bbb9fa1cd7bfa14a5a4bb99cb2f61184b1efc6f3 100644 (file)
@@ -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 */
index bd8f0a64d90983cf0a9d8765d6c5404841c9113a..c439b443e488ddd4931aa8b4ff1c16ec13242ff5 100644 (file)
@@ -35,6 +35,7 @@
 
 #if HAVE_XWAYLAND
 #include <wlr/xwayland.h>
+#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);
 }
index 0fd2168e63008db91936da750d59690a362c34bb..564fa3e2bab69fb1a259b3210f71533a3af51d4a 100644 (file)
@@ -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));
+}