2022-07-06 15:42:37 +02:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
#include "../../Compositor.hpp"
|
|
|
|
|
|
|
|
void Events::listener_newIdleInhibitor(wl_listener* listener, void* data) {
|
|
|
|
const auto WLRIDLEINHIBITOR = (wlr_idle_inhibitor_v1*)data;
|
|
|
|
|
|
|
|
if (!WLRIDLEINHIBITOR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_pInputManager->newIdleInhibitor(WLRIDLEINHIBITOR);
|
|
|
|
}
|
|
|
|
|
2024-04-12 01:17:50 +02:00
|
|
|
static void destroyInhibitor(SIdleInhibitor* inhibitor) {
|
|
|
|
g_pHookSystem->unhook(inhibitor->onWindowDestroy);
|
|
|
|
|
|
|
|
g_pInputManager->m_lIdleInhibitors.remove(*inhibitor);
|
|
|
|
|
|
|
|
Debug::log(LOG, "Destroyed an idleinhibitor");
|
|
|
|
|
|
|
|
g_pInputManager->recheckIdleInhibitorStatus();
|
|
|
|
}
|
|
|
|
|
2022-07-06 15:42:37 +02:00
|
|
|
void CInputManager::newIdleInhibitor(wlr_idle_inhibitor_v1* pInhibitor) {
|
|
|
|
const auto PINHIBIT = &m_lIdleInhibitors.emplace_back();
|
|
|
|
|
|
|
|
Debug::log(LOG, "New idle inhibitor registered");
|
|
|
|
|
|
|
|
PINHIBIT->pWlrInhibitor = pInhibitor;
|
|
|
|
|
2024-04-12 01:17:50 +02:00
|
|
|
PINHIBIT->onWindowDestroy = g_pHookSystem->hookDynamic("closeWindow", [PINHIBIT](void* self, SCallbackInfo& info, std::any data) {
|
|
|
|
if (PINHIBIT->pWindow == std::any_cast<CWindow*>(data))
|
|
|
|
destroyInhibitor(PINHIBIT);
|
|
|
|
});
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
PINHIBIT->hyprListener_Destroy.initCallback(
|
|
|
|
&pInhibitor->events.destroy,
|
|
|
|
[](void* owner, void* data) {
|
|
|
|
const auto PINH = (SIdleInhibitor*)owner;
|
2022-07-06 15:42:37 +02:00
|
|
|
|
2024-04-12 01:17:50 +02:00
|
|
|
destroyInhibitor(PINH);
|
2022-12-16 18:17:31 +01:00
|
|
|
},
|
|
|
|
PINHIBIT, "IdleInhibitor");
|
2022-07-06 15:42:37 +02:00
|
|
|
|
|
|
|
PINHIBIT->pWindow = g_pCompositor->getWindowFromSurface(pInhibitor->surface);
|
|
|
|
|
|
|
|
if (PINHIBIT->pWindow)
|
2023-09-20 17:25:03 +02:00
|
|
|
Debug::log(LOG, "IdleInhibitor got window {}", PINHIBIT->pWindow);
|
2022-07-06 15:42:37 +02:00
|
|
|
|
|
|
|
recheckIdleInhibitorStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::recheckIdleInhibitorStatus() {
|
|
|
|
|
|
|
|
for (auto& ii : m_lIdleInhibitors) {
|
|
|
|
if (!ii.pWindow) {
|
2023-07-13 18:05:34 +02:00
|
|
|
g_pCompositor->setIdleActivityInhibit(false);
|
2022-07-06 15:42:37 +02:00
|
|
|
return;
|
|
|
|
} 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;
|
|
|
|
}
|