From b2b3abe0ebc0ca147e1a29d06d1872bc09bf16cc Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Wed, 1 Feb 2012 14:02:02 +0100 Subject: Remove duplicated function from QCocoaEventDispatcher The qt_mac_waitForMoreModalSessionEvents() is identical to qt_mac_waitForMoreEvents(), except that it passes a different inMode parameter to [NSApp nextEventMatchingMask]. Change the latter function to take the mode as a parameter itself, defaulting to the default mode. Change the dequeue parameter to [NSApp nextEventMatchingMask] from YES to NO. Having the function dequeue the event, and then immediately reposting the event is not necessary. Change-Id: Iba45d41ad3ff4d5721d1068e6d5c78585cb15810 Reviewed-by: Richard Moe Gustavsen --- .../platforms/cocoa/qcocoaeventdispatcher.mm | 30 +++++----------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 8e7b14069f..dbb8625aeb 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -488,32 +488,16 @@ static bool IsMouseOrKeyEvent( NSEvent* event ) return result; } -static inline void qt_mac_waitForMoreEvents() +static inline void qt_mac_waitForMoreEvents(NSString *runLoopMode = NSDefaultRunLoopMode) { // If no event exist in the cocoa event que, wait // (and free up cpu time) until at least one event occur. // This implementation is a bit on the edge, but seems to // work fine: - NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantFuture] - inMode:NSDefaultRunLoopMode - dequeue:YES]; - if (event) - [NSApp postEvent:event atStart:YES]; -} - -static inline void qt_mac_waitForMoreModalSessionEvents() -{ - // If no event exist in the cocoa event que, wait - // (and free up cpu time) until at least one event occur. - // This implementation is a bit on the edge, but seems to - // work fine: - NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantFuture] - inMode:NSModalPanelRunLoopMode - dequeue:YES]; - if (event) - [NSApp postEvent:event atStart:YES]; + [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantFuture] + inMode:runLoopMode + dequeue:NO]; } bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) @@ -568,7 +552,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) if (NSModalSession session = d->currentModalSession()) { QBoolBlocker execGuard(d->currentExecIsNSAppRun, false); while ([NSApp runModalSession:session] == NSRunContinuesResponse && !d->interrupt) - qt_mac_waitForMoreModalSessionEvents(); + qt_mac_waitForMoreEvents(NSModalPanelRunLoopMode); if (!d->interrupt && session == d->currentModalSessionCached) { // Someone called [NSApp stopModal:] from outside the event @@ -592,7 +576,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) // Since we can dispatch all kinds of events, we choose // to use cocoa's native way of running modal sessions: if (flags & QEventLoop::WaitForMoreEvents) - qt_mac_waitForMoreModalSessionEvents(); + qt_mac_waitForMoreEvents(NSModalPanelRunLoopMode); NSInteger status = [NSApp runModalSession:session]; if (status != NSRunContinuesResponse && session == d->currentModalSessionCached) { // INVARIANT: Someone called [NSApp stopModal:] from outside the event -- cgit v1.2.3