From c5f7f8ab983496f7bdced3c0944c739ba7dab338 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 1 Feb 2023 20:14:12 +0100 Subject: [PATCH] ext-session-lock-v1: convert to try_from References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/884 --- include/wlr/types/wlr_session_lock_v1.h | 13 ++++--------- types/wlr_session_lock_v1.c | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/wlr/types/wlr_session_lock_v1.h b/include/wlr/types/wlr_session_lock_v1.h index b6eee1a3..aff37871 100644 --- a/include/wlr/types/wlr_session_lock_v1.h +++ b/include/wlr/types/wlr_session_lock_v1.h @@ -94,18 +94,13 @@ uint32_t wlr_session_lock_surface_v1_configure( struct wlr_session_lock_surface_v1 *lock_surface, uint32_t width, uint32_t height); -/** - * Returns true if the surface has the session lock surface role. - */ -bool wlr_surface_is_session_lock_surface_v1(struct wlr_surface *surface); - /** * Get a struct wlr_session_lock_surface_v1 from a struct wlr_surface. - * Asserts that the surface has the session lock surface role. - * May return NULL even if the surface has the session lock surface role if the - * corresponding session lock surface has been destroyed. + * + * Returns NULL if the surface has a different role or if the lock surface + * has been destroyed. */ -struct wlr_session_lock_surface_v1 *wlr_session_lock_surface_v1_from_wlr_surface( +struct wlr_session_lock_surface_v1 *wlr_session_lock_surface_v1_try_from_wlr_surface( struct wlr_surface *surface); #endif diff --git a/types/wlr_session_lock_v1.c b/types/wlr_session_lock_v1.c index aaa46fd8..c24e05ce 100644 --- a/types/wlr_session_lock_v1.c +++ b/types/wlr_session_lock_v1.c @@ -48,13 +48,11 @@ static struct wlr_session_lock_surface_v1 *lock_surface_from_resource( static const struct wlr_surface_role lock_surface_role; -bool wlr_surface_is_session_lock_surface_v1(struct wlr_surface *surface) { - return surface->role == &lock_surface_role; -} - -struct wlr_session_lock_surface_v1 *wlr_session_lock_surface_v1_from_wlr_surface( +struct wlr_session_lock_surface_v1 *wlr_session_lock_surface_v1_try_from_wlr_surface( struct wlr_surface *surface) { - assert(wlr_surface_is_session_lock_surface_v1(surface)); + if (surface->role != &lock_surface_role) { + return NULL; + } return (struct wlr_session_lock_surface_v1 *)surface->role_data; } @@ -133,7 +131,8 @@ static const struct ext_session_lock_surface_v1_interface lock_surface_implement static void lock_surface_role_commit(struct wlr_surface *surface) { struct wlr_session_lock_surface_v1 *lock_surface = - wlr_session_lock_surface_v1_from_wlr_surface(surface); + wlr_session_lock_surface_v1_try_from_wlr_surface(surface); + assert(lock_surface != NULL); if (!lock_surface->configured) { wl_resource_post_error(lock_surface->resource, @@ -162,7 +161,8 @@ static void lock_surface_role_commit(struct wlr_surface *surface) { static void lock_surface_role_precommit(struct wlr_surface *surface, const struct wlr_surface_state *state) { struct wlr_session_lock_surface_v1 *lock_surface = - wlr_session_lock_surface_v1_from_wlr_surface(surface); + wlr_session_lock_surface_v1_try_from_wlr_surface(surface); + assert(lock_surface != NULL); if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) { wl_resource_post_error(lock_surface->resource, @@ -174,7 +174,8 @@ static void lock_surface_role_precommit(struct wlr_surface *surface, static void lock_surface_role_destroy(struct wlr_surface *surface) { struct wlr_session_lock_surface_v1 *lock_surface = - wlr_session_lock_surface_v1_from_wlr_surface(surface); + wlr_session_lock_surface_v1_try_from_wlr_surface(surface); + assert(lock_surface != NULL); wl_signal_emit_mutable(&lock_surface->events.destroy, NULL);