summaryrefslogtreecommitdiff
path: root/src/protocols/XDGShell.cpp
diff options
context:
space:
mode:
authorChris Naporlee <55722668+chrisn731@users.noreply.github.com>2026-03-23 19:08:58 -0400
committerGitHub <noreply@github.com>2026-03-23 23:08:58 +0000
commit63c56bad6fcc55f99d1437da7cd1b0b68fd9cc88 (patch)
treed319540e63de20229ca321ecd1aadc164bfdf501 /src/protocols/XDGShell.cpp
parent64a2e4e26388f017fd9198a6d70424f1f251a5a0 (diff)
protocols: reimplement unstable/xdg-foreign-v2 (#13716)
Diffstat (limited to 'src/protocols/XDGShell.cpp')
-rw-r--r--src/protocols/XDGShell.cpp69
1 files changed, 33 insertions, 36 deletions
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<CXdgToplevel> resource_, SP<CXDGSu
});
m_resource->setSetParent([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<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);
+void CXDGToplevelResource::setNewParent(SP<CXDGToplevelResource> 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<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;
- 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() {