diff --git a/src/desktop/LayerSurface.cpp b/src/desktop/LayerSurface.cpp index 78dae0a91c0..f4ffaedfc9c 100644 --- a/src/desktop/LayerSurface.cpp +++ b/src/desktop/LayerSurface.cpp @@ -31,10 +31,9 @@ PHLLS CLayerSurface::create(SP resource) { pLS->szNamespace = resource->layerNamespace; - pLS->layer = resource->current.layer; - pLS->popupHead = makeUnique(pLS); - pLS->popupHead->m_pSelf = pLS->popupHead; - pLS->monitor = pMonitor; + pLS->layer = resource->current.layer; + pLS->popupHead = CPopup::create(pLS); + pLS->monitor = pMonitor; pMonitor->m_aLayerSurfaceLayers[resource->current.layer].emplace_back(pLS); pLS->forceBlur = g_pConfigManager->shouldBlurLS(pLS->szNamespace); diff --git a/src/desktop/LayerSurface.hpp b/src/desktop/LayerSurface.hpp index ab259733f3c..f2be7459971 100644 --- a/src/desktop/LayerSurface.hpp +++ b/src/desktop/LayerSurface.hpp @@ -59,7 +59,7 @@ class CLayerSurface { CBox geometry = {0, 0, 0, 0}; Vector2D position; std::string szNamespace = ""; - UP popupHead; + SP popupHead; void onDestroy(); void onMap(); diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index dea94f556eb..20ff49d7951 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -12,23 +12,37 @@ #include "../render/OpenGL.hpp" #include -CPopup::CPopup(PHLWINDOW pOwner) : m_pWindowOwner(pOwner) { - initAllSignals(); +SP CPopup::create(PHLWINDOW pOwner) { + auto popup = SP(new CPopup()); + popup->m_pWindowOwner = pOwner; + popup->m_pSelf = popup; + popup->initAllSignals(); + return popup; } -CPopup::CPopup(PHLLS pOwner) : m_pLayerOwner(pOwner) { - initAllSignals(); +SP CPopup::create(PHLLS pOwner) { + auto popup = SP(new CPopup()); + popup->m_pLayerOwner = pOwner; + popup->m_pSelf = popup; + popup->initAllSignals(); + return 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); - - m_vLastSize = popup->surface->current.geometry.size(); - reposition(); - - initAllSignals(); +SP CPopup::create(SP resource, WP pOwner) { + auto popup = SP(new CPopup()); + popup->m_pResource = resource; + popup->m_pWindowOwner = pOwner->m_pWindowOwner; + popup->m_pLayerOwner = pOwner->m_pLayerOwner; + popup->m_pParent = pOwner; + popup->m_pSelf = popup; + popup->m_pWLSurface = CWLSurface::create(); + popup->m_pWLSurface->assign(resource->surface->surface.lock(), popup.get()); + + popup->m_vLastSize = resource->surface->current.geometry.size(); + popup->reposition(); + + popup->initAllSignals(); + return popup; } CPopup::~CPopup() { @@ -59,7 +73,7 @@ void CPopup::initAllSignals() { } void CPopup::onNewPopup(SP popup) { - const auto& POPUP = m_vChildren.emplace_back(makeShared(popup, m_pSelf)); + const auto& POPUP = m_vChildren.emplace_back(CPopup::create(popup, m_pSelf)); POPUP->m_pSelf = POPUP; Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP); } @@ -91,8 +105,7 @@ void CPopup::onMap() { g_pInputManager->simulateMouseMovement(); - m_pSubsurfaceHead = makeUnique(m_pSelf); - m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead; + m_pSubsurfaceHead = CSubsurface::create(m_pSelf); //unconstrain(); sendScale(); diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index 6051f7ebc65..a64af7eb563 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -10,11 +10,11 @@ class CXDGPopupResource; class CPopup { public: // dummy head nodes - CPopup(PHLWINDOW pOwner); - CPopup(PHLLS pOwner); + static SP create(PHLWINDOW pOwner); + static SP create(PHLLS pOwner); // real nodes - CPopup(SP popup, WP pOwner); + static SP create(SP popup, WP pOwner); ~CPopup(); @@ -45,6 +45,8 @@ class CPopup { bool m_bMapped = false; private: + CPopup() = default; + // T1 owners, each popup has to have one of these PHLWINDOWREF m_pWindowOwner; PHLLSREF m_pLayerOwner; diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index 1d938f39c7b..33ee3553cde 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -7,28 +7,45 @@ #include "../render/Renderer.hpp" #include "../managers/input/InputManager.hpp" -CSubsurface::CSubsurface(PHLWINDOW pOwner) : m_pWindowParent(pOwner) { - initSignals(); - initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); -} - -CSubsurface::CSubsurface(WP pOwner) : m_pPopupParent(pOwner) { - initSignals(); - initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); -} - -CSubsurface::CSubsurface(SP pSubsurface, PHLWINDOW pOwner) : m_pSubsurface(pSubsurface), m_pWindowParent(pOwner) { - m_pWLSurface = CWLSurface::create(); - m_pWLSurface->assign(pSubsurface->surface.lock(), this); - initSignals(); - initExistingSubsurfaces(pSubsurface->surface.lock()); -} - -CSubsurface::CSubsurface(SP pSubsurface, WP pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) { - m_pWLSurface = CWLSurface::create(); - m_pWLSurface->assign(pSubsurface->surface.lock(), this); - initSignals(); - initExistingSubsurfaces(pSubsurface->surface.lock()); +UP CSubsurface::create(PHLWINDOW pOwner) { + auto subsurface = UP(new CSubsurface()); + subsurface->m_pWindowParent = pOwner; + subsurface->m_pSelf = subsurface; + + subsurface->initSignals(); + subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); + return subsurface; +} + +UP CSubsurface::create(WP pOwner) { + auto subsurface = UP(new CSubsurface()); + subsurface->m_pPopupParent = pOwner; + subsurface->m_pSelf = subsurface; + subsurface->initSignals(); + subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); + return subsurface; +} + +UP CSubsurface::create(SP pSubsurface, PHLWINDOW pOwner) { + auto subsurface = UP(new CSubsurface()); + subsurface->m_pWindowParent = pOwner; + subsurface->m_pSelf = subsurface; + subsurface->m_pWLSurface = CWLSurface::create(); + subsurface->m_pWLSurface->assign(pSubsurface->surface.lock(), subsurface.get()); + subsurface->initSignals(); + subsurface->initExistingSubsurfaces(pSubsurface->surface.lock()); + return subsurface; +} + +UP CSubsurface::create(SP pSubsurface, WP pOwner) { + auto subsurface = UP(new CSubsurface()); + subsurface->m_pPopupParent = pOwner; + subsurface->m_pSelf = subsurface; + subsurface->m_pWLSurface = CWLSurface::create(); + subsurface->m_pWLSurface->assign(pSubsurface->surface.lock(), subsurface.get()); + subsurface->initSignals(); + subsurface->initExistingSubsurfaces(pSubsurface->surface.lock()); + return subsurface; } void CSubsurface::initSignals() { @@ -131,9 +148,9 @@ void CSubsurface::onNewSubsurface(SP pSubsurface) { WP PSUBSURFACE; if (!m_pWindowParent.expired()) - PSUBSURFACE = m_vChildren.emplace_back(makeUnique(pSubsurface, m_pWindowParent.lock())); + PSUBSURFACE = m_vChildren.emplace_back(CSubsurface::create(pSubsurface, m_pWindowParent.lock())); else if (m_pPopupParent) - PSUBSURFACE = m_vChildren.emplace_back(makeUnique(pSubsurface, m_pPopupParent)); + PSUBSURFACE = m_vChildren.emplace_back(CSubsurface::create(pSubsurface, m_pPopupParent)); PSUBSURFACE->m_pSelf = PSUBSURFACE; diff --git a/src/desktop/Subsurface.hpp b/src/desktop/Subsurface.hpp index 41958671f06..2983c7c1758 100644 --- a/src/desktop/Subsurface.hpp +++ b/src/desktop/Subsurface.hpp @@ -10,12 +10,12 @@ class CWLSubsurfaceResource; class CSubsurface { public: // root dummy nodes - CSubsurface(PHLWINDOW pOwner); - CSubsurface(WP pOwner); + static UP create(PHLWINDOW pOwner); + static UP create(WP pOwner); // real nodes - CSubsurface(SP pSubsurface, PHLWINDOW pOwner); - CSubsurface(SP pSubsurface, WP pOwner); + static UP create(SP pSubsurface, PHLWINDOW pOwner); + static UP create(SP pSubsurface, WP pOwner); ~CSubsurface() = default; @@ -37,6 +37,8 @@ class CSubsurface { WP m_pSelf; private: + CSubsurface() = default; + struct { CHyprSignalListener destroySubsurface; CHyprSignalListener commitSubsurface; diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 0f6bac99f5a..6e580e49daf 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -571,10 +571,8 @@ void CWindow::onMap() { if (m_bIsX11) return; - m_pSubsurfaceHead = makeUnique(m_pSelf.lock()); - m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead; - m_pPopupHead = makeUnique(m_pSelf.lock()); - m_pPopupHead->m_pSelf = m_pPopupHead; + m_pSubsurfaceHead = CSubsurface::create(m_pSelf.lock()); + m_pPopupHead = CPopup::create(m_pSelf.lock()); } void CWindow::onBorderAngleAnimEnd(WP pav) { diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index ce2f8eb2596..3573d7ab439 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -298,7 +298,7 @@ class CWindow { // desktop components UP m_pSubsurfaceHead; - UP m_pPopupHead; + SP m_pPopupHead; // Animated border CGradientValueData m_cRealBorderColor = {0};