diff options
author | Vaxry <[email protected]> | 2024-06-05 16:53:06 +0200 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-06-05 16:53:49 +0200 |
commit | 155fe6f165f70ea69a44cbd6989fc01a473e6946 (patch) | |
tree | f75c11207e0c091698adfb3b929309091c5eca2e | |
parent | fefa55d406e38eda481ce75178cef3e43298762d (diff) | |
download | Hyprland-155fe6f165f70ea69a44cbd6989fc01a473e6946.tar.gz Hyprland-155fe6f165f70ea69a44cbd6989fc01a473e6946.zip |
popup: minor safety improvements
-rw-r--r-- | src/desktop/Popup.cpp | 23 | ||||
-rw-r--r-- | src/desktop/Popup.hpp | 3 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 03acfff9..d42a0ef0 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -45,7 +45,7 @@ void CPopup::initAllSignals() { listeners.reposition = m_pResource->events.reposition.registerListener([this](std::any d) { this->onReposition(); }); listeners.map = m_pResource->surface->events.map.registerListener([this](std::any d) { this->onMap(); }); listeners.unmap = m_pResource->surface->events.unmap.registerListener([this](std::any d) { this->onUnmap(); }); - listeners.dismissed = m_pResource->surface->events.unmap.registerListener([this](std::any d) { this->onUnmap(); }); + listeners.dismissed = m_pResource->events.dismissed.registerListener([this](std::any d) { this->onUnmap(); }); listeners.destroy = m_pResource->surface->events.destroy.registerListener([this](std::any d) { this->onDestroy(); }); listeners.commit = m_pResource->surface->events.commit.registerListener([this](std::any d) { this->onCommit(); }); listeners.newPopup = m_pResource->surface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); }); @@ -66,6 +66,10 @@ void CPopup::onDestroy() { } void CPopup::onMap() { + if (m_bMapped) + return; + + m_bMapped = true; m_vLastSize = {m_pResource->surface->surface->current.width, m_pResource->surface->surface->current.height}; const auto COORDS = coordsGlobal(); const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS); @@ -90,8 +94,15 @@ void CPopup::onMap() { } void CPopup::onUnmap() { - if (!m_pResource || !m_pResource->surface) + if (!m_bMapped) + return; + + if (!m_pResource || !m_pResource->surface) { + Debug::log(ERR, "CPopup: orphaned (no surface/resource) and unmaps??"); + onDestroy(); return; + } + m_vLastSize = {m_pResource->surface->surface->current.width, m_pResource->surface->surface->current.height}; const auto COORDS = coordsGlobal(); @@ -109,7 +120,7 @@ void CPopup::onUnmap() { // damage all children breadthfirst( - [this](CPopup* p, void* data) { + [](CPopup* p, void* data) { if (!p->m_pResource) return; @@ -120,6 +131,12 @@ void CPopup::onUnmap() { } void CPopup::onCommit(bool ignoreSiblings) { + if (!m_pResource || !m_pResource->surface) { + Debug::log(ERR, "CPopup: orphaned (no surface/resource) and commits??"); + onDestroy(); + return; + } + if (m_pResource->surface->initialCommit) { m_pResource->surface->scheduleConfigure(); return; diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index ba6da55a..7fdabee6 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -56,7 +56,8 @@ class CPopup { bool m_bRequestedReposition = false; - bool m_bInert = false; + bool m_bInert = false; + bool m_bMapped = false; // std::vector<std::unique_ptr<CPopup>> m_vChildren; |