summaryrefslogtreecommitdiff
path: root/src/managers/input/IdleInhibitor.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-04-21 16:29:30 +0100
committerVaxry <vaxry@vaxry.net>2024-04-21 16:54:52 +0100
commitd9fe1d0f58bcafd22ee23097de41e7039a36afe2 (patch)
tree4804487f925b796defc244991bf34ad8a07b3e7e /src/managers/input/IdleInhibitor.cpp
parente823b5d6930af15c1a9c1d76682e8e7be4a0eeb6 (diff)
idle-inhibit: move to new impl
Diffstat (limited to 'src/managers/input/IdleInhibitor.cpp')
-rw-r--r--src/managers/input/IdleInhibitor.cpp60
1 files changed, 19 insertions, 41 deletions
diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp
index 72f60702..21f1652f 100644
--- a/src/managers/input/IdleInhibitor.cpp
+++ b/src/managers/input/IdleInhibitor.cpp
@@ -1,61 +1,39 @@
#include "InputManager.hpp"
#include "../../Compositor.hpp"
+#include "../../protocols/IdleInhibit.hpp"
-void Events::listener_newIdleInhibitor(wl_listener* listener, void* data) {
- const auto WLRIDLEINHIBITOR = (wlr_idle_inhibitor_v1*)data;
+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);
- if (!WLRIDLEINHIBITOR)
- return;
-
- g_pInputManager->newIdleInhibitor(WLRIDLEINHIBITOR);
-}
-
-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();
-}
+ Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface);
-void CInputManager::newIdleInhibitor(wlr_idle_inhibitor_v1* pInhibitor) {
- const auto PINHIBIT = &m_lIdleInhibitors.emplace_back();
+ 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; }); });
- Debug::log(LOG, "New idle inhibitor registered");
+ const auto PWINDOW = g_pCompositor->getWindowFromSurface(PINHIBIT->inhibitor->surface);
- PINHIBIT->pWlrInhibitor = pInhibitor;
+ if (!PWINDOW) {
+ Debug::log(WARN, "Inhibitor is for no window?");
+ return;
+ }
- PINHIBIT->onWindowDestroy = g_pHookSystem->hookDynamic("closeWindow", [PINHIBIT](void* self, SCallbackInfo& info, std::any data) {
- if (PINHIBIT->pWindow == std::any_cast<CWindow*>(data))
- destroyInhibitor(PINHIBIT);
+ 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;
});
- PINHIBIT->hyprListener_Destroy.initCallback(
- &pInhibitor->events.destroy,
- [](void* owner, void* data) {
- const auto PINH = (SIdleInhibitor*)owner;
-
- destroyInhibitor(PINH);
- },
- PINHIBIT, "IdleInhibitor");
-
- PINHIBIT->pWindow = g_pCompositor->getWindowFromSurface(pInhibitor->surface);
-
- if (PINHIBIT->pWindow)
- Debug::log(LOG, "IdleInhibitor got window {}", PINHIBIT->pWindow);
-
recheckIdleInhibitorStatus();
}
void CInputManager::recheckIdleInhibitorStatus() {
- for (auto& ii : m_lIdleInhibitors) {
- if (!ii.pWindow) {
+ for (auto& ii : m_vIdleInhibitors) {
+ if (!ii->pWindow) {
g_pCompositor->setIdleActivityInhibit(false);
return;
- } else if (g_pHyprRenderer->shouldRenderWindow(ii.pWindow)) {
+ } else if (g_pHyprRenderer->shouldRenderWindow(ii->pWindow)) {
g_pCompositor->setIdleActivityInhibit(false);
return;
}