From 748d2f656ee4952090eb4ce8702ee05c82d228cb Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 26 Oct 2025 12:34:23 +0000 Subject: [PATCH] xdg-shell: implement invalid parent errors --- src/protocols/XDGShell.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 resource_, SPm_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, WP)> exploreChildren = [](WP tl, + WP 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);