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"
|
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-04-21 17:29:30 +02:00
|
|
|
const auto PWINDOW = g_pCompositor->getWindowFromSurface(PINHIBIT->inhibitor->surface);
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-04-25 01:05:19 +02:00
|
|
|
if (PWINDOW) {
|
|
|
|
PINHIBIT->pWindow = PWINDOW;
|
|
|
|
PINHIBIT->windowDestroyListener = PWINDOW->events.destroy.registerListener([PINHIBIT](std::any data) {
|
|
|
|
Debug::log(WARN, "Inhibitor got its window destroyed before its inhibitor resource.");
|
|
|
|
PINHIBIT->pWindow = nullptr;
|
|
|
|
});
|
|
|
|
} else
|
2024-04-21 17:29:30 +02:00
|
|
|
Debug::log(WARN, "Inhibitor is for no window?");
|
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) {
|
|
|
|
if (!ii->pWindow) {
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(false);
|
2022-07-06 15:42:37 +02:00
|
|
|
return;
|
2024-04-21 17:29:30 +02:00
|
|
|
} else if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow)) {
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(false);
|
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) {
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(false);
|
2022-10-31 13:26:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FOCUS && g_pCompositor->isWindowActive(w.get())) {
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(false);
|
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)) {
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(false);
|
2022-10-31 13:26:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(true);
|
2022-07-06 15:42:37 +02:00
|
|
|
return;
|
2024-04-25 01:05:19 +02:00
|
|
|
}
|