mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-09-23 11:48:29 +00:00
desktop: move desktop types to memory-safe pointers
This commit is contained in:
@@ -571,7 +571,6 @@ void CCompositor::cleanup() {
|
|||||||
g_pLayoutManager.reset();
|
g_pLayoutManager.reset();
|
||||||
g_pHyprError.reset();
|
g_pHyprError.reset();
|
||||||
g_pConfigManager.reset();
|
g_pConfigManager.reset();
|
||||||
g_pAnimationManager.reset();
|
|
||||||
g_pKeybindManager.reset();
|
g_pKeybindManager.reset();
|
||||||
g_pHookSystem.reset();
|
g_pHookSystem.reset();
|
||||||
g_pWatchdog.reset();
|
g_pWatchdog.reset();
|
||||||
|
@@ -33,6 +33,7 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
|
|||||||
|
|
||||||
pLS->layer = resource->current.layer;
|
pLS->layer = resource->current.layer;
|
||||||
pLS->popupHead = makeUnique<CPopup>(pLS);
|
pLS->popupHead = makeUnique<CPopup>(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);
|
||||||
|
|
||||||
@@ -331,7 +332,7 @@ void CLayerSurface::onCommit() {
|
|||||||
nullptr);
|
nullptr);
|
||||||
if (!WASLASTFOCUS && popupHead) {
|
if (!WASLASTFOCUS && popupHead) {
|
||||||
popupHead->breadthfirst(
|
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());
|
WASLASTFOCUS = WASLASTFOCUS || (popup->m_pWLSurface && g_pSeatManager->state.keyboardFocus == popup->m_pWLSurface->resource());
|
||||||
},
|
},
|
||||||
nullptr);
|
nullptr);
|
||||||
@@ -576,7 +577,7 @@ int CLayerSurface::popupsCount() {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int no = -1; // we have one dummy
|
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;
|
return no;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,8 @@ CPopup::CPopup(PHLLS pOwner) : m_pLayerOwner(pOwner) {
|
|||||||
initAllSignals();
|
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 = CWLSurface::create();
|
||||||
m_pWLSurface->assign(popup->surface->surface.lock(), this);
|
m_pWLSurface->assign(popup->surface->surface.lock(), this);
|
||||||
|
|
||||||
@@ -58,7 +59,8 @@ 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, 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);
|
Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +91,8 @@ void CPopup::onMap() {
|
|||||||
|
|
||||||
g_pInputManager->simulateMouseMovement();
|
g_pInputManager->simulateMouseMovement();
|
||||||
|
|
||||||
m_pSubsurfaceHead = makeUnique<CSubsurface>(this);
|
m_pSubsurfaceHead = makeUnique<CSubsurface>(m_pSelf);
|
||||||
|
m_pSubsurfaceHead->m_pSelf = m_pSubsurfaceHead;
|
||||||
|
|
||||||
//unconstrain();
|
//unconstrain();
|
||||||
sendScale();
|
sendScale();
|
||||||
@@ -126,7 +129,7 @@ void CPopup::onUnmap() {
|
|||||||
|
|
||||||
// damage all children
|
// damage all children
|
||||||
breadthfirst(
|
breadthfirst(
|
||||||
[](CPopup* p, void* data) {
|
[](WP<CPopup> p, void* data) {
|
||||||
if (!p->m_pResource)
|
if (!p->m_pResource)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -223,7 +226,7 @@ Vector2D CPopup::coordsRelativeToParent() {
|
|||||||
if (!m_pResource)
|
if (!m_pResource)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
CPopup* current = this;
|
WP<CPopup> current = m_pSelf;
|
||||||
offset -= current->m_pResource->surface->current.geometry.pos();
|
offset -= current->m_pResource->surface->current.geometry.pos();
|
||||||
|
|
||||||
while (current->m_pParent && current->m_pResource) {
|
while (current->m_pParent && current->m_pResource) {
|
||||||
@@ -256,7 +259,7 @@ Vector2D CPopup::t1ParentCoords() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CPopup::recheckTree() {
|
void CPopup::recheckTree() {
|
||||||
CPopup* curr = this;
|
WP<CPopup> curr = m_pSelf;
|
||||||
while (curr->m_pParent) {
|
while (curr->m_pParent) {
|
||||||
curr = curr->m_pParent;
|
curr = curr->m_pParent;
|
||||||
}
|
}
|
||||||
@@ -296,17 +299,17 @@ bool CPopup::visible() {
|
|||||||
return false;
|
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) {
|
for (auto const& n : nodes) {
|
||||||
fn(n, data);
|
fn(n, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CPopup*> nodes2;
|
std::vector<WP<CPopup>> nodes2;
|
||||||
nodes2.reserve(nodes.size() * 2);
|
nodes2.reserve(nodes.size() * 2);
|
||||||
|
|
||||||
for (auto const& n : nodes) {
|
for (auto const& n : nodes) {
|
||||||
for (auto const& c : n->m_vChildren) {
|
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);
|
bfHelper(nodes2, fn, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPopup::breadthfirst(std::function<void(CPopup*, void*)> fn, void* data) {
|
void CPopup::breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data) {
|
||||||
std::vector<CPopup*> popups;
|
std::vector<WP<CPopup>> popups;
|
||||||
popups.push_back(this);
|
popups.push_back(m_pSelf);
|
||||||
bfHelper(popups, fn, data);
|
bfHelper(popups, fn, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPopup* CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
|
WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
|
||||||
std::vector<CPopup*> popups;
|
std::vector<WP<CPopup>> popups;
|
||||||
breadthfirst([](CPopup* popup, void* data) { ((std::vector<CPopup*>*)data)->push_back(popup); }, &popups);
|
breadthfirst([](WP<CPopup> popup, void* data) { ((std::vector<WP<CPopup>>*)data)->push_back(popup); }, &popups);
|
||||||
|
|
||||||
for (auto const& p : popups | std::views::reverse) {
|
for (auto const& p : popups | std::views::reverse) {
|
||||||
if (!p->m_pResource || !p->m_bMapped)
|
if (!p->m_pResource || !p->m_bMapped)
|
||||||
@@ -344,5 +347,5 @@ CPopup* CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ class CPopup {
|
|||||||
CPopup(PHLLS pOwner);
|
CPopup(PHLLS pOwner);
|
||||||
|
|
||||||
// real nodes
|
// real nodes
|
||||||
CPopup(SP<CXDGPopupResource> popup, CPopup* pOwner);
|
CPopup(SP<CXDGPopupResource> popup, WP<CPopup> pOwner);
|
||||||
|
|
||||||
~CPopup();
|
~CPopup();
|
||||||
|
|
||||||
@@ -36,11 +36,12 @@ class CPopup {
|
|||||||
bool visible();
|
bool visible();
|
||||||
|
|
||||||
// will also loop over this node
|
// will also loop over this node
|
||||||
void breadthfirst(std::function<void(CPopup*, void*)> fn, void* data);
|
void breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data);
|
||||||
CPopup* at(const Vector2D& globalCoords, bool allowsInput = false);
|
WP<CPopup> at(const Vector2D& globalCoords, bool allowsInput = false);
|
||||||
|
|
||||||
//
|
//
|
||||||
SP<CWLSurface> m_pWLSurface;
|
SP<CWLSurface> m_pWLSurface;
|
||||||
|
WP<CPopup> m_pSelf;
|
||||||
bool m_bMapped = false;
|
bool m_bMapped = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -49,7 +50,7 @@ class CPopup {
|
|||||||
PHLLSREF m_pLayerOwner;
|
PHLLSREF m_pLayerOwner;
|
||||||
|
|
||||||
// T2 owners
|
// T2 owners
|
||||||
CPopup* m_pParent = nullptr;
|
WP<CPopup> m_pParent;
|
||||||
|
|
||||||
WP<CXDGPopupResource> m_pResource;
|
WP<CXDGPopupResource> m_pResource;
|
||||||
|
|
||||||
@@ -81,5 +82,5 @@ class CPopup {
|
|||||||
|
|
||||||
Vector2D localToGlobal(const Vector2D& rel);
|
Vector2D localToGlobal(const Vector2D& rel);
|
||||||
Vector2D t1ParentCoords();
|
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);
|
||||||
};
|
};
|
||||||
|
@@ -12,7 +12,7 @@ CSubsurface::CSubsurface(PHLWINDOW pOwner) : m_pWindowParent(pOwner) {
|
|||||||
initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
|
initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
|
||||||
}
|
}
|
||||||
|
|
||||||
CSubsurface::CSubsurface(CPopup* pOwner) : m_pPopupParent(pOwner) {
|
CSubsurface::CSubsurface(WP<CPopup> pOwner) : m_pPopupParent(pOwner) {
|
||||||
initSignals();
|
initSignals();
|
||||||
initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
|
initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ CSubsurface::CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner
|
|||||||
initExistingSubsurfaces(pSubsurface->surface.lock());
|
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 = CWLSurface::create();
|
||||||
m_pWLSurface->assign(pSubsurface->surface.lock(), this);
|
m_pWLSurface->assign(pSubsurface->surface.lock(), this);
|
||||||
initSignals();
|
initSignals();
|
||||||
@@ -132,16 +132,18 @@ void CSubsurface::onDestroy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CSubsurface::onNewSubsurface(SP<CWLSubsurfaceResource> pSubsurface) {
|
void CSubsurface::onNewSubsurface(SP<CWLSubsurfaceResource> pSubsurface) {
|
||||||
CSubsurface* PSUBSURFACE = nullptr;
|
WP<CSubsurface> PSUBSURFACE;
|
||||||
|
|
||||||
if (!m_pWindowParent.expired())
|
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)
|
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);
|
ASSERT(PSUBSURFACE);
|
||||||
|
|
||||||
PSUBSURFACE->m_pParent = this;
|
PSUBSURFACE->m_pParent = PSUBSURFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSubsurface::onMap() {
|
void CSubsurface::onMap() {
|
||||||
|
@@ -11,11 +11,11 @@ class CSubsurface {
|
|||||||
public:
|
public:
|
||||||
// root dummy nodes
|
// root dummy nodes
|
||||||
CSubsurface(PHLWINDOW pOwner);
|
CSubsurface(PHLWINDOW pOwner);
|
||||||
CSubsurface(CPopup* pOwner);
|
CSubsurface(WP<CPopup> pOwner);
|
||||||
|
|
||||||
// real nodes
|
// real nodes
|
||||||
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner);
|
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, PHLWINDOW pOwner);
|
||||||
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, CPopup* pOwner);
|
CSubsurface(SP<CWLSubsurfaceResource> pSubsurface, WP<CPopup> pOwner);
|
||||||
|
|
||||||
~CSubsurface();
|
~CSubsurface();
|
||||||
|
|
||||||
@@ -34,6 +34,8 @@ class CSubsurface {
|
|||||||
|
|
||||||
void recheckDamageForSubsurfaces();
|
void recheckDamageForSubsurfaces();
|
||||||
|
|
||||||
|
WP<CSubsurface> m_pSelf;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct {
|
struct {
|
||||||
CHyprSignalListener destroySubsurface;
|
CHyprSignalListener destroySubsurface;
|
||||||
@@ -48,10 +50,10 @@ class CSubsurface {
|
|||||||
Vector2D m_vLastSize = {};
|
Vector2D m_vLastSize = {};
|
||||||
|
|
||||||
// if nullptr, means it's a dummy node
|
// if nullptr, means it's a dummy node
|
||||||
CSubsurface* m_pParent = nullptr;
|
WP<CSubsurface> m_pParent;
|
||||||
|
|
||||||
PHLWINDOWREF m_pWindowParent;
|
PHLWINDOWREF m_pWindowParent;
|
||||||
CPopup* m_pPopupParent = nullptr;
|
WP<CPopup> m_pPopupParent;
|
||||||
|
|
||||||
std::vector<UP<CSubsurface>> m_vChildren;
|
std::vector<UP<CSubsurface>> m_vChildren;
|
||||||
|
|
||||||
|
@@ -154,7 +154,7 @@ SBoxExtents CWindow::getFullWindowExtents() {
|
|||||||
CBox surfaceExtents = {0, 0, 0, 0};
|
CBox surfaceExtents = {0, 0, 0, 0};
|
||||||
// TODO: this could be better, perhaps make a getFullWindowRegion?
|
// TODO: this could be better, perhaps make a getFullWindowRegion?
|
||||||
m_pPopupHead->breadthfirst(
|
m_pPopupHead->breadthfirst(
|
||||||
[](CPopup* popup, void* data) {
|
[](WP<CPopup> popup, void* data) {
|
||||||
if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource())
|
if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -570,7 +570,9 @@ void CWindow::onMap() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_pSubsurfaceHead = makeUnique<CSubsurface>(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 = makeUnique<CPopup>(m_pSelf.lock());
|
||||||
|
m_pPopupHead->m_pSelf = m_pPopupHead;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindow::onBorderAngleAnimEnd(WP<CBaseAnimatedVariable> pav) {
|
void CWindow::onBorderAngleAnimEnd(WP<CBaseAnimatedVariable> pav) {
|
||||||
@@ -847,7 +849,7 @@ bool CWindow::hasPopupAt(const Vector2D& pos) {
|
|||||||
if (m_bIsX11)
|
if (m_bIsX11)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CPopup* popup = m_pPopupHead->at(pos);
|
auto popup = m_pPopupHead->at(pos);
|
||||||
|
|
||||||
return popup && popup->m_pWLSurface->resource();
|
return popup && popup->m_pWLSurface->resource();
|
||||||
}
|
}
|
||||||
@@ -1289,7 +1291,7 @@ int CWindow::popupsCount() {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int no = -1;
|
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;
|
return no;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -181,6 +181,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
g_pCompositor->cleanup();
|
g_pCompositor->cleanup();
|
||||||
|
|
||||||
|
g_pCompositor.reset();
|
||||||
|
|
||||||
Debug::log(LOG, "Hyprland has reached the end.");
|
Debug::log(LOG, "Hyprland has reached the end.");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@@ -615,7 +615,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, PHLMONITOR pMonitor, timespe
|
|||||||
renderdata.surfaceCounter = 0;
|
renderdata.surfaceCounter = 0;
|
||||||
|
|
||||||
pWindow->m_pPopupHead->breadthfirst(
|
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)
|
if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped)
|
||||||
return;
|
return;
|
||||||
const auto pos = popup->coordsRelativeToParent();
|
const auto pos = popup->coordsRelativeToParent();
|
||||||
@@ -718,7 +718,7 @@ void CHyprRenderer::renderLayer(PHLLS pLayer, PHLMONITOR pMonitor, timespec* tim
|
|||||||
renderdata.surfaceCounter = 0;
|
renderdata.surfaceCounter = 0;
|
||||||
if (popups) {
|
if (popups) {
|
||||||
pLayer->popupHead->breadthfirst(
|
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)
|
if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource() || !popup->m_bMapped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user