mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
subcompositor: convert to try_from
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/884
This commit is contained in:
parent
c5f7f8ab98
commit
eb3e8f08a8
3 changed files with 22 additions and 40 deletions
|
@ -62,18 +62,13 @@ struct wlr_subcompositor {
|
||||||
} events;
|
} events;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* 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
|
* Returns NULL if the surface doesn't have the subsurface role or if
|
||||||
* corresponding subsurface has been destroyed.
|
* 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_surface *surface);
|
||||||
|
|
||||||
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display);
|
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display);
|
||||||
|
|
|
@ -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) {
|
struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface) {
|
||||||
while (wlr_surface_is_subsurface(surface)) {
|
struct wlr_subsurface *subsurface;
|
||||||
struct wlr_subsurface *subsurface =
|
while ((subsurface = wlr_subsurface_try_from_wlr_surface(surface))) {
|
||||||
wlr_subsurface_from_wlr_surface(surface);
|
|
||||||
if (subsurface == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
surface = subsurface->parent;
|
surface = subsurface->parent;
|
||||||
}
|
}
|
||||||
return surface;
|
return surface;
|
||||||
|
|
|
@ -16,10 +16,7 @@ static bool subsurface_is_synchronized(struct wlr_subsurface *subsurface) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wlr_surface_is_subsurface(subsurface->parent)) {
|
subsurface = wlr_subsurface_try_from_wlr_surface(subsurface->parent);
|
||||||
break;
|
|
||||||
}
|
|
||||||
subsurface = wlr_subsurface_from_wlr_surface(subsurface->parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -197,13 +194,11 @@ static void subsurface_consider_map(struct wlr_subsurface *subsurface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wlr_surface_is_subsurface(subsurface->parent)) {
|
|
||||||
struct wlr_subsurface *parent =
|
struct wlr_subsurface *parent =
|
||||||
wlr_subsurface_from_wlr_surface(subsurface->parent);
|
wlr_subsurface_try_from_wlr_surface(subsurface->parent);
|
||||||
if (parent == NULL || !parent->mapped) {
|
if (parent == NULL || !parent->mapped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Now we can map the subsurface
|
// Now we can map the subsurface
|
||||||
subsurface->mapped = true;
|
subsurface->mapped = true;
|
||||||
|
@ -242,16 +237,16 @@ static void subsurface_unmap(struct wlr_subsurface *subsurface) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_role_commit(struct wlr_surface *surface) {
|
static void subsurface_role_commit(struct wlr_surface *surface) {
|
||||||
struct wlr_subsurface *subsurface =
|
struct wlr_subsurface *subsurface = wlr_subsurface_try_from_wlr_surface(surface);
|
||||||
wlr_subsurface_from_wlr_surface(surface);
|
assert(subsurface != NULL);
|
||||||
|
|
||||||
subsurface_consider_map(subsurface);
|
subsurface_consider_map(subsurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_role_precommit(struct wlr_surface *surface,
|
static void subsurface_role_precommit(struct wlr_surface *surface,
|
||||||
const struct wlr_surface_state *state) {
|
const struct wlr_surface_state *state) {
|
||||||
struct wlr_subsurface *subsurface =
|
struct wlr_subsurface *subsurface = wlr_subsurface_try_from_wlr_surface(surface);
|
||||||
wlr_subsurface_from_wlr_surface(surface);
|
assert(subsurface != NULL);
|
||||||
|
|
||||||
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
|
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
|
||||||
// This is a NULL commit
|
// 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) {
|
static void subsurface_role_destroy(struct wlr_surface *surface) {
|
||||||
struct wlr_subsurface *subsurface =
|
struct wlr_subsurface *subsurface = wlr_subsurface_try_from_wlr_surface(surface);
|
||||||
wlr_subsurface_from_wlr_surface(surface);
|
assert(subsurface != NULL);
|
||||||
|
|
||||||
if (subsurface->has_cache) {
|
if (subsurface->has_cache) {
|
||||||
wlr_surface_unlock_cached(subsurface->surface,
|
wlr_surface_unlock_cached(subsurface->surface,
|
||||||
|
@ -403,13 +398,10 @@ static struct wlr_subsurface *subsurface_create(struct wlr_surface *surface,
|
||||||
return subsurface;
|
return subsurface;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
|
struct wlr_subsurface *wlr_subsurface_try_from_wlr_surface(struct wlr_surface *surface) {
|
||||||
return surface->role == &subsurface_role;
|
if (surface->role != &subsurface_role) {
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
|
|
||||||
struct wlr_surface *surface) {
|
|
||||||
assert(wlr_surface_is_subsurface(surface));
|
|
||||||
return (struct wlr_subsurface *)surface->role_data;
|
return (struct wlr_subsurface *)surface->role_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,8 +427,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wlr_surface_is_subsurface(surface) &&
|
if (wlr_subsurface_try_from_wlr_surface(surface) != NULL) {
|
||||||
wlr_subsurface_from_wlr_surface(surface) != NULL) {
|
|
||||||
wl_resource_post_error(resource,
|
wl_resource_post_error(resource,
|
||||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",
|
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",
|
||||||
|
|
Loading…
Reference in a new issue