Remove duplicated function from QCocoaEventDispatcher
authorBradley T. Hughes <bradley.hughes@nokia.com>
Wed, 1 Feb 2012 13:02:02 +0000 (14:02 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 2 Feb 2012 08:27:25 +0000 (09:27 +0100)
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 <richard.gustavsen@nokia.com>
src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm

index 8e7b140..dbb8625 100644 (file)
@@ -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