Skip to content

Commit

Permalink
input/cursor: handle setting a NULL image surface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RedSoxFan authored and ddevault committed Jan 8, 2020
1 parent 9d48a3d commit 5250eeb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sway/input/cursor.c
Expand Up @@ -798,17 +798,26 @@ 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)) {
return;
}

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;

Expand All @@ -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;
Expand Down

0 comments on commit 5250eeb

Please sign in to comment.