summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2020-01-05 22:29:32 -0500
committerDrew DeVault <sir@cmpwn.com>2020-01-08 10:27:20 -0500
commit5250eebafea0fd62297f9de85a58d5fe095967b3 (patch)
tree3ec41ff19f71cae858236292e004b5938be34a1f
parent9d48a3d78d830a5bd432267e3be065d526543a5f (diff)
input/cursor: handle setting a NULL image surface1.3-rc2
This fixes a crash when attempting to listen to a signal on a NULL cursor image surface. If the surface is NULL, the listener is just reinitialized using wl_list_init.
-rw-r--r--sway/input/cursor.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 215dc7672..9d14c585a 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -798,6 +798,17 @@ static void handle_image_surface_destroy(struct wl_listener *listener,
cursor_rebase(cursor);
}
+static void set_image_surface(struct sway_cursor *cursor,
+ struct wlr_surface *surface) {
+ wl_list_remove(&cursor->image_surface_destroy.link);
+ cursor->image_surface = surface;
+ if (surface) {
+ wl_signal_add(&surface->events.destroy, &cursor->image_surface_destroy);
+ } else {
+ wl_list_init(&cursor->image_surface_destroy.link);
+ }
+}
+
void cursor_set_image(struct sway_cursor *cursor, const char *image,
struct wl_client *client) {
if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
@@ -805,10 +816,8 @@ void cursor_set_image(struct sway_cursor *cursor, const char *image,
}
const char *current_image = cursor->image;
+ set_image_surface(cursor, NULL);
cursor->image = image;
- wl_list_remove(&cursor->image_surface_destroy.link);
- cursor->image_surface = NULL;
- wl_list_init(&cursor->image_surface_destroy.link);
cursor->hotspot_x = cursor->hotspot_y = 0;
cursor->image_client = client;
@@ -831,11 +840,8 @@ void cursor_set_image_surface(struct sway_cursor *cursor,
return;
}
+ set_image_surface(cursor, surface);
cursor->image = NULL;
- wl_list_remove(&cursor->image_surface_destroy.link);
- cursor->image_surface = surface;
- wl_signal_add(&cursor->image_surface->events.destroy,
- &cursor->image_surface_destroy);
cursor->hotspot_x = hotspot_x;
cursor->hotspot_y = hotspot_y;
cursor->image_client = client;