From 0b215c5f246d3fde6c023e78b3e3579f7498c172 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 4 May 2024 23:46:10 +0100 Subject: idle-inhibit: fix and cleanup visibility logic fixes #5878 --- src/managers/input/IdleInhibitor.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/managers/input/IdleInhibitor.cpp') diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index 40c8c637..dc7c61c3 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -14,26 +14,33 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) { recheckIdleInhibitorStatus(); }); - const auto PWINDOW = g_pCompositor->getWindowFromSurface(PINHIBIT->inhibitor->surface); - - if (PWINDOW) { - PINHIBIT->pWindow = PWINDOW; - PINHIBIT->windowDestroyListener = PWINDOW->events.destroy.registerListener([PINHIBIT](std::any data) { - Debug::log(WARN, "Inhibitor got its window destroyed before its inhibitor resource."); - PINHIBIT->pWindow.reset(); - }); - } else - Debug::log(WARN, "Inhibitor is for no window?"); + auto WLSurface = CWLSurface::surfaceFromWlr(PINHIBIT->inhibitor->surface); + + if (!WLSurface) { + Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Ignoring."); + PINHIBIT->inert = true; + recheckIdleInhibitorStatus(); + return; + } + + PINHIBIT->surfaceDestroyListener = WLSurface->events.destroy.registerListener( + [this, PINHIBIT](std::any data) { std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); }); + recheckIdleInhibitorStatus(); } void CInputManager::recheckIdleInhibitorStatus() { for (auto& ii : m_vIdleInhibitors) { - if (ii->pWindow.expired()) + if (ii->inert) + continue; + + auto WLSurface = CWLSurface::surfaceFromWlr(ii->inhibitor->surface); + + if (!WLSurface) continue; - if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow.lock())) { + if (WLSurface->visible()) { PROTO::idle->setInhibit(true); return; } -- cgit v1.2.3