From 63c56bad6fcc55f99d1437da7cd1b0b68fd9cc88 Mon Sep 17 00:00:00 2001 From: Chris Naporlee <55722668+chrisn731@users.noreply.github.com> Date: Mon, 23 Mar 2026 19:08:58 -0400 Subject: protocols: reimplement unstable/xdg-foreign-v2 (#13716) --- src/protocols/XDGShell.cpp | 69 ++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'src/protocols/XDGShell.cpp') diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 969556a3..774346d4 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -220,52 +220,49 @@ CXDGToplevelResource::CXDGToplevelResource(SP resource_, SPsetSetParent([this](CXdgToplevel* r, wl_resource* parentR) { - auto oldParent = m_parent; - - if (m_parent) - std::erase(m_parent->m_children, m_self); - auto newp = parentR ? CXDGToplevelResource::fromResource(parentR) : nullptr; + setNewParent(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); +void CXDGToplevelResource::setNewParent(SP newParent) { + auto oldParent = m_parent; - if (any) - break; - } - return any; - }; + if (m_parent) + std::erase(m_parent->m_children, m_self); - if (exploreChildren(m_self, newp)) { - r->error(XDG_TOPLEVEL_ERROR_INVALID_PARENT, "Parent cannot be a descendant"); - return; - } + if (newParent) { + if (m_self == newParent) { + m_resource->error(XDG_TOPLEVEL_ERROR_INVALID_PARENT, "Parent cannot be self"); + return; } - m_parent = newp; + 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; - if (m_parent) { - m_parent->m_children.emplace_back(m_self); + any = any || exploreChildren(c, target); - if (m_parent->m_window && m_parent->m_window->m_pinned) - m_self->m_window->m_pinned = true; + if (any) + break; + } + return any; + }; + if (exploreChildren(m_self, newParent)) { + m_resource->error(XDG_TOPLEVEL_ERROR_INVALID_PARENT, "Parent cannot be a descendant of itself"); + return; } + } - LOGM(Log::DEBUG, "Toplevel {:x} sets parent to {:x}{}", (uintptr_t)this, (uintptr_t)newp.get(), (oldParent ? std::format(" (was {:x})", (uintptr_t)oldParent.get()) : "")); - }); + m_parent = newParent; + if (m_parent) { + m_parent->m_children.emplace_back(m_self); + if (m_parent->m_window && m_parent->m_window->m_pinned) + m_self->m_window->m_pinned = true; + } + LOGM(Log::DEBUG, "Toplevel {:x} sets parent to {:x}{}", (uintptr_t)this, (uintptr_t)newParent.get(), (oldParent ? std::format(" (was {:x})", (uintptr_t)oldParent.get()) : "")); } CXDGToplevelResource::~CXDGToplevelResource() { -- cgit v1.2.3