diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3f9126b7..43efdac1 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -571,7 +571,6 @@ void CCompositor::cleanup() { g_pLayoutManager.reset(); g_pHyprError.reset(); g_pConfigManager.reset(); - g_pAnimationManager.reset(); g_pKeybindManager.reset(); g_pHookSystem.reset(); g_pWatchdog.reset(); diff --git a/src/desktop/LayerSurface.cpp b/src/desktop/LayerSurface.cpp index dd30aa7c..c2b07c5d 100644 --- a/src/desktop/LayerSurface.cpp +++ b/src/desktop/LayerSurface.cpp @@ -31,9 +31,10 @@ PHLLS CLayerSurface::create(SP resource) { pLS->szNamespace = resource->layerNamespace; - pLS->layer = resource->current.layer; - pLS->popupHead = makeUnique(pLS); - pLS->monitor = pMonitor; + pLS->layer = resource->current.layer; + pLS->popupHead = makeUnique(pLS); + pLS->popupHead->m_pSelf = pLS->popupHead; + pLS->monitor = pMonitor; pMonitor->m_aLayerSurfaceLayers[resource->current.layer].emplace_back(pLS); pLS->forceBlur = g_pConfigManager->shouldBlurLS(pLS->szNamespace); @@ -331,7 +332,7 @@ void CLayerSurface::onCommit() { nullptr); if (!WASLASTFOCUS && popupHead) { popupHead->breadthfirst( - [&WASLASTFOCUS](CPopup* popup, void* data) { + [&WASLASTFOCUS](WP popup, void* data) { WASLASTFOCUS = WASLASTFOCUS || (popup->m_pWLSurface && g_pSeatManager->state.keyboardFocus == popup->m_pWLSurface->resource()); }, nullptr); @@ -576,7 +577,7 @@ int CLayerSurface::popupsCount() { return 0; int no = -1; // we have one dummy - popupHead->breadthfirst([](CPopup* p, void* data) { *(int*)data += 1; }, &no); + popupHead->breadthfirst([](WP p, void* data) { *(int*)data += 1; }, &no); return no; } 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 {}; } diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index 2b7b4e82..6051f7eb 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -14,7 +14,7 @@ class CPopup { CPopup(PHLLS pOwner); // real nodes - CPopup(SP popup, CPopup* pOwner); + CPopup(SP popup, WP pOwner); ~CPopup(); @@ -36,11 +36,12 @@ class CPopup { bool visible(); // will also loop over this node - void breadthfirst(std::function fn, void* data); - CPopup* at(const Vector2D& globalCoords, bool allowsInput = false); + void breadthfirst(std::function, void*)> fn, void* data); + WP at(const Vector2D& globalCoords, bool allowsInput = false); // SP m_pWLSurface; + WP m_pSelf; bool m_bMapped = false; private: @@ -49,7 +50,7 @@ class CPopup { PHLLSREF m_pLayerOwner; // T2 owners - CPopup* m_pParent = nullptr; + WP m_pParent; WP m_pResource; @@ -81,5 +82,5 @@ class CPopup { Vector2D localToGlobal(const Vector2D& rel); Vector2D t1ParentCoords(); - static void bfHelper(std::vector const& nodes, std::function fn, void* data); + static void bfHelper(std::vector> const& nodes, std::function, void*)> fn, void* data); }; diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index eb18ee39..5657cb39 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -12,7 +12,7 @@ CSubsurface::CSubsurface(PHLWINDOW pOwner) : m_pWindowParent(pOwner) { initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); } -CSubsurface::CSubsurface(CPopup* pOwner) : m_pPopupParent(pOwner) { +CSubsurface::CSubsurface(WP pOwner) : m_pPopupParent(pOwner) { initSignals(); initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); } @@ -24,7 +24,7 @@ CSubsurface::CSubsurface(SP pSubsurface, PHLWINDOW pOwner initExistingSubsurfaces(pSubsurface->surface.lock()); } -CSubsurface::CSubsurface(SP pSubsurface, CPopup* pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) { +CSubsurface::CSubsurface(SP pSubsurface, WP pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) { m_pWLSurface = CWLSurface::create(); m_pWLSurface->assign(pSubsurface->surface.lock(), this); initSignals(); @@ -132,16 +132,18 @@ void CSubsurface::onDestroy() { } void CSubsurface::onNewSubsurface(SP pSubsurface) { - CSubsurface* PSUBSURFACE = nullptr; + WP PSUBSURFACE; if (!m_pWindowParent.expired()) - PSUBSURFACE = m_vChildren.emplace_back(makeUnique(pSubsurface, m_pWindowParent.lock())).get(); + PSUBSURFACE = m_vChildren.emplace_back(makeUnique(pSubsurface, m_pWindowParent.lock())); else if (m_pPopupParent) - PSUBSURFACE = m_vChildren.emplace_back(makeUnique(pSubsurface, m_pPopupParent)).get(); + PSUBSURFACE = m_vChildren.emplace_back(makeUnique(pSubsurface, m_pPopupParent)); + + PSUBSURFACE->m_pSelf = PSUBSURFACE; ASSERT(PSUBSURFACE); - PSUBSURFACE->m_pParent = this; + PSUBSURFACE->m_pParent = PSUBSURFACE; } void CSubsurface::onMap() { diff --git a/src/desktop/Subsurface.hpp b/src/desktop/Subsurface.hpp index aacbad91..f16a11ea 100644 --- a/src/desktop/Subsurface.hpp +++ b/src/desktop/Subsurface.hpp @@ -11,28 +11,30 @@ class CSubsurface { public: // root dummy nodes CSubsurface(PHLWINDOW pOwner); - CSubsurface(CPopup* pOwner); + CSubsurface(WP pOwner); // real nodes CSubsurface(SP pSubsurface, PHLWINDOW pOwner); - CSubsurface(SP pSubsurface, CPopup* pOwner); + CSubsurface(SP pSubsurface, WP pOwner); ~CSubsurface(); - Vector2D coordsRelativeToParent(); - Vector2D coordsGlobal(); + Vector2D coordsRelativeToParent(); + Vector2D coordsGlobal(); - Vector2D size(); + Vector2D size(); - void onCommit(); - void onDestroy(); - void onNewSubsurface(SP pSubsurface); - void onMap(); - void onUnmap(); + void onCommit(); + void onDestroy(); + void onNewSubsurface(SP pSubsurface); + void onMap(); + void onUnmap(); - bool visible(); + bool visible(); - void recheckDamageForSubsurfaces(); + void recheckDamageForSubsurfaces(); + + WP m_pSelf; private: struct { @@ -48,10 +50,10 @@ class CSubsurface { Vector2D m_vLastSize = {}; // if nullptr, means it's a dummy node - CSubsurface* m_pParent = nullptr; + WP m_pParent; PHLWINDOWREF m_pWindowParent; - CPopup* m_pPopupParent = nullptr; + WP m_pPopupParent; std::vector> m_vChildren; diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index b1b3c66c..9dcdb385 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -154,7 +154,7 @@ SBoxExtents CWindow::getFullWindowExtents() { CBox surfaceExtents = {0, 0, 0, 0}; // TODO: this could be better, perhaps make a getFullWindowRegion? m_pPopupHead->breadthfirst( - [](CPopup* popup, void* data) { + [](WP popup, void* data) { if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource()) return; @@ -569,8 +569,10 @@ void CWindow::onMap() { if (m_bIsX11) return; - m_pSubsurfaceHead = makeUnique(m_pSelf.lock()); - m_pPopupHead = makeUnique(m_pSelf.lock()); + m_pSubsurfaceHead = makeUnique(m_pSelf.lock()); + m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead; + m_pPopupHead = makeUnique(m_pSelf.lock()); + m_pPopupHead->m_pSelf = m_pPopupHead; } void CWindow::onBorderAngleAnimEnd(WP pav) { @@ -847,7 +849,7 @@ bool CWindow::hasPopupAt(const Vector2D& pos) { if (m_bIsX11) return false; - CPopup* popup = m_pPopupHead->at(pos); + auto popup = m_pPopupHead->at(pos); return popup && popup->m_pWLSurface->resource(); } @@ -1289,7 +1291,7 @@ int CWindow::popupsCount() { return 0; int no = -1; - m_pPopupHead->breadthfirst([](CPopup* p, void* d) { *((int*)d) += 1; }, &no); + m_pPopupHead->breadthfirst([](WP p, void* d) { *((int*)d) += 1; }, &no); return no; } diff --git a/src/main.cpp b/src/main.cpp index d244f10f..464ed978 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -181,6 +181,8 @@ int main(int argc, char** argv) { g_pCompositor->cleanup(); + g_pCompositor.reset(); + Debug::log(LOG, "Hyprland has reached the end."); return EXIT_SUCCESS; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index d82d79d1..f897379a 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -615,7 +615,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe renderdata.surfaceCounter = 0; pWindow->m_pPopupHead->breadthfirst( - [this, &renderdata](CPopup* popup, void* data) { + [this, &renderdata](WP popup, void* data) { if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped) return; const auto pos = popup->coordsRelativeToParent(); @@ -718,7 +718,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* tim renderdata.surfaceCounter = 0; if (popups) { pLayer->popupHead->breadthfirst( - [this, &renderdata](CPopup* popup, void* data) { + [this, &renderdata](WP popup, void* data) { if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped) return;