summaryrefslogtreecommitdiff
path: root/src/protocols/XDGShell.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-10-26 12:34:23 +0000
committerVaxry <vaxry@vaxry.net>2025-10-26 12:34:35 +0000
commit748d2f656ee4952090eb4ce8702ee05c82d228cb (patch)
tree3efa3b7f2bbf6abce57d4327d6aeb4c474a2d349 /src/protocols/XDGShell.cpp
parent6ea4769b39fccec22ae2acd015511a745d378840 (diff)
xdg-shell: implement invalid parent errors
Diffstat (limited to 'src/protocols/XDGShell.cpp')
-rw-r--r--src/protocols/XDGShell.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp
index 55945cb9..58f297b9 100644
--- a/src/protocols/XDGShell.cpp
+++ b/src/protocols/XDGShell.cpp
@@ -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);