From 0a28e13787a83a48cbca9641a02b8ea4857c733c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 26 Jan 2025 12:54:32 +0000 Subject: desktop: move desktop types to memory-safe pointers --- src/desktop/Popup.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/desktop/Popup.cpp') diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 831619a5..0c7c72a4 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -20,7 +20,8 @@ CPopup::CPopup(PHLLS pOwner) : m_pLayerOwner(pOwner) { initAllSignals(); } -CPopup::CPopup(SP popup, CPopup* pOwner) : m_pWindowOwner(pOwner->m_pWindowOwner), m_pLayerOwner(pOwner->m_pLayerOwner), m_pParent(pOwner), m_pResource(popup) { +CPopup::CPopup(SP popup, WP pOwner) : + m_pWindowOwner(pOwner->m_pWindowOwner), m_pLayerOwner(pOwner->m_pLayerOwner), m_pParent(pOwner), m_pResource(popup) { m_pWLSurface = CWLSurface::create(); m_pWLSurface->assign(popup->surface->surface.lock(), this); @@ -58,7 +59,8 @@ void CPopup::initAllSignals() { } void CPopup::onNewPopup(SP popup) { - const auto POPUP = m_vChildren.emplace_back(makeShared(popup, this)).get(); + const auto& POPUP = m_vChildren.emplace_back(makeShared(popup, m_pSelf)); + POPUP->m_pSelf = POPUP; Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP); } @@ -89,7 +91,8 @@ void CPopup::onMap() { g_pInputManager->simulateMouseMovement(); - m_pSubsurfaceHead = makeUnique(this); + m_pSubsurfaceHead = makeUnique(m_pSelf); + m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead; //unconstrain(); sendScale(); @@ -126,7 +129,7 @@ void CPopup::onUnmap() { // damage all children breadthfirst( - [](CPopup* p, void* data) { + [](WP p, void* data) { if (!p->m_pResource) return; @@ -223,7 +226,7 @@ Vector2D CPopup::coordsRelativeToParent() { if (!m_pResource) return {}; - CPopup* current = this; + WP current = m_pSelf; offset -= current->m_pResource->surface->current.geometry.pos(); while (current->m_pParent && current->m_pResource) { @@ -256,7 +259,7 @@ Vector2D CPopup::t1ParentCoords() { } void CPopup::recheckTree() { - CPopup* curr = this; + WP curr = m_pSelf; while (curr->m_pParent) { curr = curr->m_pParent; } @@ -296,17 +299,17 @@ bool CPopup::visible() { return false; } -void CPopup::bfHelper(std::vector const& nodes, std::function fn, void* data) { +void CPopup::bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data) { for (auto const& n : nodes) { fn(n, data); } - std::vector nodes2; + std::vector> nodes2; nodes2.reserve(nodes.size() * 2); for (auto const& n : nodes) { for (auto const& c : n->m_vChildren) { - nodes2.push_back(c.get()); + nodes2.push_back(c->m_pSelf); } } @@ -314,15 +317,15 @@ void CPopup::bfHelper(std::vector const& nodes, std::function fn, void* data) { - std::vector popups; - popups.push_back(this); +void CPopup::breadthfirst(std::function, void*)> fn, void* data) { + std::vector> popups; + popups.push_back(m_pSelf); bfHelper(popups, fn, data); } -CPopup* CPopup::at(const Vector2D& globalCoords, bool allowsInput) { - std::vector popups; - breadthfirst([](CPopup* popup, void* data) { ((std::vector*)data)->push_back(popup); }, &popups); +WP CPopup::at(const Vector2D& globalCoords, bool allowsInput) { + std::vector> popups; + breadthfirst([](WP popup, void* data) { ((std::vector>*)data)->push_back(popup); }, &popups); for (auto const& p : popups | std::views::reverse) { if (!p->m_pResource || !p->m_bMapped) @@ -344,5 +347,5 @@ CPopup* CPopup::at(const Vector2D& globalCoords, bool allowsInput) { } } - return nullptr; + return {}; } -- cgit v1.2.3