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 +++++++++++++++++++------------ src/managers/input/InputManager.hpp | 4 ++-- 2 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src/managers') 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; } diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 98032dd4..719e19c6 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -242,8 +242,8 @@ class CInputManager { // idle inhibitors struct SIdleInhibitor { std::shared_ptr inhibitor; - PHLWINDOWREF pWindow; - CHyprSignalListener windowDestroyListener; + bool inert = false; + CHyprSignalListener surfaceDestroyListener; }; std::vector> m_vIdleInhibitors; -- cgit v1.2.3