2022-07-06 15:42:37 +02:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
#include "../../Compositor.hpp"
|
2024-04-21 17:29:30 +02:00
|
|
|
#include "../../protocols/IdleInhibit.hpp"
|
2024-04-29 18:42:07 +02:00
|
|
|
#include "../../protocols/IdleNotify.hpp"
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-04-21 17:29:30 +02:00
|
|
|
void CInputManager::newIdleInhibitor(std::any inhibitor) {
|
|
|
|
const auto PINHIBIT = m_vIdleInhibitors.emplace_back(std::make_unique<SIdleInhibitor>()).get();
|
|
|
|
PINHIBIT->inhibitor = std::any_cast<std::shared_ptr<CIdleInhibitor>>(inhibitor);
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-04-21 17:29:30 +02:00
|
|
|
Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface);
|
2024-04-12 01:17:50 +02:00
|
|
|
|
2024-04-25 01:05:19 +02:00
|
|
|
PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource.lock()->events.destroy.registerListener([this, PINHIBIT](std::any data) {
|
|
|
|
std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; });
|
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
});
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-05-05 00:46:10 +02:00
|
|
|
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; }); });
|
|
|
|
|
2022-07-06 15:42:37 +02:00
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::recheckIdleInhibitorStatus() {
|
|
|
|
|
2024-04-21 17:29:30 +02:00
|
|
|
for (auto& ii : m_vIdleInhibitors) {
|
2024-05-05 00:46:10 +02:00
|
|
|
if (ii->inert)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto WLSurface = CWLSurface::surfaceFromWlr(ii->inhibitor->surface);
|
|
|
|
|
|
|
|
if (!WLSurface)
|
2024-04-29 18:42:07 +02:00
|
|
|
continue;
|
|
|
|
|
2024-05-05 00:46:10 +02:00
|
|
|
if (WLSurface->visible()) {
|
2024-04-29 18:42:07 +02:00
|
|
|
PROTO::idle->setInhibit(true);
|
2022-07-06 15:42:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 13:26:07 +01:00
|
|
|
// check manual user-set inhibitors
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
|
|
|
if (w->m_eIdleInhibitMode == IDLEINHIBIT_NONE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (w->m_eIdleInhibitMode == IDLEINHIBIT_ALWAYS) {
|
2024-04-29 18:42:07 +02:00
|
|
|
PROTO::idle->setInhibit(true);
|
2022-10-31 13:26:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w)) {
|
2024-04-29 18:42:07 +02:00
|
|
|
PROTO::idle->setInhibit(true);
|
2022-10-31 13:26:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-03 11:09:42 +02:00
|
|
|
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->m_pWorkspace)) {
|
2024-04-29 18:42:07 +02:00
|
|
|
PROTO::idle->setInhibit(true);
|
2022-10-31 13:26:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-29 18:42:07 +02:00
|
|
|
PROTO::idle->setInhibit(false);
|
2022-07-06 15:42:37 +02:00
|
|
|
return;
|
2024-04-25 01:05:19 +02:00
|
|
|
}
|