3
0
mirror of https://github.com/hyprwm/Hyprland.git synced 2025-10-29 11:22:47 +00:00

xdg-shell: implement invalid parent errors

This commit is contained in:
Vaxry 2025-10-26 12:34:23 +00:00
parent 6ea4769b39
commit 748d2f656e
No known key found for this signature in database
GPG Key ID: 665806380871D640

View File

@ -223,7 +223,36 @@ CXDGToplevelResource::CXDGToplevelResource(SP<CXdgToplevel> resource_, SP<CXDGSu
std::erase(m_parent->m_children, m_self);
auto newp = parentR ? CXDGToplevelResource::fromResource(parentR) : nullptr;
m_parent = newp;
if (newp) {
// check for protocol constraints
if (newp == m_self) {
r->error(XDG_TOPLEVEL_ERROR_INVALID_PARENT, "Parent cannot be self");
return;
}
static std::function<bool(WP<CXDGToplevelResource>, WP<CXDGToplevelResource>)> exploreChildren = [](WP<CXDGToplevelResource> tl,
WP<CXDGToplevelResource> target) -> bool {
bool any = false;
for (const auto& c : tl->m_children) {
if (c == target)
return true;
any = any || exploreChildren(c, target);
if (any)
break;
}
return any;
};
if (exploreChildren(m_self, newp)) {
r->error(XDG_TOPLEVEL_ERROR_INVALID_PARENT, "Parent cannot be a descendant");
return;
}
}
m_parent = newp;
if (m_parent)
m_parent->m_children.emplace_back(m_self);