summaryrefslogtreecommitdiff
path: root/src/managers/input/IdleInhibitor.cpp
diff options
context:
space:
mode:
authorDarksome <dev@darkso.me>2022-07-15 19:42:03 +0300
committerDarksome <dev@darkso.me>2022-07-15 19:42:03 +0300
commit5388b54442614cb0d3d445f101e7cd86bf64c125 (patch)
tree26057ff185e423e944e8b250ed7fe26654b69623 /src/managers/input/IdleInhibitor.cpp
parentcb8a6f881b11e9a269fd5f7aa64eafe2beda0b0d (diff)
parent6306d4dae3fa221a6099e109c7faef60bac4fac5 (diff)
Merge upstream
Diffstat (limited to 'src/managers/input/IdleInhibitor.cpp')
-rw-r--r--src/managers/input/IdleInhibitor.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp
new file mode 100644
index 00000000..3efb40c6
--- /dev/null
+++ b/src/managers/input/IdleInhibitor.cpp
@@ -0,0 +1,54 @@
+#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);
+}
+
+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;
+
+ PINHIBIT->hyprListener_Destroy.initCallback(&pInhibitor->events.destroy, [](void* owner, void* data){
+
+ const auto PINH = (SIdleInhibitor*)owner;
+
+ g_pInputManager->m_lIdleInhibitors.remove(*PINH);
+
+ Debug::log(LOG, "Destroyed an idleinhibitor");
+
+ g_pInputManager->recheckIdleInhibitorStatus();
+
+ }, PINHIBIT, "IdleInhibitor");
+
+ PINHIBIT->pWindow = g_pCompositor->getWindowFromSurface(pInhibitor->surface);
+
+ if (PINHIBIT->pWindow)
+ Debug::log(LOG, "IdleInhibitor got window %x (%s)", PINHIBIT->pWindow, PINHIBIT->pWindow->m_szTitle.c_str());
+
+ recheckIdleInhibitorStatus();
+}
+
+void CInputManager::recheckIdleInhibitorStatus() {
+
+ for (auto& ii : m_lIdleInhibitors) {
+ if (!ii.pWindow) {
+ wlr_idle_set_enabled(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat, false);
+ return;
+ } else if (g_pHyprRenderer->shouldRenderWindow(ii.pWindow)) {
+ wlr_idle_set_enabled(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat, false);
+ return;
+ }
+ }
+
+ wlr_idle_set_enabled(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat, true);
+ return;
+} \ No newline at end of file