diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-08-26 10:24:45 +0200 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-08-26 10:24:45 +0200 |
| commit | 83ab3ae0afeafe25ca2038888478740d0a80396a (patch) | |
| tree | 0a4fe421ed1375238d12fe55d5d898774848580b /src/managers/XWaylandManager.cpp | |
| parent | b672118f9238a48a18efd741cbcda387c5552238 (diff) | |
xwaylandmgr: minor refactor to activateSurface
Make it more efficient now that we can + fix possible nullptr deref
fixes #7514
Diffstat (limited to 'src/managers/XWaylandManager.cpp')
| -rw-r--r-- | src/managers/XWaylandManager.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 2f0632e0..a6fd97f5 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -28,26 +28,28 @@ void CHyprXWaylandManager::activateSurface(SP<CWLSurfaceResource> pSurface, bool if (!pSurface) return; - // TODO: - // this cannot be nicely done until we rewrite wlr_surface - for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped) - continue; - - if (w->m_pWLSurface->resource() != pSurface) - continue; - - if (w->m_bIsX11) { - if (activate) { - w->m_pXWaylandSurface->setMinimized(false); - w->m_pXWaylandSurface->restackToTop(); - } - w->m_pXWaylandSurface->activate(activate); - } else { - w->m_pXDGSurface->toplevel->setActive(activate); - if (g_pCompositor->m_pLastFocus && g_pCompositor->m_pLastWindow->m_bIsX11) - activateSurface(g_pCompositor->m_pLastFocus.lock(), false); + auto HLSurface = CWLSurface::fromResource(pSurface); + if (!HLSurface) { + Debug::log(TRACE, "CHyprXWaylandManager::activateSurface on non-desktop surface, ignoring"); + return; + } + + const auto PWINDOW = HLSurface->getWindow(); + if (!PWINDOW) { + Debug::log(TRACE, "CHyprXWaylandManager::activateSurface on non-window surface, ignoring"); + return; + } + + if (PWINDOW->m_bIsX11 && PWINDOW->m_pXWaylandSurface) { + if (activate) { + PWINDOW->m_pXWaylandSurface->setMinimized(false); + PWINDOW->m_pXWaylandSurface->restackToTop(); } + PWINDOW->m_pXWaylandSurface->activate(activate); + } else if (!PWINDOW->m_bIsX11 && PWINDOW->m_pXDGSurface) { + PWINDOW->m_pXDGSurface->toplevel->setActive(activate); + if (g_pCompositor->m_pLastFocus && g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsX11) + activateSurface(g_pCompositor->m_pLastFocus.lock(), false); } } |
