]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xwayland: reset cursor image on cursor theme reload
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sun, 9 Jun 2024 22:01:54 +0000 (00:01 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 11 Jun 2024 20:40:06 +0000 (21:40 +0100)
As wlr_xwayland caches the pixel data when not yet started
up due to the delayed lazy startup approach, we do have to
re-set the xwayland cursor image when reloading the cursor
theme. Otherwise the first X11 client connected will cause
the xwayland server to use the cached (and destroyed) pixel
data.

To reproduce:
- Compile with b_sanitize=address,undefined
- Start labwc (nothing in autostart that could create
  a X11 connection, e.g. no GTK or X11 application)
- Reconfigure
- Start some X11 client

include/xwayland.h
src/input/cursor.c
src/xwayland.c

index 0072106e8c1060671d8d4085252572ca9cdcd70c..99867e3e10d365a19314731d37f3113948bba943 100644 (file)
@@ -95,5 +95,7 @@ void xwayland_adjust_usable_area(struct view *view,
 
 void xwayland_update_workarea(struct server *server);
 
+void xwayland_reset_cursor(struct server *server);
+
 #endif /* HAVE_XWAYLAND */
 #endif /* LABWC_XWAYLAND_H */
index 975a295e00959d087c641002b4f3e8ad456f71dd..3e3c0003b626588628bee4f26a19663f14b451a7 100644 (file)
@@ -26,6 +26,7 @@
 #include "resistance.h"
 #include "ssd.h"
 #include "view.h"
+#include "xwayland.h"
 
 #define LAB_CURSOR_SHAPE_V1_VERSION 1
 
@@ -1403,6 +1404,9 @@ void
 cursor_reload(struct seat *seat)
 {
        cursor_load(seat);
+#if HAVE_XWAYLAND
+       xwayland_reset_cursor(seat->server);
+#endif
        cursor_update_image(seat);
 }
 
index 2e537038253646f6ad80483cfc07420e4b830b56..d4eff83d659b605acf1579cfcd8b78c81d5d4bf8 100644 (file)
@@ -1128,6 +1128,56 @@ xwayland_adjust_stacking_order(struct server *server)
        wl_array_release(&views);
 }
 
+void
+xwayland_reset_cursor(struct server *server)
+{
+       /*
+        * As xwayland caches the pixel data when not yet started up
+        * due to the delayed lazy startup approach, we do have to
+        * re-set the xwayland cursor image. Otherwise the first X11
+        * client connected will cause the xwayland server to use
+        * the cached (and potentially destroyed) pixel data.
+        *
+        * Calling this function after reloading the cursor theme
+        * ensures that the cached pixel data keeps being valid.
+        *
+        * To reproduce:
+        * - Compile with b_sanitize=address,undefined
+        * - Start labwc (nothing in autostart that could create
+        *   a X11 connection, e.g. no GTK or X11 application)
+        * - Reconfigure
+        * - Start some X11 client
+        */
+
+       if (!server->xwayland) {
+               return;
+       }
+
+       struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(
+               server->seat.xcursor_manager, XCURSOR_DEFAULT, 1);
+
+       if (xcursor && !server->xwayland->xwm) {
+               /* Prevents setting the cursor on an active xwayland server */
+               struct wlr_xcursor_image *image = xcursor->images[0];
+               wlr_xwayland_set_cursor(server->xwayland, image->buffer,
+                       image->width * 4, image->width,
+                       image->height, image->hotspot_x,
+                       image->hotspot_y);
+               return;
+       }
+
+       if (server->xwayland->cursor) {
+               /*
+                * The previous configured theme has set the
+                * default cursor or the xwayland server is
+                * currently running but still has a cached
+                * xcursor set that will be used on the next
+                * xwayland destroy -> lazy startup cycle.
+                */
+               zfree(server->xwayland->cursor);
+       }
+}
+
 void
 xwayland_server_finish(struct server *server)
 {