Skip to content

Commit

Permalink
desktop: move popup and subsurface ctors to factories
Browse files Browse the repository at this point in the history
makes sure m_pSelf is set before we do anything like possibly adding children

fixes #9275

supersedes #9276
  • Loading branch information
vaxerski committed Feb 1, 2025
1 parent 5b43c10 commit c6f6722
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 57 deletions.
7 changes: 3 additions & 4 deletions src/desktop/LayerSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/LayerSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
45 changes: 29 additions & 16 deletions src/desktop/Popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions src/desktop/Popup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
65 changes: 41 additions & 24 deletions src/desktop/Subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 6 additions & 4 deletions src/desktop/Subsurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,6 +37,8 @@ class CSubsurface {
WP<CSubsurface> m_pSelf;

private:
CSubsurface() = default;

struct {
CHyprSignalListener destroySubsurface;
CHyprSignalListener commitSubsurface;
Expand Down
6 changes: 2 additions & 4 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

29 comments on commit c6f6722

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip onDestroy()

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit make hyprland laggy </3

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit make hyprland laggy </3

make an issue

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes hyprland is also lagging for me as well

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice commit.......

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my browser is shitting itself

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this commit also causes a memory leak

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebuild to 5b43c10 i gotta wait for compile to finish uwu

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i already did allat

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm 4 steps ahead bro

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice fix..

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post the issue stepbro

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ayo thats kindaa ..... you're making me blush....

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont call me that >.<

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UwU

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👉 👈 🥺

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm guessing the 3 latest commits were untwested...

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OwO i just said untwested. that sounded kinda cute..

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this even fix #9275 ?? lol let me see

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ig it did

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,< this woulda never happened if we used your PR

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ik bro... i got that pr pasted on my profile for a month now, very embarrassing

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless i get another pr to above 9 comments i think

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now i'm stuck in the tty stepbro, i rebuilt from git head omfg

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop flirting with me... 😭

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flirts with contributor

gets asked to leave hyprland issue tracker

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared ptrs strike again..

@nnyyxxxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

64fefa3 fixed the issue

@gksudolol
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more breaking my WeakPtr </3

Please sign in to comment.