From 0ea6b6e2cc490f3fbd0b92b03c0ae6eed2c0bbbf Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 8 Dec 2023 14:09:27 +0100 Subject: [PATCH] session-lock-v1: use wlr_surface_synced --- include/wlr/types/wlr_session_lock_v1.h | 3 +++ types/wlr_session_lock_v1.c | 30 ++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/wlr/types/wlr_session_lock_v1.h b/include/wlr/types/wlr_session_lock_v1.h index 981e2240..058bf0d7 100644 --- a/include/wlr/types/wlr_session_lock_v1.h +++ b/include/wlr/types/wlr_session_lock_v1.h @@ -12,6 +12,7 @@ #include #include #include +#include struct wlr_session_lock_manager_v1 { struct wl_global *global; @@ -80,6 +81,8 @@ struct wlr_session_lock_surface_v1 { // private state + struct wlr_surface_synced synced; + struct wl_listener output_destroy; }; diff --git a/types/wlr_session_lock_v1.c b/types/wlr_session_lock_v1.c index 1979e7e4..d5a1a826 100644 --- a/types/wlr_session_lock_v1.c +++ b/types/wlr_session_lock_v1.c @@ -38,7 +38,7 @@ static void lock_surface_destroy(struct wlr_session_lock_surface_v1 *lock_surfac assert(wl_list_empty(&lock_surface->events.destroy.listener_list)); wl_list_remove(&lock_surface->output_destroy.link); - + wlr_surface_synced_finish(&lock_surface->synced); wl_resource_set_user_data(lock_surface->resource, NULL); free(lock_surface); } @@ -149,14 +149,14 @@ static const struct ext_session_lock_surface_v1_interface lock_surface_implement .ack_configure = lock_surface_handle_ack_configure, }; -static void lock_surface_role_commit(struct wlr_surface *surface) { +static void lock_surface_role_client_commit(struct wlr_surface *surface) { struct wlr_session_lock_surface_v1 *lock_surface = wlr_session_lock_surface_v1_try_from_wlr_surface(surface); if (lock_surface == NULL) { return; } - if (!wlr_surface_has_buffer(surface)) { + if (!wlr_surface_state_has_buffer(&surface->pending)) { wl_resource_post_error(lock_surface->resource, EXT_SESSION_LOCK_SURFACE_V1_ERROR_NULL_BUFFER, "session lock surface is committed with a null buffer"); @@ -170,15 +170,21 @@ static void lock_surface_role_commit(struct wlr_surface *surface) { return; } - if ((uint32_t)surface->current.width != lock_surface->pending.width || - (uint32_t)surface->current.height != lock_surface->pending.height) { + if ((uint32_t)surface->pending.width != lock_surface->pending.width || + (uint32_t)surface->pending.height != lock_surface->pending.height) { wl_resource_post_error(lock_surface->resource, EXT_SESSION_LOCK_SURFACE_V1_ERROR_DIMENSIONS_MISMATCH, "committed surface dimensions do not match last acked configure"); return; } +} - lock_surface->current = lock_surface->pending; +static void lock_surface_role_commit(struct wlr_surface *surface) { + struct wlr_session_lock_surface_v1 *lock_surface = + wlr_session_lock_surface_v1_try_from_wlr_surface(surface); + if (lock_surface == NULL) { + return; + } wlr_surface_map(surface); } @@ -194,10 +200,15 @@ static void lock_surface_role_destroy(struct wlr_surface *surface) { static const struct wlr_surface_role lock_surface_role = { .name = "ext_session_lock_surface_v1", + .client_commit = lock_surface_role_client_commit, .commit = lock_surface_role_commit, .destroy = lock_surface_role_destroy, }; +static const struct wlr_surface_synced_impl surface_synced_impl = { + .state_size = sizeof(struct wlr_session_lock_surface_v1_state), +}; + static void lock_surface_handle_output_destroy(struct wl_listener *listener, void *data) { struct wlr_session_lock_surface_v1 *lock_surface = @@ -268,6 +279,13 @@ static void lock_handle_get_lock_surface(struct wl_client *client, return; } + if (!wlr_surface_synced_init(&lock_surface->synced, surface, + &surface_synced_impl, &lock_surface->pending, &lock_surface->current)) { + free(lock_surface); + wl_client_post_no_memory(client); + return; + } + lock_surface->resource = lock_surface_resource; wl_resource_set_user_data(lock_surface_resource, lock_surface);