2022-07-06 15:42:37 +02:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
|
#include "../../Compositor.hpp"
|
2024-04-21 16:29:30 +01:00
|
|
|
#include "../../protocols/IdleInhibit.hpp"
|
2024-04-29 17:42:07 +01:00
|
|
|
#include "../../protocols/IdleNotify.hpp"
|
2024-12-13 21:30:19 +00:00
|
|
|
#include "../../protocols/core/Compositor.hpp"
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-04-21 16:29:30 +01:00
|
|
|
void CInputManager::newIdleInhibitor(std::any inhibitor) {
|
2025-05-01 23:57:11 +02:00
|
|
|
const auto PINHIBIT = m_idleInhibitors.emplace_back(makeUnique<SIdleInhibitor>()).get();
|
2024-05-05 17:16:00 +01:00
|
|
|
PINHIBIT->inhibitor = std::any_cast<SP<CIdleInhibitor>>(inhibitor);
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2025-12-18 17:23:24 +00:00
|
|
|
Log::logger->log(Log::DEBUG, "New idle inhibitor registered for surface {:x}", rc<uintptr_t>(PINHIBIT->inhibitor->m_surface.get()));
|
2024-04-12 00:17:50 +01:00
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
PINHIBIT->inhibitor->m_listeners.destroy = PINHIBIT->inhibitor->m_resource->m_events.destroy.listen([this, PINHIBIT] {
|
2025-05-01 23:57:11 +02:00
|
|
|
std::erase_if(m_idleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; });
|
2024-04-24 19:05:19 -04:00
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
|
});
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2025-12-08 15:04:40 +00:00
|
|
|
auto WLSurface = Desktop::View::CWLSurface::fromResource(PINHIBIT->inhibitor->m_surface.lock());
|
2024-05-04 23:46:10 +01:00
|
|
|
|
|
|
|
|
if (!WLSurface) {
|
2025-12-18 17:23:24 +00:00
|
|
|
Log::logger->log(Log::DEBUG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Assuming it's visible.");
|
2024-05-05 22:04:40 +09:00
|
|
|
PINHIBIT->nonDesktop = true;
|
2024-05-04 23:46:10 +01:00
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-08 09:56:40 -07:00
|
|
|
PINHIBIT->surfaceDestroyListener =
|
|
|
|
|
WLSurface->m_events.destroy.listen([this, PINHIBIT] { std::erase_if(m_idleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); });
|
2024-05-04 23:46:10 +01:00
|
|
|
|
2022-07-06 15:42:37 +02:00
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CInputManager::recheckIdleInhibitorStatus() {
|
|
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
for (auto const& ii : m_idleInhibitors) {
|
2024-05-05 22:04:40 +09:00
|
|
|
if (ii->nonDesktop) {
|
|
|
|
|
PROTO::idle->setInhibit(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-04 23:46:10 +01:00
|
|
|
|
2025-12-08 15:04:40 +00:00
|
|
|
auto WLSurface = Desktop::View::CWLSurface::fromResource(ii->inhibitor->m_surface.lock());
|
2024-05-04 23:46:10 +01:00
|
|
|
|
2025-12-11 16:29:26 +00:00
|
|
|
if (!WLSurface || !WLSurface->view())
|
2024-04-29 17:42:07 +01:00
|
|
|
continue;
|
|
|
|
|
|
2025-12-11 16:29:26 +00:00
|
|
|
if (WLSurface->view()->aliveAndVisible()) {
|
2024-04-29 17:42:07 +01:00
|
|
|
PROTO::idle->setInhibit(true);
|
2022-07-06 15:42:37 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-31 12:26:07 +00:00
|
|
|
// check manual user-set inhibitors
|
2025-04-22 15:23:29 +02:00
|
|
|
for (auto const& w : g_pCompositor->m_windows) {
|
2024-12-13 21:30:19 +00:00
|
|
|
if (isWindowInhibiting(w)) {
|
2024-04-29 17:42:07 +01:00
|
|
|
PROTO::idle->setInhibit(true);
|
2022-10-31 12:26:07 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2024-12-13 21:30:19 +00:00
|
|
|
}
|
2022-10-31 12:26:07 +00:00
|
|
|
|
2024-12-13 21:30:19 +00:00
|
|
|
PROTO::idle->setInhibit(false);
|
|
|
|
|
}
|
2022-10-31 12:26:07 +00:00
|
|
|
|
2024-12-13 21:30:19 +00:00
|
|
|
bool CInputManager::isWindowInhibiting(const PHLWINDOW& w, bool onlyHl) {
|
2025-11-17 18:34:02 +00:00
|
|
|
if (w->m_ruleApplicator->idleInhibitMode().valueOrDefault() == Desktop::Rule::IDLEINHIBIT_ALWAYS)
|
2024-12-13 21:30:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
2025-11-17 18:34:02 +00:00
|
|
|
if (w->m_ruleApplicator->idleInhibitMode().valueOrDefault() == Desktop::Rule::IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w))
|
2024-12-13 21:30:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
2025-11-17 18:34:02 +00:00
|
|
|
if (w->m_ruleApplicator->idleInhibitMode().valueOrDefault() == Desktop::Rule::IDLEINHIBIT_FULLSCREEN && w->isFullscreen() && w->m_workspace && w->m_workspace->isVisible())
|
2024-12-13 21:30:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (onlyHl)
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-05-01 23:57:11 +02:00
|
|
|
for (auto const& ii : m_idleInhibitors) {
|
2024-12-13 21:30:19 +00:00
|
|
|
if (ii->nonDesktop || !ii->inhibitor)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool isInhibiting = false;
|
2025-12-08 15:04:40 +00:00
|
|
|
w->wlSurface()->resource()->breadthfirst(
|
2024-12-13 21:30:19 +00:00
|
|
|
[&ii](SP<CWLSurfaceResource> surf, const Vector2D& pos, void* data) {
|
2025-05-04 00:13:29 +02:00
|
|
|
if (ii->inhibitor->m_surface != surf)
|
2024-12-13 21:30:19 +00:00
|
|
|
return;
|
|
|
|
|
|
2025-12-08 15:04:40 +00:00
|
|
|
auto WLSurface = Desktop::View::CWLSurface::fromResource(surf);
|
2024-12-13 21:30:19 +00:00
|
|
|
|
2025-12-11 16:29:26 +00:00
|
|
|
if (!WLSurface || !WLSurface->view())
|
2024-12-13 21:30:19 +00:00
|
|
|
return;
|
|
|
|
|
|
2025-12-11 16:29:26 +00:00
|
|
|
if (WLSurface->view()->aliveAndVisible())
|
2025-08-14 19:44:56 +05:00
|
|
|
*sc<bool*>(data) = true;
|
2024-12-13 21:30:19 +00:00
|
|
|
},
|
|
|
|
|
&isInhibiting);
|
|
|
|
|
|
|
|
|
|
if (isInhibiting)
|
|
|
|
|
return true;
|
2022-10-31 12:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-13 21:30:19 +00:00
|
|
|
return false;
|
2024-04-24 19:05:19 -04:00
|
|
|
}
|