hypridle/src/core/Hypridle.hpp

100 lines
3.2 KiB
C++
Raw Normal View History

2024-02-17 19:30:11 +00:00
#pragma once
#include <memory>
#include <vector>
2024-02-17 22:13:06 +00:00
#include <sdbus-c++/sdbus-c++.h>
#include <hyprutils/os/FileDescriptor.hpp>
2024-02-22 11:33:19 +01:00
#include <condition_variable>
2024-02-17 19:30:11 +00:00
#include "wayland.hpp"
#include "ext-idle-notify-v1.hpp"
#include "hyprland-lock-notify-v1.hpp"
#include "../defines.hpp"
2024-02-17 19:30:11 +00:00
class CHypridle {
public:
CHypridle();
struct SIdleListener {
SP<CCExtIdleNotificationV1> notification = nullptr;
std::string onTimeout = "";
std::string onRestore = "";
2024-02-17 19:30:11 +00:00
};
2024-02-17 23:24:01 +00:00
struct SDbusInhibitCookie {
uint32_t cookie = 0;
std::string app, reason, ownerID;
2024-02-17 23:24:01 +00:00
};
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*);
2024-02-17 19:30:11 +00:00
2024-02-17 23:24:01 +00:00
void onInhibit(bool lock);
2024-02-17 19:30:11 +00:00
void onLocked();
void onUnlocked();
2024-02-17 23:24:01 +00:00
SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie);
void registerDbusInhibitCookie(SDbusInhibitCookie& cookie);
bool unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie);
bool unregisterDbusInhibitCookies(const std::string& ownerID);
2024-02-17 19:30:11 +00:00
void handleInhibitOnDbusSleep(bool toSleep);
void inhibitSleep();
void uninhibitSleep();
2024-02-17 19:30:11 +00:00
private:
2024-02-17 23:24:01 +00:00
void setupDBUS();
void enterEventLoop();
2024-02-17 22:13:06 +00:00
2024-02-17 23:24:01 +00:00
bool m_bTerminate = false;
bool isIdled = false;
bool m_isLocked = false;
2024-02-17 23:24:01 +00:00
int64_t m_iInhibitLocks = 0;
2024-02-17 22:13:06 +00:00
enum {
SLEEP_INHIBIT_NONE,
SLEEP_INHIBIT_NORMAL,
SLEEP_INHIBIT_LOCK_NOTIFY,
} m_inhibitSleepBehavior;
2024-02-17 19:30:11 +00:00
struct {
wl_display* display = nullptr;
SP<CCWlRegistry> registry = nullptr;
SP<CCWlSeat> seat = nullptr;
SP<CCHyprlandLockNotifierV1> lockNotifier = nullptr;
SP<CCHyprlandLockNotificationV1> lockNotification = nullptr;
2024-02-17 19:30:11 +00:00
} m_sWaylandState;
struct {
SP<CCExtIdleNotifierV1> notifier = nullptr;
2024-02-17 19:30:11 +00:00
std::vector<SIdleListener> listeners;
} m_sWaylandIdleState;
2024-02-17 22:13:06 +00:00
struct {
std::unique_ptr<sdbus::IConnection> connection;
std::unique_ptr<sdbus::IConnection> screenSaverServiceConnection;
std::unique_ptr<sdbus::IProxy> login;
std::vector<std::unique_ptr<sdbus::IObject>> screenSaverObjects;
std::vector<SDbusInhibitCookie> inhibitCookies;
Hyprutils::OS::CFileDescriptor sleepInhibitFd;
2024-02-17 22:13:06 +00:00
} m_sDBUSState;
struct {
std::condition_variable loopSignal;
std::mutex loopMutex;
std::atomic<bool> shouldProcess = false;
std::mutex loopRequestMutex;
std::mutex eventLock;
} m_sEventLoopInternals;
2024-02-17 19:30:11 +00:00
};
2024-02-17 22:13:06 +00:00
inline std::unique_ptr<CHypridle> g_pHypridle;