From b0ab577474618bba26b133f942901b5545653566 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 13 Feb 2019 09:02:15 +0100 Subject: [PATCH 1/2] Moved wayland cursor handling to seat. --- uwac/libuwac/uwac-display.c | 15 --------------- uwac/libuwac/uwac-input.c | 22 ++++++++++++++++++++-- uwac/libuwac/uwac-priv.h | 5 ++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/uwac/libuwac/uwac-display.c b/uwac/libuwac/uwac-display.c index 3e485cbde..230c0c4ad 100644 --- a/uwac/libuwac/uwac-display.c +++ b/uwac/libuwac/uwac-display.c @@ -180,18 +180,6 @@ static void registry_handle_global(void* data, struct wl_registry* registry, uin { d->shm = wl_registry_bind(registry, id, &wl_shm_interface, min(TARGET_SHM_INTERFACE, version)); wl_shm_add_listener(d->shm, &shm_listener, d); - - d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm); - if (!d->cursor_theme) { - assert(uwacErrorHandler(d, UWAC_ERROR_NOMEMORY, "unable to get wayland cursor theme\n")); - return; - } - - d->default_cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); - if (!d->default_cursor) { - assert(uwacErrorHandler(d, UWAC_ERROR_NOMEMORY, "unable to get wayland cursor left_ptr\n")); - return; - } } else if (strcmp(interface, "wl_output") == 0) { @@ -596,9 +584,6 @@ UwacReturnCode UwacCloseDisplay(UwacDisplay** pdisplay) if (display->shell) wl_shell_destroy(display->shell); - if (display->cursor_theme) - wl_cursor_theme_destroy(display->cursor_theme); - if (display->shm) wl_shm_destroy(display->shm); diff --git a/uwac/libuwac/uwac-input.c b/uwac/libuwac/uwac-input.c index d67ff536e..34afb26c7 100644 --- a/uwac/libuwac/uwac-input.c +++ b/uwac/libuwac/uwac-input.c @@ -97,7 +97,7 @@ set_cursor_image(UwacSeat* seat, uint32_t serial) struct wl_surface* surface = NULL; int32_t x = 0, y = 0; - if (!seat || !seat->display || !seat->display->default_cursor || !seat->display->default_cursor->images) + if (!seat || !seat->display || !seat->default_cursor || !seat->default_cursor->images) return UWAC_ERROR_INTERNAL; switch(seat->pointer_type) { @@ -113,7 +113,7 @@ set_cursor_image(UwacSeat* seat, uint32_t serial) case 1: /* NULL pointer */ break; default: /* Default system pointer */ - cursor = seat->display->default_cursor; + cursor = seat->default_cursor; if (!cursor) return UWAC_ERROR_INTERNAL; image = cursor->images[0]; @@ -839,6 +839,19 @@ static void seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_s input->pointer = wl_seat_get_pointer(seat); wl_pointer_set_user_data(input->pointer, input); wl_pointer_add_listener(input->pointer, &pointer_listener, input); + + input->cursor_theme = wl_cursor_theme_load(NULL, 32, input->display->shm); + if (!input->cursor_theme) { + assert(uwacErrorHandler(input->display, UWAC_ERROR_NOMEMORY, "unable to get wayland cursor theme\n")); + return; + } + + input->default_cursor = wl_cursor_theme_get_cursor(input->cursor_theme, "left_ptr"); + if (!input->default_cursor) { + assert(uwacErrorHandler(input->display, UWAC_ERROR_NOMEMORY, "unable to get wayland cursor left_ptr\n")); + return; + } + } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) { #ifdef WL_POINTER_RELEASE_SINCE_VERSION if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION) @@ -846,6 +859,11 @@ static void seat_handle_capabilities(void *data, struct wl_seat *seat, enum wl_s else #endif wl_pointer_destroy(input->pointer); + if (input->cursor_theme) + wl_cursor_theme_destroy(input->cursor_theme); + + input->default_cursor = NULL; + input->cursor_theme = NULL; input->pointer = NULL; } diff --git a/uwac/libuwac/uwac-priv.h b/uwac/libuwac/uwac-priv.h index 125c92800..617908581 100644 --- a/uwac/libuwac/uwac-priv.h +++ b/uwac/libuwac/uwac-priv.h @@ -120,9 +120,6 @@ struct uwac_display { UwacTask dispatch_fd_task; uint32_t serial; - struct wl_cursor_theme *cursor_theme; - struct wl_cursor *default_cursor; - struct wl_list windows; struct wl_list outputs; @@ -160,6 +157,8 @@ struct uwac_seat { struct wl_pointer *pointer; struct wl_surface *pointer_surface; struct wl_cursor_image *pointer_image; + struct wl_cursor_theme *cursor_theme; + struct wl_cursor *default_cursor; void *pointer_data; size_t pointer_size; int pointer_type; From 073c54a368957cde7d705d1b7365ab949e059287 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 19 Feb 2019 09:29:17 +0100 Subject: [PATCH 2/2] Use safe iteration for seat removal. --- uwac/libuwac/uwac-display.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/uwac/libuwac/uwac-display.c b/uwac/libuwac/uwac-display.c index 230c0c4ad..af389e5ac 100644 --- a/uwac/libuwac/uwac-display.c +++ b/uwac/libuwac/uwac-display.c @@ -132,8 +132,8 @@ static const struct zwp_fullscreen_shell_v1_listener fullscreen_shell_listener = static void display_destroy_seat(UwacDisplay* d, uint32_t name) { - UwacSeat* seat; - wl_list_for_each(seat, &d->seats, link) + UwacSeat* seat, *tmp; + wl_list_for_each_safe(seat, tmp, &d->seats, link) { if (seat->seat_id == name) { @@ -225,12 +225,12 @@ static void registry_handle_global(void* data, struct wl_registry* registry, uin } else if (strcmp(interface, "wl_data_device_manager") == 0) { - UwacSeat* seat; + UwacSeat* seat, *tmp; d->data_device_manager = wl_registry_bind(registry, id, &wl_data_device_manager_interface, min(TARGET_DDM_INTERFACE, version)); - wl_list_for_each(seat, &d->seats, link) + wl_list_for_each_safe(seat, tmp, &d->seats, link) { UwacSeatRegisterDDM(seat); UwacSeatRegisterClipboard(seat); @@ -641,12 +641,12 @@ const char* UwacErrorString(UwacReturnCode error) UwacReturnCode UwacDisplayQueryInterfaceVersion(const UwacDisplay* display, const char* name, uint32_t* version) { - const UwacGlobal* global; + const UwacGlobal* global, *tmp; if (!display) return UWAC_ERROR_INVALID_DISPLAY; - wl_list_for_each(global, &display->globals, link) + wl_list_for_each_safe(global, tmp, &display->globals, link) { if (strcmp(global->interface, name) == 0) {