Hyprland/src/managers/input/IdleInhibitor.cpp

75 lines
2.5 KiB
C++
Raw Normal View History

#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"
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<SP<CIdleInhibitor>>(inhibitor);
2024-04-21 17:29:30 +02:00
Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface);
PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource->events.destroy.registerListener([this, PINHIBIT](std::any data) {
std::erase_if(m_vIdleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; });
recheckIdleInhibitorStatus();
});
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. Assuming it's visible.");
PINHIBIT->nonDesktop = 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() {
2024-04-21 17:29:30 +02:00
for (auto& ii : m_vIdleInhibitors) {
if (ii->nonDesktop) {
PROTO::idle->setInhibit(true);
return;
}
auto WLSurface = CWLSurface::surfaceFromWlr(ii->inhibitor->surface);
if (!WLSurface)
2024-04-29 18:42:07 +02:00
continue;
if (WLSurface->visible()) {
2024-04-29 18:42:07 +02:00
PROTO::idle->setInhibit(true);
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;
}
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);
return;
}