aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-02-01 20:14:39 +0100
committerSimon Ser <contact@emersion.fr>2023-02-01 20:14:39 +0100
commiteb3e8f08a8bb17f9b6260015b901cacbb9b0ce94 (patch)
treeb0b19e0b0a12b2b0be9e08abd42c0b1fb9d31cf6
parentc5f7f8ab983496f7bdced3c0944c739ba7dab338 (diff)
subcompositor: convert to try_from
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/884
-rw-r--r--include/wlr/types/wlr_subcompositor.h13
-rw-r--r--types/wlr_compositor.c8
-rw-r--r--types/wlr_subcompositor.c41
3 files changed, 22 insertions, 40 deletions
diff --git a/include/wlr/types/wlr_subcompositor.h b/include/wlr/types/wlr_subcompositor.h
index afbff45b..c292ea0c 100644
--- a/include/wlr/types/wlr_subcompositor.h
+++ b/include/wlr/types/wlr_subcompositor.h
@@ -63,17 +63,12 @@ struct wlr_subcompositor {
};
/**
- * Returns true if the surface has the subsurface role.
- */
-bool wlr_surface_is_subsurface(struct wlr_surface *surface);
-
-/**
* Get a struct wlr_subsurface from a struct wlr_surface.
- * Asserts that the surface has the subsurface role.
- * May return NULL even if the surface has the subsurface role if the
- * corresponding subsurface has been destroyed.
+ *
+ * Returns NULL if the surface doesn't have the subsurface role or if
+ * the subsurface has been destroyed.
*/
-struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
+struct wlr_subsurface *wlr_subsurface_try_from_wlr_surface(
struct wlr_surface *surface);
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display);
diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c
index 83c98ffc..f43641a2 100644
--- a/types/wlr_compositor.c
+++ b/types/wlr_compositor.c
@@ -812,12 +812,8 @@ void wlr_surface_unlock_cached(struct wlr_surface *surface, uint32_t seq) {
}
struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface) {
- while (wlr_surface_is_subsurface(surface)) {
- struct wlr_subsurface *subsurface =
- wlr_subsurface_from_wlr_surface(surface);
- if (subsurface == NULL) {
- break;
- }
+ struct wlr_subsurface *subsurface;
+ while ((subsurface = wlr_subsurface_try_from_wlr_surface(surface))) {
surface = subsurface->parent;
}
return surface;
diff --git a/types/wlr_subcompositor.c b/types/wlr_subcompositor.c
index 6e8a67a6..db4883e2 100644
--- a/types/wlr_subcompositor.c
+++ b/types/wlr_subcompositor.c
@@ -16,10 +16,7 @@ static bool subsurface_is_synchronized(struct wlr_subsurface *subsurface) {
return true;
}
- if (!wlr_surface_is_subsurface(subsurface->parent)) {
- break;
- }
- subsurface = wlr_subsurface_from_wlr_surface(subsurface->parent);
+ subsurface = wlr_subsurface_try_from_wlr_surface(subsurface->parent);
}
return false;
@@ -197,12 +194,10 @@ static void subsurface_consider_map(struct wlr_subsurface *subsurface) {
return;
}
- if (wlr_surface_is_subsurface(subsurface->parent)) {
- struct wlr_subsurface *parent =
- wlr_subsurface_from_wlr_surface(subsurface->parent);
- if (parent == NULL || !parent->mapped) {
- return;
- }
+ struct wlr_subsurface *parent =
+ wlr_subsurface_try_from_wlr_surface(subsurface->parent);
+ if (parent == NULL || !parent->mapped) {
+ return;
}
// Now we can map the subsurface
@@ -242,16 +237,16 @@ static void subsurface_unmap(struct wlr_subsurface *subsurface) {
}
static void subsurface_role_commit(struct wlr_surface *surface) {
- struct wlr_subsurface *subsurface =
- wlr_subsurface_from_wlr_surface(surface);
+ struct wlr_subsurface *subsurface = wlr_subsurface_try_from_wlr_surface(surface);
+ assert(subsurface != NULL);
subsurface_consider_map(subsurface);
}
static void subsurface_role_precommit(struct wlr_surface *surface,
const struct wlr_surface_state *state) {
- struct wlr_subsurface *subsurface =
- wlr_subsurface_from_wlr_surface(surface);
+ struct wlr_subsurface *subsurface = wlr_subsurface_try_from_wlr_surface(surface);
+ assert(subsurface != NULL);
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
@@ -260,8 +255,8 @@ static void subsurface_role_precommit(struct wlr_surface *surface,
}
static void subsurface_role_destroy(struct wlr_surface *surface) {
- struct wlr_subsurface *subsurface =
- wlr_subsurface_from_wlr_surface(surface);
+ struct wlr_subsurface *subsurface = wlr_subsurface_try_from_wlr_surface(surface);
+ assert(subsurface != NULL);
if (subsurface->has_cache) {
wlr_surface_unlock_cached(subsurface->surface,
@@ -403,13 +398,10 @@ static struct wlr_subsurface *subsurface_create(struct wlr_surface *surface,
return subsurface;
}
-bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
- return surface->role == &subsurface_role;
-}
-
-struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
- struct wlr_surface *surface) {
- assert(wlr_surface_is_subsurface(surface));
+struct wlr_subsurface *wlr_subsurface_try_from_wlr_surface(struct wlr_surface *surface) {
+ if (surface->role != &subsurface_role) {
+ return NULL;
+ }
return (struct wlr_subsurface *)surface->role_data;
}
@@ -435,8 +427,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
return;
}
- if (wlr_surface_is_subsurface(surface) &&
- wlr_subsurface_from_wlr_surface(surface) != NULL) {
+ if (wlr_subsurface_try_from_wlr_surface(surface) != NULL) {
wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",