summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-02-01 15:08:30 +0000
committerVaxry <vaxry@vaxry.net>2025-02-01 15:08:30 +0000
commitc6f672257bd2ae98f4fd7a6a273b2d1d3e944baa (patch)
tree3b331626749173588719ac4303dd347af0820e5e /src
parent5b43c106bd1cde9ac0b5626130890cde4de0b245 (diff)
desktop: move popup and subsurface ctors to factories
makes sure m_pSelf is set before we do anything like possibly adding children fixes #9275 supersedes #9276
Diffstat (limited to 'src')
-rw-r--r--src/desktop/LayerSurface.cpp7
-rw-r--r--src/desktop/LayerSurface.hpp2
-rw-r--r--src/desktop/Popup.cpp45
-rw-r--r--src/desktop/Popup.hpp8
-rw-r--r--src/desktop/Subsurface.cpp65
-rw-r--r--src/desktop/Subsurface.hpp10
-rw-r--r--src/desktop/Window.cpp6
-rw-r--r--src/desktop/Window.hpp2
8 files changed, 88 insertions, 57 deletions
diff --git a/src/desktop/LayerSurface.cpp b/src/desktop/LayerSurface.cpp
index 78dae0a9..f4ffaedf 100644
--- a/src/desktop/LayerSurface.cpp
+++ b/src/desktop/LayerSurface.cpp
@@ -31,10 +31,9 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
pLS->szNamespace = resource->layerNamespace;
- pLS->layer = resource->current.layer;
- pLS->popupHead = makeUnique<CPopup>(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 ab259733..f2be7459 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<CPopup> popupHead;
+ SP<CPopup> popupHead;
void onDestroy();
void onMap();
diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp
index dea94f55..20ff49d7 100644
--- a/src/desktop/Popup.cpp
+++ b/src/desktop/Popup.cpp
@@ -12,23 +12,37 @@
#include "../render/OpenGL.hpp"
#include <ranges>
-CPopup::CPopup(PHLWINDOW pOwner) : m_pWindowOwner(pOwner) {
- initAllSignals();
+SP<CPopup> CPopup::create(PHLWINDOW pOwner) {
+ auto popup = SP<CPopup>(new CPopup());
+ popup->m_pWindowOwner = pOwner;
+ popup->m_pSelf = popup;
+ popup->initAllSignals();
+ return popup;
}
-CPopup::CPopup(PHLLS pOwner) : m_pLayerOwner(pOwner) {
- initAllSignals();
+SP<CPopup> CPopup::create(PHLLS pOwner) {
+ auto popup = SP<CPopup>(new CPopup());
+ popup->m_pLayerOwner = pOwner;
+ popup->m_pSelf = popup;
+ popup->initAllSignals();
+ return popup;
}
-CPopup::CPopup(SP<CXDGPopupResource> popup, WP<CPopup> 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> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) {
+ auto popup = SP<CPopup>(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<CXDGPopupResource> popup) {
- const auto& POPUP = m_vChildren.emplace_back(makeShared<CPopup>(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<CSubsurface>(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 6051f7eb..a64af7eb 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<CPopup> create(PHLWINDOW pOwner);
+ static SP<CPopup> create(PHLLS pOwner);
// real nodes
- CPopup(SP<CXDGPopupResource> popup, WP<CPopup> pOwner);
+ static SP<CPopup> create(SP<CXDGPopupResource> popup, WP<CPopup> 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 1d938f39..33ee3553 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<CPopup> pOwner) : m_pPopupParent(pOwner) {
- initSignals();
- initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
-}
-
-CSubsurface::CSubsurface(SP<CWLSubsurfaceResource> 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<CWLSubsurfaceResource> pSubsurface, WP<CPopup> 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> CSubsurface::create(PHLWINDOW pOwner) {
+ auto subsurface = UP<CSubsurface>(new CSubsurface());
+ subsurface->m_pWindowParent = pOwner;
+ subsurface->m_pSelf = subsurface;
+
+ subsurface->initSignals();
+ subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
+ return subsurface;
+}
+
+UP<CSubsurface> CSubsurface::create(WP<CPopup> pOwner) {
+ auto subsurface = UP<CSubsurface>(new CSubsurface());
+ subsurface->m_pPopupParent = pOwner;
+ subsurface->m_pSelf = subsurface;
+ subsurface->initSignals();
+ subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
+ return subsurface;
+}
+
+UP<CSubsurface> CSubsurface::create(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner) {
+ auto subsurface = UP<CSubsurface>(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> CSubsurface::create(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner) {
+ auto subsurface = UP<CSubsurface>(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<CWLSubsurfaceResource> pSubsurface) {
WP<CSubsurface> PSUBSURFACE;
if (!m_pWindowParent.expired())
- PSUBSURFACE = m_vChildren.emplace_back(makeUnique<CSubsurface>(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<CSubsurface>(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 41958671..2983c7c1 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<CPopup> pOwner);
+ static UP<CSubsurface> create(PHLWINDOW pOwner);
+ static UP<CSubsurface> create(WP<CPopup> pOwner);
// real nodes
- CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner);
- CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner);
+ static UP<CSubsurface> create(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner);
+ static UP<CSubsurface> create(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner);
~CSubsurface() = default;
@@ -37,6 +37,8 @@ class CSubsurface {
WP<CSubsurface> m_pSelf;
private:
+ CSubsurface() = default;
+
struct {
CHyprSignalListener destroySubsurface;
CHyprSignalListener commitSubsurface;
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index 0f6bac99..6e580e49 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<CSubsurface>(m_pSelf.lock());
- m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead;
- m_pPopupHead = makeUnique<CPopup>(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<CBaseAnimatedVariable> pav) {
diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp
index ce2f8eb2..3573d7ab 100644
--- a/src/desktop/Window.hpp
+++ b/src/desktop/Window.hpp
@@ -298,7 +298,7 @@ class CWindow {
// desktop components
UP<CSubsurface> m_pSubsurfaceHead;
- UP<CPopup> m_pPopupHead;
+ SP<CPopup> m_pPopupHead;
// Animated border
CGradientValueData m_cRealBorderColor = {0};