2024-04-07 03:31:51 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <condition_variable>
|
2025-01-23 13:08:19 +02:00
|
|
|
#include <map>
|
2024-04-07 03:31:51 +01:00
|
|
|
#include <mutex>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <wayland-server.h>
|
2025-01-23 13:08:19 +02:00
|
|
|
#include "helpers/signal/Signal.hpp"
|
2024-04-07 03:31:51 +01:00
|
|
|
|
|
|
|
|
#include "EventLoopTimer.hpp"
|
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
namespace Aquamarine {
|
|
|
|
|
struct SPollFD;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-07 03:31:51 +01:00
|
|
|
class CEventLoopManager {
|
|
|
|
|
public:
|
2024-07-05 23:05:03 +02:00
|
|
|
CEventLoopManager(wl_display* display, wl_event_loop* wlEventLoop);
|
2024-06-02 18:42:54 +02:00
|
|
|
~CEventLoopManager();
|
2024-04-08 15:33:02 +01:00
|
|
|
|
2024-07-05 23:05:03 +02:00
|
|
|
void enterLoop();
|
2024-05-07 13:30:31 +01:00
|
|
|
|
|
|
|
|
// Note: will remove the timer if the ptr is lost.
|
2024-05-05 17:16:00 +01:00
|
|
|
void addTimer(SP<CEventLoopTimer> timer);
|
|
|
|
|
void removeTimer(SP<CEventLoopTimer> timer);
|
2024-04-07 03:31:51 +01:00
|
|
|
|
2024-04-07 21:55:14 +01:00
|
|
|
void onTimerFire();
|
|
|
|
|
|
2024-04-07 03:31:51 +01:00
|
|
|
// recalculates timers
|
|
|
|
|
void nudgeTimers();
|
|
|
|
|
|
2024-07-05 23:05:03 +02:00
|
|
|
// schedules a function to run later, aka in a wayland idle event.
|
|
|
|
|
void doLater(const std::function<void()>& fn);
|
|
|
|
|
|
|
|
|
|
struct SIdleData {
|
|
|
|
|
wl_event_source* eventSource = nullptr;
|
|
|
|
|
std::vector<std::function<void()>> fns;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-07 03:31:51 +01:00
|
|
|
private:
|
2025-01-23 13:08:19 +02:00
|
|
|
// Manages the event sources after AQ pollFDs change.
|
|
|
|
|
void syncPollFDs();
|
|
|
|
|
|
|
|
|
|
struct SEventSourceData {
|
|
|
|
|
SP<Aquamarine::SPollFD> pollFD;
|
|
|
|
|
wl_event_source* eventSource = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-07 03:31:51 +01:00
|
|
|
struct {
|
2025-01-23 13:08:19 +02:00
|
|
|
wl_event_loop* loop = nullptr;
|
|
|
|
|
wl_display* display = nullptr;
|
|
|
|
|
wl_event_source* eventSource = nullptr;
|
2024-04-07 03:31:51 +01:00
|
|
|
} m_sWayland;
|
|
|
|
|
|
|
|
|
|
struct {
|
2024-05-05 17:16:00 +01:00
|
|
|
std::vector<SP<CEventLoopTimer>> timers;
|
|
|
|
|
int timerfd = -1;
|
2024-04-07 03:31:51 +01:00
|
|
|
} m_sTimers;
|
2024-07-05 23:05:03 +02:00
|
|
|
|
2025-01-23 13:08:19 +02:00
|
|
|
SIdleData m_sIdle;
|
|
|
|
|
std::map<int, SEventSourceData> aqEventSources;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
CHyprSignalListener pollFDsChanged;
|
|
|
|
|
} m_sListeners;
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2025-01-23 13:08:19 +02:00
|
|
|
wl_event_source* m_configWatcherInotifySource = nullptr;
|
2025-01-19 15:39:19 +01:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
friend class CSyncTimeline;
|
2024-04-07 03:31:51 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-23 21:55:41 +01:00
|
|
|
inline UP<CEventLoopManager> g_pEventLoopManager;
|