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>
|
2025-02-27 23:16:45 +00:00
|
|
|
#include <hyprutils/os/FileDescriptor.hpp>
|
2024-02-22 11:33:19 +01:00
|
|
|
#include <condition_variable>
|
2024-02-17 19:30:11 +00:00
|
|
|
|
2025-01-27 13:24:13 +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 {
|
2025-01-27 13:24:13 +00:00
|
|
|
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;
|
2024-10-20 23:04:37 +01:00
|
|
|
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
|
|
|
|
2025-01-27 13:24:13 +00:00
|
|
|
void onLocked();
|
|
|
|
|
void onUnlocked();
|
|
|
|
|
|
2024-02-17 23:24:01 +00:00
|
|
|
SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie);
|
|
|
|
|
void registerDbusInhibitCookie(SDbusInhibitCookie& cookie);
|
2024-10-20 23:04:37 +01:00
|
|
|
bool unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie);
|
|
|
|
|
bool unregisterDbusInhibitCookies(const std::string& ownerID);
|
2024-02-17 19:30:11 +00:00
|
|
|
|
2025-01-27 13:24:13 +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;
|
2024-02-27 22:22:15 +01:00
|
|
|
bool isIdled = false;
|
2025-01-27 13:24:13 +00:00
|
|
|
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
|
|
|
|
2025-01-27 13:24:13 +00:00
|
|
|
enum {
|
|
|
|
|
SLEEP_INHIBIT_NONE,
|
|
|
|
|
SLEEP_INHIBIT_NORMAL,
|
|
|
|
|
SLEEP_INHIBIT_LOCK_NOTIFY,
|
|
|
|
|
} m_inhibitSleepBehavior;
|
|
|
|
|
|
2024-02-17 19:30:11 +00:00
|
|
|
struct {
|
2025-01-27 13:24:13 +00:00
|
|
|
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 {
|
2025-01-27 13:24:13 +00:00
|
|
|
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 {
|
2024-05-14 17:10:16 +02:00
|
|
|
std::unique_ptr<sdbus::IConnection> connection;
|
|
|
|
|
std::unique_ptr<sdbus::IConnection> screenSaverServiceConnection;
|
2025-01-27 13:24:13 +00:00
|
|
|
std::unique_ptr<sdbus::IProxy> login;
|
2024-05-14 17:10:16 +02:00
|
|
|
std::vector<std::unique_ptr<sdbus::IObject>> screenSaverObjects;
|
|
|
|
|
std::vector<SDbusInhibitCookie> inhibitCookies;
|
2025-02-27 23:16:45 +00:00
|
|
|
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;
|