#pragma once #include #include #include #include #include #include "wayland.hpp" #include "ext-idle-notify-v1.hpp" #include "hyprland-lock-notify-v1.hpp" #include "../defines.hpp" class CHypridle { public: CHypridle(); struct SIdleListener { SP notification = nullptr; std::string onTimeout = ""; std::string onRestore = ""; }; struct SDbusInhibitCookie { uint32_t cookie = 0; std::string app, reason, ownerID; }; void run(); void onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version); void onGlobalRemoved(void* data, struct wl_registry* registry, uint32_t name); void onIdled(SIdleListener*); void onResumed(SIdleListener*); void onInhibit(bool lock); void onLocked(); void onUnlocked(); SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie); void registerDbusInhibitCookie(SDbusInhibitCookie& cookie); bool unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie); bool unregisterDbusInhibitCookies(const std::string& ownerID); void handleInhibitOnDbusSleep(bool toSleep); void inhibitSleep(); void uninhibitSleep(); private: void setupDBUS(); void enterEventLoop(); bool m_bTerminate = false; bool isIdled = false; bool m_isLocked = false; int64_t m_iInhibitLocks = 0; enum { SLEEP_INHIBIT_NONE, SLEEP_INHIBIT_NORMAL, SLEEP_INHIBIT_LOCK_NOTIFY, } m_inhibitSleepBehavior; struct { wl_display* display = nullptr; SP registry = nullptr; SP seat = nullptr; SP lockNotifier = nullptr; SP lockNotification = nullptr; } m_sWaylandState; struct { SP notifier = nullptr; std::vector listeners; } m_sWaylandIdleState; struct { std::unique_ptr connection; std::unique_ptr screenSaverServiceConnection; std::unique_ptr login; std::vector> screenSaverObjects; std::vector inhibitCookies; Hyprutils::OS::CFileDescriptor sleepInhibitFd; } m_sDBUSState; struct { std::condition_variable loopSignal; std::mutex loopMutex; std::atomic shouldProcess = false; std::mutex loopRequestMutex; std::mutex eventLock; } m_sEventLoopInternals; }; inline std::unique_ptr g_pHypridle;