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 <richard.gustavsen@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-02-01 14:02:02 +01:00 committed by Qt by Nokia
parent 8fad23f326
commit b2b3abe0eb

View 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