diff options
| author | davc0n <dconti.dev@gmail.com> | 2025-04-24 20:49:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-24 20:49:49 +0200 |
| commit | 0e80ecc5342db04c8c1f807fa6db4c703fb89e3a (patch) | |
| tree | d71179a6517216ab32a12ebaf147e9eaffdbdffa /src/desktop/Popup.cpp | |
| parent | be6268a7ecea2ad50cdb78fb661884811a8a28e8 (diff) | |
layers: refactor class member vars (#10149)
* layers: refactor class member vars
* popups: rename m_WLSurface to m_wlSurface
Diffstat (limited to 'src/desktop/Popup.cpp')
| -rw-r--r-- | src/desktop/Popup.cpp | 226 |
1 files changed, 114 insertions, 112 deletions
diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 912069e7..d67eec6c 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -13,32 +13,32 @@ #include <ranges> UP<CPopup> CPopup::create(PHLWINDOW pOwner) { - auto popup = UP<CPopup>(new CPopup()); - popup->m_pWindowOwner = pOwner; - popup->m_pSelf = popup; + auto popup = UP<CPopup>(new CPopup()); + popup->m_windowOwner = pOwner; + popup->m_self = popup; popup->initAllSignals(); return popup; } UP<CPopup> CPopup::create(PHLLS pOwner) { - auto popup = UP<CPopup>(new CPopup()); - popup->m_pLayerOwner = pOwner; - popup->m_pSelf = popup; + auto popup = UP<CPopup>(new CPopup()); + popup->m_layerOwner = pOwner; + popup->m_self = popup; popup->initAllSignals(); return popup; } UP<CPopup> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) { - auto popup = UP<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(); + auto popup = UP<CPopup>(new CPopup()); + popup->m_resource = resource; + popup->m_windowOwner = pOwner->m_windowOwner; + popup->m_layerOwner = pOwner->m_layerOwner; + popup->m_parent = pOwner; + popup->m_self = popup; + popup->m_wlSurface = CWLSurface::create(); + popup->m_wlSurface->assign(resource->surface->surface.lock(), popup.get()); + + popup->m_lastSize = resource->surface->current.geometry.size(); popup->reposition(); popup->initAllSignals(); @@ -46,104 +46,106 @@ UP<CPopup> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) { } CPopup::~CPopup() { - if (m_pWLSurface) - m_pWLSurface->unassign(); + if (m_wlSurface) + m_wlSurface->unassign(); } void CPopup::initAllSignals() { - if (!m_pResource) { - if (!m_pWindowOwner.expired()) - listeners.newPopup = m_pWindowOwner->m_pXDGSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); }); - else if (!m_pLayerOwner.expired()) - listeners.newPopup = m_pLayerOwner->layerSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); }); + if (!m_resource) { + if (!m_windowOwner.expired()) + m_listeners.newPopup = + m_windowOwner->m_pXDGSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); }); + else if (!m_layerOwner.expired()) + m_listeners.newPopup = + m_layerOwner->m_layerSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); }); else ASSERT(false); return; } - 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->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)); }); + m_listeners.reposition = m_resource->events.reposition.registerListener([this](std::any d) { this->onReposition(); }); + m_listeners.map = m_resource->surface->events.map.registerListener([this](std::any d) { this->onMap(); }); + m_listeners.unmap = m_resource->surface->events.unmap.registerListener([this](std::any d) { this->onUnmap(); }); + m_listeners.dismissed = m_resource->events.dismissed.registerListener([this](std::any d) { this->onUnmap(); }); + m_listeners.destroy = m_resource->surface->events.destroy.registerListener([this](std::any d) { this->onDestroy(); }); + m_listeners.commit = m_resource->surface->events.commit.registerListener([this](std::any d) { this->onCommit(); }); + m_listeners.newPopup = m_resource->surface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); }); } void CPopup::onNewPopup(SP<CXDGPopupResource> popup) { - const auto& POPUP = m_vChildren.emplace_back(CPopup::create(popup, m_pSelf)); - POPUP->m_pSelf = POPUP; + const auto& POPUP = m_children.emplace_back(CPopup::create(popup, m_self)); + POPUP->m_self = POPUP; Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP); } void CPopup::onDestroy() { - m_bInert = true; + m_inert = true; - if (!m_pParent) + if (!m_parent) return; // head node - std::erase_if(m_pParent->m_vChildren, [this](const auto& other) { return other.get() == this; }); + std::erase_if(m_parent->m_children, [this](const auto& other) { return other.get() == this; }); } void CPopup::onMap() { - if (m_bMapped) + if (m_mapped) return; - m_bMapped = true; - m_vLastSize = m_pResource->surface->surface->current.size; + m_mapped = true; + m_lastSize = m_resource->surface->surface->current.size; const auto COORDS = coordsGlobal(); const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS); - CBox box = m_pWLSurface->resource()->extends(); + CBox box = m_wlSurface->resource()->extends(); box.translate(COORDS).expand(4); g_pHyprRenderer->damageBox(box); - m_vLastPos = coordsRelativeToParent(); + m_lastPos = coordsRelativeToParent(); g_pInputManager->simulateMouseMovement(); - m_pSubsurfaceHead = CSubsurface::create(m_pSelf); + m_subsurfaceHead = CSubsurface::create(m_self); //unconstrain(); sendScale(); - m_pResource->surface->surface->enter(PMONITOR->self.lock()); + m_resource->surface->surface->enter(PMONITOR->self.lock()); - if (!m_pLayerOwner.expired() && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) - g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer)); + if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) + g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer)); } void CPopup::onUnmap() { - if (!m_bMapped) + if (!m_mapped) return; - if (!m_pResource || !m_pResource->surface) { + if (!m_resource || !m_resource->surface) { Debug::log(ERR, "CPopup: orphaned (no surface/resource) and unmaps??"); onDestroy(); return; } - m_bMapped = false; + m_mapped = false; - m_vLastSize = m_pResource->surface->surface->current.size; + m_lastSize = m_resource->surface->surface->current.size; const auto COORDS = coordsGlobal(); - CBox box = m_pWLSurface->resource()->extends(); + CBox box = m_wlSurface->resource()->extends(); box.translate(COORDS).expand(4); g_pHyprRenderer->damageBox(box); - m_pSubsurfaceHead.reset(); + m_subsurfaceHead.reset(); - if (!m_pLayerOwner.expired() && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) - g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer)); + if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) + g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer)); // damage all children breadthfirst( [](WP<CPopup> p, void* data) { - if (!p->m_pResource) + if (!p->m_resource) return; auto box = CBox{p->coordsGlobal(), p->size()}; @@ -159,59 +161,59 @@ void CPopup::onUnmap() { } void CPopup::onCommit(bool ignoreSiblings) { - if (!m_pResource || !m_pResource->surface) { + if (!m_resource || !m_resource->surface) { Debug::log(ERR, "CPopup: orphaned (no surface/resource) and commits??"); onDestroy(); return; } - if (m_pResource->surface->initialCommit) { - m_pResource->surface->scheduleConfigure(); + if (m_resource->surface->initialCommit) { + m_resource->surface->scheduleConfigure(); return; } - if (!m_pWindowOwner.expired() && (!m_pWindowOwner->m_bIsMapped || !m_pWindowOwner->m_pWorkspace->m_bVisible)) { - m_vLastSize = m_pResource->surface->surface->current.size; + if (!m_windowOwner.expired() && (!m_windowOwner->m_bIsMapped || !m_windowOwner->m_pWorkspace->m_bVisible)) { + m_lastSize = m_resource->surface->surface->current.size; static auto PLOGDAMAGE = CConfigValue<Hyprlang::INT>("debug:log_damage"); if (*PLOGDAMAGE) - Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_pWindowOwner.lock()); + Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_windowOwner.lock()); return; } - if (!m_pResource->surface->mapped) + if (!m_resource->surface->mapped) return; const auto COORDS = coordsGlobal(); const auto COORDSLOCAL = coordsRelativeToParent(); - if (m_vLastSize != m_pResource->surface->surface->current.size || m_bRequestedReposition || m_vLastPos != COORDSLOCAL) { - CBox box = {localToGlobal(m_vLastPos), m_vLastSize}; + if (m_lastSize != m_resource->surface->surface->current.size || m_requestedReposition || m_lastPos != COORDSLOCAL) { + CBox box = {localToGlobal(m_lastPos), m_lastSize}; g_pHyprRenderer->damageBox(box); - m_vLastSize = m_pResource->surface->surface->current.size; - box = {COORDS, m_vLastSize}; + m_lastSize = m_resource->surface->surface->current.size; + box = {COORDS, m_lastSize}; g_pHyprRenderer->damageBox(box); - m_vLastPos = COORDSLOCAL; + m_lastPos = COORDSLOCAL; } - if (!ignoreSiblings && m_pSubsurfaceHead) - m_pSubsurfaceHead->recheckDamageForSubsurfaces(); + if (!ignoreSiblings && m_subsurfaceHead) + m_subsurfaceHead->recheckDamageForSubsurfaces(); - g_pHyprRenderer->damageSurface(m_pWLSurface->resource(), COORDS.x, COORDS.y); + g_pHyprRenderer->damageSurface(m_wlSurface->resource(), COORDS.x, COORDS.y); - m_bRequestedReposition = false; + m_requestedReposition = false; - if (!m_pLayerOwner.expired() && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) - g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer)); + if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) + g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer)); } void CPopup::onReposition() { Debug::log(LOG, "Popup {:x} requests reposition", (uintptr_t)this); - m_bRequestedReposition = true; + m_requestedReposition = true; - m_vLastPos = coordsRelativeToParent(); + m_lastPos = coordsRelativeToParent(); reposition(); } @@ -224,31 +226,31 @@ void CPopup::reposition() { return; CBox box = {PMONITOR->vecPosition.x, PMONITOR->vecPosition.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; - m_pResource->applyPositioning(box, COORDS); + m_resource->applyPositioning(box, COORDS); } SP<CWLSurface> CPopup::getT1Owner() { - if (m_pWindowOwner) - return m_pWindowOwner->m_pWLSurface; + if (m_windowOwner) + return m_windowOwner->m_pWLSurface; else - return m_pLayerOwner->surface; + return m_layerOwner->m_surface; } Vector2D CPopup::coordsRelativeToParent() { Vector2D offset; - if (!m_pResource) + if (!m_resource) return {}; - WP<CPopup> current = m_pSelf; - offset -= current->m_pResource->surface->current.geometry.pos(); + WP<CPopup> current = m_self; + offset -= current->m_resource->surface->current.geometry.pos(); - while (current->m_pParent && current->m_pResource) { + while (current->m_parent && current->m_resource) { - offset += current->m_pWLSurface->resource()->current.offset; - offset += current->m_pResource->geometry.pos(); + offset += current->m_wlSurface->resource()->current.offset; + offset += current->m_resource->geometry.pos(); - current = current->m_pParent; + current = current->m_parent; } return offset; @@ -263,30 +265,30 @@ Vector2D CPopup::localToGlobal(const Vector2D& rel) { } Vector2D CPopup::t1ParentCoords() { - if (!m_pWindowOwner.expired()) - return m_pWindowOwner->m_vRealPosition->value(); - if (!m_pLayerOwner.expired()) - return m_pLayerOwner->realPosition->value(); + if (!m_windowOwner.expired()) + return m_windowOwner->m_vRealPosition->value(); + if (!m_layerOwner.expired()) + return m_layerOwner->m_realPosition->value(); ASSERT(false); return {}; } void CPopup::recheckTree() { - WP<CPopup> curr = m_pSelf; - while (curr->m_pParent) { - curr = curr->m_pParent; + WP<CPopup> curr = m_self; + while (curr->m_parent) { + curr = curr->m_parent; } curr->recheckChildrenRecursive(); } void CPopup::recheckChildrenRecursive() { - if (m_bInert || !m_pWLSurface) + if (m_inert || !m_wlSurface) return; std::vector<WP<CPopup>> cpy; - std::ranges::for_each(m_vChildren, [&cpy](const auto& el) { cpy.emplace_back(el); }); + std::ranges::for_each(m_children, [&cpy](const auto& el) { cpy.emplace_back(el); }); for (auto const& c : cpy) { c->onCommit(true); c->recheckChildrenRecursive(); @@ -294,25 +296,25 @@ void CPopup::recheckChildrenRecursive() { } Vector2D CPopup::size() { - return m_vLastSize; + return m_lastSize; } void CPopup::sendScale() { - if (!m_pWindowOwner.expired()) - g_pCompositor->setPreferredScaleForSurface(m_pWLSurface->resource(), m_pWindowOwner->m_pWLSurface->m_fLastScale); - else if (!m_pLayerOwner.expired()) - g_pCompositor->setPreferredScaleForSurface(m_pWLSurface->resource(), m_pLayerOwner->surface->m_fLastScale); + if (!m_windowOwner.expired()) + g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_windowOwner->m_pWLSurface->m_fLastScale); + else if (!m_layerOwner.expired()) + g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_layerOwner->m_surface->m_fLastScale); else UNREACHABLE(); } bool CPopup::visible() { - if (!m_pWindowOwner.expired()) - return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock()); - if (!m_pLayerOwner.expired()) + if (!m_windowOwner.expired()) + return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock()); + if (!m_layerOwner.expired()) return true; - if (m_pParent) - return m_pParent->visible(); + if (m_parent) + return m_parent->visible(); return false; } @@ -326,8 +328,8 @@ void CPopup::bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(W nodes2.reserve(nodes.size() * 2); for (auto const& n : nodes) { - for (auto const& c : n->m_vChildren) { - nodes2.push_back(c->m_pSelf); + for (auto const& c : n->m_children) { + nodes2.push_back(c->m_self); } } @@ -337,7 +339,7 @@ void CPopup::bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(W void CPopup::breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data) { std::vector<WP<CPopup>> popups; - popups.push_back(m_pSelf); + popups.push_back(m_self); bfHelper(popups, fn, data); } @@ -346,14 +348,14 @@ WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) { breadthfirst([&popups](WP<CPopup> popup, void* data) { popups.push_back(popup); }, &popups); for (auto const& p : popups | std::views::reverse) { - if (!p->m_pResource || !p->m_bMapped) + if (!p->m_resource || !p->m_mapped) continue; if (!allowsInput) { - const bool HASSURFACE = p->m_pResource && p->m_pResource->surface; + const bool HASSURFACE = p->m_resource && p->m_resource->surface; - Vector2D offset = HASSURFACE ? p->m_pResource->surface->current.geometry.pos() : Vector2D{}; - Vector2D size = HASSURFACE ? p->m_pResource->surface->current.geometry.size() : p->size(); + Vector2D offset = HASSURFACE ? p->m_resource->surface->current.geometry.pos() : Vector2D{}; + Vector2D size = HASSURFACE ? p->m_resource->surface->current.geometry.size() : p->size(); if (size == Vector2D{}) size = p->size(); @@ -362,7 +364,7 @@ WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) { if (BOX.containsPoint(globalCoords)) return p; } else { - const auto REGION = CRegion{p->m_pWLSurface->resource()->current.input}.intersect(CBox{{}, p->m_pWLSurface->resource()->current.size}).translate(p->coordsGlobal()); + const auto REGION = CRegion{p->m_wlSurface->resource()->current.input}.intersect(CBox{{}, p->m_wlSurface->resource()->current.size}).translate(p->coordsGlobal()); if (REGION.containsPoint(globalCoords)) return p; } @@ -372,5 +374,5 @@ WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) { } bool CPopup::inert() const { - return m_bInert; + return m_inert; } |
