From 35e134e5700b7adb393ba91127bd11188259b901 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 13 Dec 2024 21:30:19 +0000 Subject: hyprctl: add an inhibitingIdle field to windows fixes #4322 --- src/managers/input/IdleInhibitor.cpp | 54 +++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'src/managers/input/IdleInhibitor.cpp') diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index a99184e0..74760c0a 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -2,6 +2,7 @@ #include "../../Compositor.hpp" #include "../../protocols/IdleInhibit.hpp" #include "../../protocols/IdleNotify.hpp" +#include "../../protocols/core/Compositor.hpp" void CInputManager::newIdleInhibitor(std::any inhibitor) { const auto PINHIBIT = m_vIdleInhibitors.emplace_back(std::make_unique()).get(); @@ -50,24 +51,51 @@ void CInputManager::recheckIdleInhibitorStatus() { // check manual user-set inhibitors for (auto const& w : g_pCompositor->m_vWindows) { - if (w->m_eIdleInhibitMode == IDLEINHIBIT_NONE) - continue; - - if (w->m_eIdleInhibitMode == IDLEINHIBIT_ALWAYS) { + if (isWindowInhibiting(w)) { PROTO::idle->setInhibit(true); return; } + } - if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w)) { - PROTO::idle->setInhibit(true); - return; - } + PROTO::idle->setInhibit(false); +} - if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->isFullscreen() && w->m_pWorkspace && w->m_pWorkspace->isVisible()) { - PROTO::idle->setInhibit(true); - return; - } +bool CInputManager::isWindowInhibiting(const PHLWINDOW& w, bool onlyHl) { + if (w->m_eIdleInhibitMode == IDLEINHIBIT_ALWAYS) + return true; + + if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w)) + return true; + + if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->isFullscreen() && w->m_pWorkspace && w->m_pWorkspace->isVisible()) + return true; + + if (onlyHl) + return false; + + for (auto const& ii : m_vIdleInhibitors) { + if (ii->nonDesktop || !ii->inhibitor) + continue; + + bool isInhibiting = false; + w->m_pWLSurface->resource()->breadthfirst( + [&ii](SP surf, const Vector2D& pos, void* data) { + if (ii->inhibitor->surface != surf) + return; + + auto WLSurface = CWLSurface::fromResource(surf); + + if (!WLSurface) + return; + + if (WLSurface->visible()) + *(bool*)data = true; + }, + &isInhibiting); + + if (isInhibiting) + return true; } - PROTO::idle->setInhibit(false); + return false; } -- cgit v1.2.3