2024-04-07 04:31:51 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
#include "EventLoopTimer.hpp"
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
namespace Aquamarine {
|
|
|
|
struct SPollFD;
|
|
|
|
};
|
|
|
|
|
2024-04-07 04:31:51 +02: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 16:33:02 +02:00
|
|
|
|
2024-07-05 23:05:03 +02:00
|
|
|
void enterLoop();
|
2024-05-07 14:30:31 +02:00
|
|
|
|
|
|
|
// Note: will remove the timer if the ptr is lost.
|
2024-05-05 18:16:00 +02:00
|
|
|
void addTimer(SP<CEventLoopTimer> timer);
|
|
|
|
void removeTimer(SP<CEventLoopTimer> timer);
|
2024-04-07 04:31:51 +02:00
|
|
|
|
2024-04-07 22:55:14 +02:00
|
|
|
void onTimerFire();
|
|
|
|
|
2024-04-07 04:31:51 +02: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 04:31:51 +02:00
|
|
|
private:
|
|
|
|
struct {
|
2024-07-21 13:09:54 +02:00
|
|
|
wl_event_loop* loop = nullptr;
|
|
|
|
wl_display* display = nullptr;
|
|
|
|
wl_event_source* eventSource = nullptr;
|
|
|
|
std::vector<wl_event_source*> aqEventSources;
|
2024-04-07 04:31:51 +02:00
|
|
|
} m_sWayland;
|
|
|
|
|
|
|
|
struct {
|
2024-05-05 18:16:00 +02:00
|
|
|
std::vector<SP<CEventLoopTimer>> timers;
|
|
|
|
int timerfd = -1;
|
2024-04-07 04:31:51 +02:00
|
|
|
} m_sTimers;
|
2024-07-05 23:05:03 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SIdleData m_sIdle;
|
|
|
|
std::vector<SP<Aquamarine::SPollFD>> aqPollFDs;
|
|
|
|
|
|
|
|
friend class CSyncTimeline;
|
2024-04-07 04:31:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::unique_ptr<CEventLoopManager> g_pEventLoopManager;
|