summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-01-26 12:54:32 +0000
committerVaxry <vaxry@vaxry.net>2025-01-26 12:54:38 +0000
commit0a28e13787a83a48cbca9641a02b8ea4857c733c (patch)
tree3bcb22dd6d477e62748727a246e97c24de524003 /src
parent3cd6e3960f0cbf500786497017ff3084cc9deb17 (diff)
desktop: move desktop types to memory-safe pointers
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp1
-rw-r--r--src/desktop/LayerSurface.cpp11
-rw-r--r--src/desktop/Popup.cpp35
-rw-r--r--src/desktop/Popup.hpp11
-rw-r--r--src/desktop/Subsurface.cpp14
-rw-r--r--src/desktop/Subsurface.hpp30
-rw-r--r--src/desktop/Window.cpp12
-rw-r--r--src/main.cpp2
-rw-r--r--src/render/Renderer.cpp4
9 files changed, 66 insertions, 54 deletions
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<CLayerShellResource> resource) {
pLS->szNamespace = resource->layerNamespace;
- pLS->layer = resource->current.layer;
- pLS->popupHead = makeUnique<CPopup>(pLS);
- pLS->monitor = pMonitor;
+ pLS->layer = resource->current.layer;
+ pLS->popupHead = makeUnique<CPopup>(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<CPopup> 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<CPopup> 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<CXDGPopupResource> popup, CPopup* pOwner) : m_pWindowOwner(pOwner->m_pWindowOwner), m_pLayerOwner(pOwner->m_pLayerOwner), m_pParent(pOwner), m_pResource(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);
@@ -58,7 +59,8 @@ void CPopup::initAllSignals() {
}
void CPopup::onNewPopup(SP<CXDGPopupResource> popup) {
- const auto POPUP = m_vChildren.emplace_back(makeShared<CPopup>(popup, this)).get();
+ const auto& POPUP = m_vChildren.emplace_back(makeShared<CPopup>(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<CSubsurface>(this);
+ m_pSubsurfaceHead = makeUnique<CSubsurface>(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<CPopup> p, void* data) {
if (!p->m_pResource)
return;
@@ -223,7 +226,7 @@ Vector2D CPopup::coordsRelativeToParent() {
if (!m_pResource)
return {};
- CPopup* current = this;
+ WP<CPopup> 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<CPopup> 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<CPopup*> const& nodes, std::function<void(CPopup*, void*)> fn, void* data) {
+void CPopup::bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(WP<CPopup>, void*)> fn, void* data) {
for (auto const& n : nodes) {
fn(n, data);
}
- std::vector<CPopup*> nodes2;
+ std::vector<WP<CPopup>> 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<CPopup*> const& nodes, std::function<void(CPop
bfHelper(nodes2, fn, data);
}
-void CPopup::breadthfirst(std::function<void(CPopup*, void*)> fn, void* data) {
- std::vector<CPopup*> popups;
- popups.push_back(this);
+void CPopup::breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data) {
+ std::vector<WP<CPopup>> popups;
+ popups.push_back(m_pSelf);
bfHelper(popups, fn, data);
}
-CPopup* CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
- std::vector<CPopup*> popups;
- breadthfirst([](CPopup* popup, void* data) { ((std::vector<CPopup*>*)data)->push_back(popup); }, &popups);
+WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
+ std::vector<WP<CPopup>> popups;
+ breadthfirst([](WP<CPopup> popup, void* data) { ((std::vector<WP<CPopup>>*)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<CXDGPopupResource> popup, CPopup* pOwner);
+ CPopup(SP<CXDGPopupResource> popup, WP<CPopup> pOwner);
~CPopup();
@@ -36,11 +36,12 @@ class CPopup {
bool visible();
// will also loop over this node
- void breadthfirst(std::function<void(CPopup*, void*)> fn, void* data);
- CPopup* at(const Vector2D& globalCoords, bool allowsInput = false);
+ void breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data);
+ WP<CPopup> at(const Vector2D& globalCoords, bool allowsInput = false);
//
SP<CWLSurface> m_pWLSurface;
+ WP<CPopup> m_pSelf;
bool m_bMapped = false;
private:
@@ -49,7 +50,7 @@ class CPopup {
PHLLSREF m_pLayerOwner;
// T2 owners
- CPopup* m_pParent = nullptr;
+ WP<CPopup> m_pParent;
WP<CXDGPopupResource> m_pResource;
@@ -81,5 +82,5 @@ class CPopup {
Vector2D localToGlobal(const Vector2D& rel);
Vector2D t1ParentCoords();
- static void bfHelper(std::vector<CPopup*> const& nodes, std::function<void(CPopup*, void*)> fn, void* data);
+ static void bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(WP<CPopup>, 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<CPopup> pOwner) : m_pPopupParent(pOwner) {
initSignals();
initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
}
@@ -24,7 +24,7 @@ CSubsurface::CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner
initExistingSubsurfaces(pSubsurface->surface.lock());
}
-CSubsurface::CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, CPopup* pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) {
+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();
@@ -132,16 +132,18 @@ void CSubsurface::onDestroy() {
}
void CSubsurface::onNewSubsurface(SP<CWLSubsurfaceResource> pSubsurface) {
- CSubsurface* PSUBSURFACE = nullptr;
+ WP<CSubsurface> PSUBSURFACE;
if (!m_pWindowParent.expired())
- PSUBSURFACE = m_vChildren.emplace_back(makeUnique<CSubsurface>(pSubsurface, m_pWindowParent.lock())).get();
+ PSUBSURFACE = m_vChildren.emplace_back(makeUnique<CSubsurface>(pSubsurface, m_pWindowParent.lock()));
else if (m_pPopupParent)
- PSUBSURFACE = m_vChildren.emplace_back(makeUnique<CSubsurface>(pSubsurface, m_pPopupParent)).get();
+ PSUBSURFACE = m_vChildren.emplace_back(makeUnique<CSubsurface>(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<CPopup> pOwner);
// real nodes
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner);
- CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, CPopup* pOwner);
+ CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner);
~CSubsurface();
- Vector2D coordsRelativeToParent();
- Vector2D coordsGlobal();
+ Vector2D coordsRelativeToParent();
+ Vector2D coordsGlobal();
- Vector2D size();
+ Vector2D size();
- void onCommit();
- void onDestroy();
- void onNewSubsurface(SP<CWLSubsurfaceResource> pSubsurface);
- void onMap();
- void onUnmap();
+ void onCommit();
+ void onDestroy();
+ void onNewSubsurface(SP<CWLSubsurfaceResource> pSubsurface);
+ void onMap();
+ void onUnmap();
- bool visible();
+ bool visible();
- void recheckDamageForSubsurfaces();
+ void recheckDamageForSubsurfaces();
+
+ WP<CSubsurface> 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<CSubsurface> m_pParent;
PHLWINDOWREF m_pWindowParent;
- CPopup* m_pPopupParent = nullptr;
+ WP<CPopup> m_pPopupParent;
std::vector<UP<CSubsurface>> 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<CPopup> 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<CSubsurface>(m_pSelf.lock());
- m_pPopupHead = makeUnique<CPopup>(m_pSelf.lock());
+ 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;
}
void CWindow::onBorderAngleAnimEnd(WP<CBaseAnimatedVariable> 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<CPopup> 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<CPopup> 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<CPopup> popup, void* data) {
if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped)
return;