]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cursor: Prevent setting the same cursor image twice
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sat, 10 Sep 2022 17:48:49 +0000 (19:48 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 11 Sep 2022 12:30:10 +0000 (13:30 +0100)
Possibly fixes #512

Reported-by: @Flrian
src/cursor.c

index 10647e9169f24ecc52c495038b37d8d5d114414c..c8aa7da4d31fbb117977a3991b1e701793e00b74 100644 (file)
 #include "ssd.h"
 #include "config/mousebind.h"
 #include "common/scene-helpers.h"
+#include "common/zfree.h"
+
+/* Used to prevent setting the same cursor image twice */
+static char *last_cursor_image = NULL;
 
 static bool
 is_surface(enum ssd_part_type view_area)
@@ -99,8 +103,13 @@ request_cursor_notify(struct wl_listener *listener, void *data)
                 * hardware cursor on the output that it's currently on and
                 * continue to do so as the cursor moves between outputs.
                 */
+
                wlr_cursor_set_surface(seat->cursor, event->surface,
-                                      event->hotspot_x, event->hotspot_y);
+                       event->hotspot_x, event->hotspot_y);
+
+               if (last_cursor_image) {
+                       zfree(last_cursor_image);
+               }
        }
 }
 
@@ -197,6 +206,15 @@ process_cursor_resize(struct server *server, uint32_t time)
 void
 cursor_set(struct seat *seat, const char *cursor_name)
 {
+       if (last_cursor_image) {
+               if (!strcmp(last_cursor_image, cursor_name)) {
+                       /* Prevent setting the same cursor image twice */
+                       return;
+               }
+               free(last_cursor_image);
+       }
+       last_cursor_image = strdup(cursor_name);
+
        wlr_xcursor_manager_set_cursor_image(
                seat->xcursor_manager, cursor_name, seat->cursor);
 }