popup: minor safety improvements

This commit is contained in:
Vaxry 2024-06-05 16:53:06 +02:00
parent fefa55d406
commit 155fe6f165
2 changed files with 22 additions and 4 deletions

View file

@ -45,7 +45,7 @@ void CPopup::initAllSignals() {
listeners.reposition = m_pResource->events.reposition.registerListener([this](std::any d) { this->onReposition(); }); 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.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.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.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.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)); }); 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() { void CPopup::onMap() {
if (m_bMapped)
return;
m_bMapped = true;
m_vLastSize = {m_pResource->surface->surface->current.width, m_pResource->surface->surface->current.height}; m_vLastSize = {m_pResource->surface->surface->current.width, m_pResource->surface->surface->current.height};
const auto COORDS = coordsGlobal(); const auto COORDS = coordsGlobal();
const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS); const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS);
@ -90,8 +94,15 @@ void CPopup::onMap() {
} }
void CPopup::onUnmap() { void CPopup::onUnmap() {
if (!m_pResource || !m_pResource->surface) if (!m_bMapped)
return; 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}; m_vLastSize = {m_pResource->surface->surface->current.width, m_pResource->surface->surface->current.height};
const auto COORDS = coordsGlobal(); const auto COORDS = coordsGlobal();
@ -109,7 +120,7 @@ void CPopup::onUnmap() {
// damage all children // damage all children
breadthfirst( breadthfirst(
[this](CPopup* p, void* data) { [](CPopup* p, void* data) {
if (!p->m_pResource) if (!p->m_pResource)
return; return;
@ -120,6 +131,12 @@ void CPopup::onUnmap() {
} }
void CPopup::onCommit(bool ignoreSiblings) { 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) { if (m_pResource->surface->initialCommit) {
m_pResource->surface->scheduleConfigure(); m_pResource->surface->scheduleConfigure();
return; return;

View file

@ -56,7 +56,8 @@ class CPopup {
bool m_bRequestedReposition = false; bool m_bRequestedReposition = false;
bool m_bInert = false; bool m_bInert = false;
bool m_bMapped = false;
// //
std::vector<std::unique_ptr<CPopup>> m_vChildren; std::vector<std::unique_ptr<CPopup>> m_vChildren;