mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-05 05:05:57 +01:00
subcompositor protocol errors
This commit is contained in:
parent
93f79378f7
commit
19e30aab9b
3 changed files with 41 additions and 4 deletions
|
@ -114,4 +114,9 @@ int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
|
||||||
void wlr_surface_make_subsurface(struct wlr_surface *surface,
|
void wlr_surface_make_subsurface(struct wlr_surface *surface,
|
||||||
struct wlr_surface *parent, uint32_t id);
|
struct wlr_surface *parent, uint32_t id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the top of the subsurface tree for this surface.
|
||||||
|
*/
|
||||||
|
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -84,10 +84,31 @@ static void subcompositor_get_subsurface(struct wl_client *client,
|
||||||
struct wlr_surface *surface = wl_resource_get_user_data(surface_resource);
|
struct wlr_surface *surface = wl_resource_get_user_data(surface_resource);
|
||||||
struct wlr_surface *parent = wl_resource_get_user_data(parent_resource);
|
struct wlr_surface *parent = wl_resource_get_user_data(parent_resource);
|
||||||
|
|
||||||
// TODO: errors
|
static const char msg[] = "get_subsurface: wl_subsurface@";
|
||||||
// * cannot be its own parent
|
|
||||||
// * cannot already a subsurface
|
if (surface == parent) {
|
||||||
// * cannot be an ancestor of parent
|
wl_resource_post_error(resource,
|
||||||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||||
|
"%s%d: wl_surface@%d cannot be its own parent",
|
||||||
|
msg, id, wl_resource_get_id(surface_resource));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (surface->subsurface) {
|
||||||
|
wl_resource_post_error(resource,
|
||||||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||||
|
"%s%d: wl_surface@%d is already a sub-surface",
|
||||||
|
msg, id, wl_resource_get_id(surface_resource));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wlr_surface_get_main_surface(parent) == surface) {
|
||||||
|
wl_resource_post_error(resource,
|
||||||
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||||
|
"%s%d: wl_surface@%d is an ancestor of parent",
|
||||||
|
msg, id, wl_resource_get_id(surface_resource));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (wlr_surface_set_role(surface, "wl_subsurface", resource,
|
if (wlr_surface_set_role(surface, "wl_subsurface", resource,
|
||||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) {
|
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) {
|
||||||
|
|
|
@ -769,3 +769,14 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
|
||||||
|
|
||||||
surface->subsurface = subsurface;
|
surface->subsurface = subsurface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface) {
|
||||||
|
struct wlr_subsurface *sub;
|
||||||
|
|
||||||
|
while (surface && (sub = surface->subsurface)) {
|
||||||
|
surface = sub->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue