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-01-23 21:55:41 +01:00
|
|
|
const auto PINHIBIT = m_vIdleInhibitors.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
|
|
|
|
2024-07-22 11:06:11 -05:00
|
|
|
Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface.get());
|
2024-04-12 00:17:50 +01:00
|
|
|
|
2024-05-05 17:16:00 +01:00
|
|
|
PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource->events.destroy.registerListener([this, PINHIBIT](std::any data) {
|
2024-04-24 19:05:19 -04:00
|
|
|
std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; });
|
|
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
|
});
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
auto WLSurface = CWLSurface::fromResource(PINHIBIT->inhibitor->surface.lock());
|
2024-05-04 23:46:10 +01:00
|
|
|
|
|
|
|
|
if (!WLSurface) {
|
2024-05-05 22:04:40 +09:00
|
|
|
Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Assuming it's visible.");
|
|
|
|
|
PINHIBIT->nonDesktop = true;
|
2024-05-04 23:46:10 +01:00
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 02:37:12 +02:00
|
|
|
PINHIBIT->surfaceDestroyListener = WLSurface->m_events.destroy.registerListener(
|
2024-05-04 23:46:10 +01:00
|
|
|
[this, PINHIBIT](std::any data) { std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); });
|
|
|
|
|
|
2022-07-06 15:42:37 +02:00
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CInputManager::recheckIdleInhibitorStatus() {
|
|
|
|
|
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& ii : m_vIdleInhibitors) {
|
2024-05-05 22:04:40 +09:00
|
|
|
if (ii->nonDesktop) {
|
|
|
|
|
PROTO::idle->setInhibit(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-04 23:46:10 +01:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
auto WLSurface = CWLSurface::fromResource(ii->inhibitor->surface.lock());
|
2024-05-04 23:46:10 +01:00
|
|
|
|
|
|
|
|
if (!WLSurface)
|
2024-04-29 17:42:07 +01:00
|
|
|
continue;
|
|
|
|
|
|
2024-05-04 23:46:10 +01:00
|
|
|
if (WLSurface->visible()) {
|
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-04-28 22:25:22 +02:00
|
|
|
if (w->m_idleInhibitMode == IDLEINHIBIT_ALWAYS)
|
2024-12-13 21:30:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
if (w->m_idleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w))
|
2024-12-13 21:30:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
if (w->m_idleInhibitMode == 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;
|
|
|
|
|
|
|
|
|
|
for (auto const& ii : m_vIdleInhibitors) {
|
|
|
|
|
if (ii->nonDesktop || !ii->inhibitor)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool isInhibiting = false;
|
2025-04-28 22:25:22 +02:00
|
|
|
w->m_wlSurface->resource()->breadthfirst(
|
2024-12-13 21:30:19 +00:00
|
|
|
[&ii](SP<CWLSurfaceResource> 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;
|
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
|
|
|
}
|