diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-01-06 00:55:48 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-06 11:30:04 +0100 |
commit | 558fd5b1661070caa08e0f3f1f00f661e7226001 (patch) | |
tree | 41b0003f7040956a3726f9ac3d511fc500e1759e /Userland/Libraries/LibCore/EventLoop.cpp | |
parent | fa902cd5d578b3b14556dcf9b86b43fde23c6338 (diff) | |
download | serenity-558fd5b1661070caa08e0f3f1f00f661e7226001.zip |
LibCore: Make `EventLoop::pump()` return event count
Sometimes, pumping the event loop will cause new events to be
generated. For example, an IPC message could be delivered which then
dispatches a new event to be handled by the GUI. To the invoker of
`EventLoop::pump()`, it is not obvious if any events were processed at
all.
Libraries like SDL2 might not have the opportunity to run the event
loop often enough that events can be processed swiftly, since it might
spend time doing other things. This can result in stuttering GUI
interactions.
This changes `EventLoop::pump()` to return the number of processed
events. This functionality will be used by our SDL2 port in another PR.
Diffstat (limited to 'Userland/Libraries/LibCore/EventLoop.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/EventLoop.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index 7859a9429d..40b5608747 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -379,7 +379,7 @@ void EventLoop::spin_until(Function<bool()> goal_condition) pump(); } -void EventLoop::pump(WaitMode mode) +size_t EventLoop::pump(WaitMode mode) { wait_for_event(mode); @@ -389,6 +389,7 @@ void EventLoop::pump(WaitMode mode) events = move(m_queued_events); } + size_t processed_events = 0; for (size_t i = 0; i < events.size(); ++i) { auto& queued_event = events.at(i); auto receiver = queued_event.receiver.strong_ref(); @@ -400,7 +401,6 @@ void EventLoop::pump(WaitMode mode) switch (event.type()) { case Event::Quit: VERIFY_NOT_REACHED(); - return; default: dbgln_if(EVENTLOOP_DEBUG, "Event type {} with no receiver :(", event.type()); break; @@ -412,6 +412,7 @@ void EventLoop::pump(WaitMode mode) NonnullRefPtr<Object> protector(*receiver); receiver->dispatch_event(event); } + ++processed_events; if (m_exit_requested) { Threading::MutexLocker locker(m_private->lock); @@ -422,9 +423,11 @@ void EventLoop::pump(WaitMode mode) new_event_queue.unchecked_append(move(events[i])); new_event_queue.extend(move(m_queued_events)); m_queued_events = move(new_event_queue); - return; + break; } } + + return processed_events; } void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event) |