From d115196010efb4ac55be998ffe7ed00db0cbffaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 5 Sep 2018 17:21:24 +0200 Subject: macOS: Use single call site for timer processing in event dispatcher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes it easier to add shared logic later on. The call to maybeCancelWaitForMoreEvents() has been left out as it was not called from all call sites. Change-Id: Ibcb10ab4d788de80850b0e5a4286b4d49091cddb Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.h | 1 + src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 6d62447f33..ebf33cf4e2 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -153,6 +153,7 @@ public: void maybeStopCFRunLoopTimer(); static void runLoopTimerCallback(CFRunLoopTimerRef, void *info); static void activateTimersSourceCallback(void *info); + bool processTimers(); // Set 'blockSendPostedEvents' to true if you _really_ need // to make sure that qt events are not posted while calling diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 2a41498564..b0f2b6d940 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -120,11 +120,17 @@ void QCocoaEventDispatcherPrivate::runLoopTimerCallback(CFRunLoopTimerRef, void void QCocoaEventDispatcherPrivate::activateTimersSourceCallback(void *info) { QCocoaEventDispatcherPrivate *d = static_cast(info); - (void) d->timerInfoList.activateTimers(); - d->maybeStartCFRunLoopTimer(); + d->processTimers(); d->maybeCancelWaitForMoreEvents(); } +bool QCocoaEventDispatcherPrivate::processTimers() +{ + int activated = timerInfoList.activateTimers(); + maybeStartCFRunLoopTimer(); + return activated > 0; +} + void QCocoaEventDispatcherPrivate::maybeStartCFRunLoopTimer() { if (timerInfoList.isEmpty()) { @@ -500,10 +506,9 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) } while (!d->interrupt && event); if ((d->processEventsFlags & QEventLoop::EventLoopExec) == 0) { - // when called "manually", always send posted events and timers + // When called "manually", always process posted events and timers d->processPostedEvents(); - retVal = d->timerInfoList.activateTimers() > 0 || retVal; - d->maybeStartCFRunLoopTimer(); + retVal = d->processTimers() || retVal; } // be sure to return true if the posted event source fired -- cgit v1.2.3