From 58d10c0bd7cff2009edf6183c660b2e149eb9a82 Mon Sep 17 00:00:00 2001 From: Morten Sorvig Date: Thu, 23 Jun 2011 09:05:34 +0200 Subject: [PATCH] Refactor window system event dispatching. Add QWindowSystemInterface::sendWindowSystemEvents, which contains the canonical "empty and send queued window system events" implementation. Make the Cocoa, QPA, and GLIB dispatchers use the new implementation. Cocoa now no longer inherits from QPA. --- src/gui/kernel/qwindowsysteminterface_qpa.cpp | 33 +++++++++++++++++ src/gui/kernel/qwindowsysteminterface_qpa.h | 5 +++ .../eventdispatchers/qeventdispatcher_glib.cpp | 18 +--------- .../eventdispatchers/qeventdispatcher_qpa.cpp | 41 ++++------------------ .../platforms/cocoa/qcocoaeventdispatcher.h | 6 ++-- .../platforms/cocoa/qcocoaeventdispatcher.mm | 6 ++-- 6 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index 9df8b1a..6b2b2d5 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -270,4 +270,37 @@ void QWindowSystemInterface::handleExposeEvent(QWindow *tlw, const QRegion ®i QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } +bool QWindowSystemInterface::sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags) +{ + int nevents = 0; + + // handle gui and posted events + QCoreApplication::sendPostedEvents(); + + while (true) { + QWindowSystemInterfacePrivate::WindowSystemEvent *event; + if (!(flags & QEventLoop::ExcludeUserInputEvents) + && QWindowSystemInterfacePrivate::windowSystemEventsQueued() > 0) { + // process a pending user input event + event = QWindowSystemInterfacePrivate::getWindowSystemEvent(); + if (!event) + break; + } else { + break; + } + + if (eventDispatcher->filterEvent(event)) { + delete event; + continue; + } + + nevents++; + + QGuiApplicationPrivate::processWindowSystemEvent(event); + delete event; + } + + return (nevents > 0); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 1188ca3..17d8f83 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -44,10 +44,12 @@ #include #include #include +#include #include #include #include #include +#include QT_BEGIN_HEADER @@ -105,6 +107,9 @@ public: static void handleScreenGeometryChange(int screenIndex); static void handleScreenAvailableGeometryChange(int screenIndex); static void handleScreenCountChange(int count); + + // For event dispatcher implementations + static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags); }; QT_END_NAMESPACE diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp b/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp index 39b14e3..3d28ea2 100644 --- a/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp +++ b/src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp @@ -74,26 +74,10 @@ static gboolean userEventSourceCheck(GSource *source) static gboolean userEventSourceDispatch(GSource *s, GSourceFunc, gpointer) { GUserEventSource * source = reinterpret_cast(s); - - QWindowSystemInterfacePrivate::WindowSystemEvent * event; - while (QWindowSystemInterfacePrivate::windowSystemEventsQueued()) { - event = QWindowSystemInterfacePrivate::getWindowSystemEvent(); - if (!event) - break; - - // send through event filter - if (source->q->filterEvent(event)) { - delete event; - continue; - } - QGuiApplicationPrivate::processWindowSystemEvent(event); - delete event; - } - + QWindowSystemInterface::sendWindowSystemEvents(source->q, flags); return true; } - static GSourceFuncs userEventSourceFuncs = { userEventSourcePrepare, userEventSourceCheck, diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp b/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp index e6bd4c7..db20797 100644 --- a/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp +++ b/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp @@ -83,43 +83,14 @@ bool QEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherQPA); - int nevents = 0; - - // handle gui and posted events - d->interrupt = false; - QCoreApplication::sendPostedEvents(); - - while (!d->interrupt) { // also flushes output buffer ###can be optimized - QWindowSystemInterfacePrivate::WindowSystemEvent *event; - if (!(flags & QEventLoop::ExcludeUserInputEvents) - && QWindowSystemInterfacePrivate::windowSystemEventsQueued() > 0) { - // process a pending user input event - event = QWindowSystemInterfacePrivate::getWindowSystemEvent(); - if (!event) - break; - } else { - break; - } - - if (filterEvent(event)) { - delete event; - continue; - } - nevents++; - - QGuiApplicationPrivate::processWindowSystemEvent(event); - delete event; - } + bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(this, flags); -#ifdef Q_OS_MAC // (inverted inheritance on mac: QEventDispatcherMac calls QEventDispatcherQPA) - if (!d->interrupt) { - if (EVENTDISPATCHERBASE::processEvents(flags)) { - EVENTDISPATCHERBASE::processEvents(flags); - return true; - } + if (EVENTDISPATCHERBASE::processEvents(flags)) { + EVENTDISPATCHERBASE::processEvents(flags); + return true; } -#endif - return (nevents > 0); + + return didSendEvents; } bool QEventDispatcherQPA::hasPendingEvents() diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 2567700..2085a43 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -90,7 +90,7 @@ #include #include #include -#include +#include #include @@ -115,7 +115,7 @@ public: }; class QCocoaEventDispatcherPrivate; -class QCocoaEventDispatcher : public QEventDispatcherQPA +class QCocoaEventDispatcher : public QEventDispatcherUNIX { Q_OBJECT Q_DECLARE_PRIVATE(QCocoaEventDispatcher) @@ -167,7 +167,7 @@ struct MacSocketInfo { }; typedef QHash MacSocketHash; -class QCocoaEventDispatcherPrivate : public QEventDispatcherQPAPrivate +class QCocoaEventDispatcherPrivate : public QEventDispatcherUNIXPrivate { Q_DECLARE_PUBLIC(QCocoaEventDispatcher) diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index b5cbc83..cfb6995 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -910,7 +910,7 @@ QCocoaEventDispatcherPrivate::QCocoaEventDispatcherPrivate() } QCocoaEventDispatcher::QCocoaEventDispatcher(QObject *parent) - : QEventDispatcherQPA(*new QCocoaEventDispatcherPrivate, parent) + : QEventDispatcherUNIX(*new QCocoaEventDispatcherPrivate, parent) { Q_D(QCocoaEventDispatcher); CFRunLoopSourceContext context; @@ -992,9 +992,7 @@ void processPostedEvents(QCocoaEventDispatcherPrivate *const d, const bool block if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) { d->lastSerial = d->serialNumber; - // Call down to the base class event handler, which will send - // the window system events. - d->q_func()->QEventDispatcherQPA::processEvents(QEventLoop::AllEvents); + QWindowSystemInterface::sendWindowSystemEvents(d->q_func(), QEventLoop::AllEvents); } } -- 2.7.4