1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

CEventLoop: Allow manually driving the event loop

Move the bulk of exec() into a new pump(). Since SDL wants to drive the
event loop itself, this is a requirement. We also add a WaitMode flag to
allow for immediately pumping events -- again, this is required because
SDL wants to be in full control of the event loop, and not let us wait.
This commit is contained in:
Robin Burchell 2019-05-18 13:39:21 +02:00 committed by Andreas Kling
parent 85d2e85912
commit d791bce6af
2 changed files with 72 additions and 50 deletions

View file

@ -20,6 +20,15 @@ public:
int exec();
enum class WaitMode {
WaitForEvents,
PollForEvents,
};
// processe events, generally called by exec() in a loop.
// this should really only be used for integrating with other event loops
void pump(WaitMode = WaitMode::WaitForEvents);
void post_event(CObject& receiver, OwnPtr<CEvent>&&);
static CEventLoop& main();
@ -46,13 +55,14 @@ protected:
virtual void do_processing() { }
private:
void wait_for_event();
void wait_for_event(WaitMode);
void get_next_timer_expiration(timeval&);
struct QueuedEvent {
WeakPtr<CObject> receiver;
OwnPtr<CEvent> event;
};
Vector<QueuedEvent, 64> m_queued_events;
bool m_running { false };