From 478ceb71ec2774726610dd42c51289be8feba520 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 28 Apr 2024 10:48:29 -0400 Subject: [PATCH] Ladybird/AppKit: Ensure LibCore events are processed When we receive a LibCore event, we post an "application defined" Cocoa event to the NSApp. However, we are currently only processing these from `pump`, which is only invoked manually. Instead, we should listen for the event that we've posted and process the event queue at that time. This is much closer to how Qt's event loop behaves as well with EventLoopImplementationQtEventTarget. --- Ladybird/AppKit/Application/Application.mm | 10 ++++++++++ Ladybird/AppKit/Application/EventLoopImplementation.mm | 6 +----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Ladybird/AppKit/Application/Application.mm b/Ladybird/AppKit/Application/Application.mm index ea0a5428bd0..c6711cdd14b 100644 --- a/Ladybird/AppKit/Application/Application.mm +++ b/Ladybird/AppKit/Application/Application.mm @@ -7,6 +7,7 @@ #include #include #include +#include #include #import @@ -62,4 +63,13 @@ Core::EventLoop::current().quit(0); } +- (void)sendEvent:(NSEvent*)event +{ + if ([event type] == NSEventTypeApplicationDefined) { + Core::ThreadEventQueue::current().process(); + } else { + [super sendEvent:event]; + } +} + @end diff --git a/Ladybird/AppKit/Application/EventLoopImplementation.mm b/Ladybird/AppKit/Application/EventLoopImplementation.mm index feb61662cf5..0031e037ced 100644 --- a/Ladybird/AppKit/Application/EventLoopImplementation.mm +++ b/Ladybird/AppKit/Application/EventLoopImplementation.mm @@ -177,11 +177,7 @@ size_t CFEventLoopImplementation::pump(PumpMode mode) dequeue:YES]; while (event) { - if (event.type == NSEventTypeApplicationDefined) { - m_thread_event_queue.process(); - } else { - [NSApp sendEvent:event]; - } + [NSApp sendEvent:event]; event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:nil