From b76e64e7bf5c24488cf6a37174d1858e2256578a Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 9 Oct 2017 15:23:58 +0200 Subject: [PATCH] Fix cleanup old cursor surface in wlr_output_set_cursor_surface --- types/wlr_output.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 83d6713f..011451be 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -171,12 +171,8 @@ bool wlr_output_set_cursor(struct wlr_output *output, return set_cursor(output, buf, stride, width, height, hotspot_x, hotspot_y); } -static void handle_cursor_surface_commit(struct wl_listener *listener, - void *data) { - struct wlr_output *output = wl_container_of(listener, output, - cursor.surface_commit); - struct wlr_surface *surface = data; - +static void commit_cursor_surface(struct wlr_output *output, + struct wlr_surface *surface) { struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); if (buffer == NULL) { return; @@ -198,6 +194,15 @@ static void handle_cursor_surface_commit(struct wl_listener *listener, wl_shm_buffer_end_access(buffer); } +static void handle_cursor_surface_commit(struct wl_listener *listener, + void *data) { + struct wlr_output *output = wl_container_of(listener, output, + cursor.surface_commit); + struct wlr_surface *surface = data; + + commit_cursor_surface(output, surface); +} + static void handle_cursor_surface_destroy(struct wl_listener *listener, void *data) { struct wlr_output *output = wl_container_of(listener, output, @@ -218,9 +223,9 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, output->cursor.hotspot_y = hotspot_y; if (surface && output->cursor.surface == surface) { + commit_cursor_surface(output, surface); return; } - output->cursor.surface = surface; if (output->cursor.surface) { wl_list_remove(&output->cursor.surface_commit.link); @@ -228,9 +233,12 @@ void wlr_output_set_cursor_surface(struct wlr_output *output, output->cursor.surface = NULL; } + output->cursor.surface = surface; + if (surface != NULL) { wl_signal_add(&surface->events.commit, &output->cursor.surface_commit); wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy); + commit_cursor_surface(output, surface); } else { set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); }