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
This commit is contained in:
Vaxry
2025-02-01 15:08:30 +00:00
parent 5b43c106bd
commit c6f672257b
8 changed files with 80 additions and 49 deletions

View File

@@ -31,10 +31,9 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
pLS->szNamespace = resource->layerNamespace; pLS->szNamespace = resource->layerNamespace;
pLS->layer = resource->current.layer; pLS->layer = resource->current.layer;
pLS->popupHead = makeUnique<CPopup>(pLS); pLS->popupHead = CPopup::create(pLS);
pLS->popupHead->m_pSelf = pLS->popupHead; pLS->monitor = pMonitor;
pLS->monitor = pMonitor;
pMonitor->m_aLayerSurfaceLayers[resource->current.layer].emplace_back(pLS); pMonitor->m_aLayerSurfaceLayers[resource->current.layer].emplace_back(pLS);
pLS->forceBlur = g_pConfigManager->shouldBlurLS(pLS->szNamespace); pLS->forceBlur = g_pConfigManager->shouldBlurLS(pLS->szNamespace);

View File

@@ -59,7 +59,7 @@ class CLayerSurface {
CBox geometry = {0, 0, 0, 0}; CBox geometry = {0, 0, 0, 0};
Vector2D position; Vector2D position;
std::string szNamespace = ""; std::string szNamespace = "";
UP<CPopup> popupHead; SP<CPopup> popupHead;
void onDestroy(); void onDestroy();
void onMap(); void onMap();

View File

@@ -12,23 +12,37 @@
#include "../render/OpenGL.hpp" #include "../render/OpenGL.hpp"
#include <ranges> #include <ranges>
CPopup::CPopup(PHLWINDOW pOwner) : m_pWindowOwner(pOwner) { SP<CPopup> CPopup::create(PHLWINDOW pOwner) {
initAllSignals(); 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) { SP<CPopup> CPopup::create(PHLLS pOwner) {
initAllSignals(); 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) : SP<CPopup> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) {
m_pWindowOwner(pOwner->m_pWindowOwner), m_pLayerOwner(pOwner->m_pLayerOwner), m_pParent(pOwner), m_pResource(popup) { auto popup = SP<CPopup>(new CPopup());
m_pWLSurface = CWLSurface::create(); popup->m_pResource = resource;
m_pWLSurface->assign(popup->surface->surface.lock(), this); 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());
m_vLastSize = popup->surface->current.geometry.size(); popup->m_vLastSize = resource->surface->current.geometry.size();
reposition(); popup->reposition();
initAllSignals(); popup->initAllSignals();
return popup;
} }
CPopup::~CPopup() { CPopup::~CPopup() {
@@ -59,7 +73,7 @@ void CPopup::initAllSignals() {
} }
void CPopup::onNewPopup(SP<CXDGPopupResource> popup) { 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; POPUP->m_pSelf = POPUP;
Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP); Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP);
} }
@@ -91,8 +105,7 @@ void CPopup::onMap() {
g_pInputManager->simulateMouseMovement(); g_pInputManager->simulateMouseMovement();
m_pSubsurfaceHead = makeUnique<CSubsurface>(m_pSelf); m_pSubsurfaceHead = CSubsurface::create(m_pSelf);
m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead;
//unconstrain(); //unconstrain();
sendScale(); sendScale();

View File

@@ -10,11 +10,11 @@ class CXDGPopupResource;
class CPopup { class CPopup {
public: public:
// dummy head nodes // dummy head nodes
CPopup(PHLWINDOW pOwner); static SP<CPopup> create(PHLWINDOW pOwner);
CPopup(PHLLS pOwner); static SP<CPopup> create(PHLLS pOwner);
// real nodes // real nodes
CPopup(SP<CXDGPopupResource> popup, WP<CPopup> pOwner); static SP<CPopup> create(SP<CXDGPopupResource> popup, WP<CPopup> pOwner);
~CPopup(); ~CPopup();
@@ -45,6 +45,8 @@ class CPopup {
bool m_bMapped = false; bool m_bMapped = false;
private: private:
CPopup() = default;
// T1 owners, each popup has to have one of these // T1 owners, each popup has to have one of these
PHLWINDOWREF m_pWindowOwner; PHLWINDOWREF m_pWindowOwner;
PHLLSREF m_pLayerOwner; PHLLSREF m_pLayerOwner;

View File

@@ -7,28 +7,45 @@
#include "../render/Renderer.hpp" #include "../render/Renderer.hpp"
#include "../managers/input/InputManager.hpp" #include "../managers/input/InputManager.hpp"
CSubsurface::CSubsurface(PHLWINDOW pOwner) : m_pWindowParent(pOwner) { UP<CSubsurface> CSubsurface::create(PHLWINDOW pOwner) {
initSignals(); auto subsurface = UP<CSubsurface>(new CSubsurface());
initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); subsurface->m_pWindowParent = pOwner;
subsurface->m_pSelf = subsurface;
subsurface->initSignals();
subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
return subsurface;
} }
CSubsurface::CSubsurface(WP<CPopup> pOwner) : m_pPopupParent(pOwner) { UP<CSubsurface> CSubsurface::create(WP<CPopup> pOwner) {
initSignals(); auto subsurface = UP<CSubsurface>(new CSubsurface());
initExistingSubsurfaces(pOwner->m_pWLSurface->resource()); subsurface->m_pPopupParent = pOwner;
subsurface->m_pSelf = subsurface;
subsurface->initSignals();
subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
return subsurface;
} }
CSubsurface::CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner) : m_pSubsurface(pSubsurface), m_pWindowParent(pOwner) { UP<CSubsurface> CSubsurface::create(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner) {
m_pWLSurface = CWLSurface::create(); auto subsurface = UP<CSubsurface>(new CSubsurface());
m_pWLSurface->assign(pSubsurface->surface.lock(), this); subsurface->m_pWindowParent = pOwner;
initSignals(); subsurface->m_pSelf = subsurface;
initExistingSubsurfaces(pSubsurface->surface.lock()); subsurface->m_pWLSurface = CWLSurface::create();
subsurface->m_pWLSurface->assign(pSubsurface->surface.lock(), subsurface.get());
subsurface->initSignals();
subsurface->initExistingSubsurfaces(pSubsurface->surface.lock());
return subsurface;
} }
CSubsurface::CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) { UP<CSubsurface> CSubsurface::create(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner) {
m_pWLSurface = CWLSurface::create(); auto subsurface = UP<CSubsurface>(new CSubsurface());
m_pWLSurface->assign(pSubsurface->surface.lock(), this); subsurface->m_pPopupParent = pOwner;
initSignals(); subsurface->m_pSelf = subsurface;
initExistingSubsurfaces(pSubsurface->surface.lock()); 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() { void CSubsurface::initSignals() {
@@ -131,9 +148,9 @@ void CSubsurface::onNewSubsurface(SP<CWLSubsurfaceResource> pSubsurface) {
WP<CSubsurface> PSUBSURFACE; WP<CSubsurface> PSUBSURFACE;
if (!m_pWindowParent.expired()) 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) 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; PSUBSURFACE->m_pSelf = PSUBSURFACE;

View File

@@ -10,12 +10,12 @@ class CWLSubsurfaceResource;
class CSubsurface { class CSubsurface {
public: public:
// root dummy nodes // root dummy nodes
CSubsurface(PHLWINDOW pOwner); static UP<CSubsurface> create(PHLWINDOW pOwner);
CSubsurface(WP<CPopup> pOwner); static UP<CSubsurface> create(WP<CPopup> pOwner);
// real nodes // real nodes
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner); static UP<CSubsurface> create(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner);
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner); static UP<CSubsurface> create(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner);
~CSubsurface() = default; ~CSubsurface() = default;
@@ -37,6 +37,8 @@ class CSubsurface {
WP<CSubsurface> m_pSelf; WP<CSubsurface> m_pSelf;
private: private:
CSubsurface() = default;
struct { struct {
CHyprSignalListener destroySubsurface; CHyprSignalListener destroySubsurface;
CHyprSignalListener commitSubsurface; CHyprSignalListener commitSubsurface;

View File

@@ -571,10 +571,8 @@ void CWindow::onMap() {
if (m_bIsX11) if (m_bIsX11)
return; return;
m_pSubsurfaceHead = makeUnique<CSubsurface>(m_pSelf.lock()); m_pSubsurfaceHead = CSubsurface::create(m_pSelf.lock());
m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead; m_pPopupHead = CPopup::create(m_pSelf.lock());
m_pPopupHead = makeUnique<CPopup>(m_pSelf.lock());
m_pPopupHead->m_pSelf = m_pPopupHead;
} }
void CWindow::onBorderAngleAnimEnd(WP<CBaseAnimatedVariable> pav) { void CWindow::onBorderAngleAnimEnd(WP<CBaseAnimatedVariable> pav) {

View File

@@ -298,7 +298,7 @@ class CWindow {
// desktop components // desktop components
UP<CSubsurface> m_pSubsurfaceHead; UP<CSubsurface> m_pSubsurfaceHead;
UP<CPopup> m_pPopupHead; SP<CPopup> m_pPopupHead;
// Animated border // Animated border
CGradientValueData m_cRealBorderColor = {0}; CGradientValueData m_cRealBorderColor = {0};