Refactor window system event dispatching.
authorMorten Sorvig <morten.sorvig@nokia.com>
Thu, 23 Jun 2011 07:05:34 +0000 (09:05 +0200)
committerMorten Sorvig <morten.sorvig@nokia.com>
Thu, 23 Jun 2011 09:04:21 +0000 (11:04 +0200)
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
src/gui/kernel/qwindowsysteminterface_qpa.h
src/platformsupport/eventdispatchers/qeventdispatcher_glib.cpp
src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp
src/plugins/platforms/cocoa/qcocoaeventdispatcher.h
src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm

index 9df8b1a..6b2b2d5 100644 (file)
@@ -270,4 +270,37 @@ void QWindowSystemInterface::handleExposeEvent(QWindow *tlw, const QRegion &regi
     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
index 1188ca3..17d8f83 100644 (file)
 #include <QtCore/QTime>
 #include <QtGui/qwindowdefs.h>
 #include <QtCore/QEvent>
+#include <QtCore/QAbstractEventDispatcher>
 #include <QtGui/QWindow>
 #include <QtCore/QWeakPointer>
 #include <QtCore/QMutex>
 #include <QtGui/QTouchEvent>
+#include <QtCore/QEventLoop>
 
 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
index 39b14e3..3d28ea2 100644 (file)
@@ -74,26 +74,10 @@ static gboolean userEventSourceCheck(GSource *source)
 static gboolean userEventSourceDispatch(GSource *s, GSourceFunc, gpointer)
 {
     GUserEventSource * source = reinterpret_cast<GUserEventSource *>(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,
index e6bd4c7..db20797 100644 (file)
@@ -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()
index 2567700..2085a43 100644 (file)
@@ -90,7 +90,7 @@
 #include <QtCore/qhash.h>
 #include <QtCore/qstack.h>
 #include <QtGui/qwindowdefs.h>
-#include <QtPlatformSupport/private/qeventdispatcher_qpa_p.h>
+#include <QtCore/private/qeventdispatcher_unix_p.h>
 
 #include <CoreFoundation/CoreFoundation.h>
 
@@ -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<int, MacSocketInfo *> MacSocketHash;
 
-class QCocoaEventDispatcherPrivate : public QEventDispatcherQPAPrivate
+class QCocoaEventDispatcherPrivate : public QEventDispatcherUNIXPrivate
 {
     Q_DECLARE_PUBLIC(QCocoaEventDispatcher)
 
index b5cbc83..cfb6995 100644 (file)
@@ -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);
     }
 }