diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2020-01-05 22:29:32 -0500 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-01-06 10:12:28 +0100 |
commit | 1e2a2b07781057cd23f41411418e8b5870bf5b89 (patch) | |
tree | be9da1b1b96454f217a57f03e30f3fbaef95cbf1 | |
parent | input/cursor: handle image surface destroy (diff) | |
download | sway-1e2a2b07781057cd23f41411418e8b5870bf5b89.tar.gz sway-1e2a2b07781057cd23f41411418e8b5870bf5b89.tar.zst sway-1e2a2b07781057cd23f41411418e8b5870bf5b89.zip |
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.
-rw-r--r-- | sway/input/cursor.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 215dc767..9d14c585 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, | |||
798 | cursor_rebase(cursor); | 798 | cursor_rebase(cursor); |
799 | } | 799 | } |
800 | 800 | ||
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 | |||
801 | void cursor_set_image(struct sway_cursor *cursor, const char *image, | 812 | void cursor_set_image(struct sway_cursor *cursor, const char *image, |
802 | struct wl_client *client) { | 813 | struct wl_client *client) { |
803 | if (!(cursor->seat->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { | 814 | 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, | |||
805 | } | 816 | } |
806 | 817 | ||
807 | const char *current_image = cursor->image; | 818 | const char *current_image = cursor->image; |
819 | set_image_surface(cursor, NULL); | ||
808 | cursor->image = image; | 820 | 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); | ||
812 | cursor->hotspot_x = cursor->hotspot_y = 0; | 821 | cursor->hotspot_x = cursor->hotspot_y = 0; |
813 | cursor->image_client = client; | 822 | cursor->image_client = client; |
814 | 823 | ||
@@ -831,11 +840,8 @@ void cursor_set_image_surface(struct sway_cursor *cursor, | |||
831 | return; | 840 | return; |
832 | } | 841 | } |
833 | 842 | ||
843 | set_image_surface(cursor, surface); | ||
834 | cursor->image = NULL; | 844 | 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); | ||
839 | cursor->hotspot_x = hotspot_x; | 845 | cursor->hotspot_x = hotspot_x; |
840 | cursor->hotspot_y = hotspot_y; | 846 | cursor->hotspot_y = hotspot_y; |
841 | cursor->image_client = client; | 847 | cursor->image_client = client; |