Fix cleanup old cursor surface in wlr_output_set_cursor_surface

This commit is contained in:
emersion 2017-10-09 15:23:58 +02:00
parent 8492174088
commit b76e64e7bf
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -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); return set_cursor(output, buf, stride, width, height, hotspot_x, hotspot_y);
} }
static void handle_cursor_surface_commit(struct wl_listener *listener, static void commit_cursor_surface(struct wlr_output *output,
void *data) { struct wlr_surface *surface) {
struct wlr_output *output = wl_container_of(listener, output,
cursor.surface_commit);
struct wlr_surface *surface = data;
struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer);
if (buffer == NULL) { if (buffer == NULL) {
return; return;
@ -198,6 +194,15 @@ static void handle_cursor_surface_commit(struct wl_listener *listener,
wl_shm_buffer_end_access(buffer); 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, static void handle_cursor_surface_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct wlr_output *output = wl_container_of(listener, output, 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; output->cursor.hotspot_y = hotspot_y;
if (surface && output->cursor.surface == surface) { if (surface && output->cursor.surface == surface) {
commit_cursor_surface(output, surface);
return; return;
} }
output->cursor.surface = surface;
if (output->cursor.surface) { if (output->cursor.surface) {
wl_list_remove(&output->cursor.surface_commit.link); 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 = NULL;
} }
output->cursor.surface = surface;
if (surface != NULL) { if (surface != NULL) {
wl_signal_add(&surface->events.commit, &output->cursor.surface_commit); wl_signal_add(&surface->events.commit, &output->cursor.surface_commit);
wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy); wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy);
commit_cursor_surface(output, surface);
} else { } else {
set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y); set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y);
} }