Skip to content

Commit 5250eeb

Browse files
RedSoxFanddevault
authored andcommitted
input/cursor: handle setting a NULL image surface
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.
1 parent 9d48a3d commit 5250eeb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Diff for: sway/input/cursor.c

+13-7
Original file line numberDiff line numberDiff line change
@@ -798,17 +798,26 @@ static void handle_image_surface_destroy(struct wl_listener *listener,
798798
cursor_rebase(cursor);
799799
}
800800

801+
static void set_image_surface(struct sway_cursor *cursor,
802+
struct wlr_surface *surface) {
803+
wl_list_remove(&cursor->image_surface_destroy.link);
804+
cursor->image_surface = surface;
805+
if (surface) {
806+
wl_signal_add(&surface->events.destroy, &cursor->image_surface_destroy);
807+
} else {
808+
wl_list_init(&cursor->image_surface_destroy.link);
809+
}
810+
}
811+
801812
void cursor_set_image(struct sway_cursor *cursor, const char *image,
802813
struct wl_client *client) {
803814
if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
804815
return;
805816
}
806817

807818
const char *current_image = cursor->image;
819+
set_image_surface(cursor, NULL);
808820
cursor->image = image;
809-
wl_list_remove(&cursor->image_surface_destroy.link);
810-
cursor->image_surface = NULL;
811-
wl_list_init(&cursor->image_surface_destroy.link);
812821
cursor->hotspot_x = cursor->hotspot_y = 0;
813822
cursor->image_client = client;
814823

@@ -831,11 +840,8 @@ void cursor_set_image_surface(struct sway_cursor *cursor,
831840
return;
832841
}
833842

843+
set_image_surface(cursor, surface);
834844
cursor->image = NULL;
835-
wl_list_remove(&cursor->image_surface_destroy.link);
836-
cursor->image_surface = surface;
837-
wl_signal_add(&cursor->image_surface->events.destroy,
838-
&cursor->image_surface_destroy);
839845
cursor->hotspot_x = hotspot_x;
840846
cursor->hotspot_y = hotspot_y;
841847
cursor->image_client = client;

0 commit comments

Comments
 (0)