Make QPlatformIntegration not have a factory for eventdispatcher
authorJørgen Lind <jorgen.lind@nokia.com>
Wed, 27 Jul 2011 14:54:53 +0000 (16:54 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Thu, 28 Jul 2011 08:06:11 +0000 (10:06 +0200)
but rather an accessor for the guiThreadEventDispatcher

Change-Id: I1b9ba14efc9f338c5a67e3e24ddb0caf76c07413
Reviewed-on: http://codereview.qt.nokia.com/2321
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
15 files changed:
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qplatformintegration_qpa.h
src/plugins/platforms/cocoa/qcocoaintegration.h
src/plugins/platforms/cocoa/qcocoaintegration.mm
src/plugins/platforms/openwfd/qopenwfddevice.cpp
src/plugins/platforms/openwfd/qopenwfdintegration.cpp
src/plugins/platforms/openwfd/qopenwfdintegration.h
src/plugins/platforms/wayland/qwaylanddisplay.cpp
src/plugins/platforms/wayland/qwaylanddisplay.h
src/plugins/platforms/wayland/qwaylandintegration.cpp
src/plugins/platforms/wayland/qwaylandintegration.h
src/plugins/platforms/xcb/qxcbconnection.cpp
src/plugins/platforms/xcb/qxcbconnection.h
src/plugins/platforms/xcb/qxcbintegration.cpp
src/plugins/platforms/xcb/qxcbintegration.h

index 5a31fb5..6442f29 100644 (file)
@@ -318,7 +318,7 @@ void QGuiApplicationPrivate::createEventDispatcher()
         createPlatformIntegration();
 
     if (!eventDispatcher) {
-        QAbstractEventDispatcher *eventDispatcher = platform_integration->createEventDispatcher();
+        QAbstractEventDispatcher *eventDispatcher = platform_integration->guiThreadEventDispatcher();
         setEventDispatcher(eventDispatcher);
     }
 }
@@ -327,9 +327,9 @@ void QGuiApplicationPrivate::setEventDispatcher(QAbstractEventDispatcher *eventD
 {
     Q_Q(QGuiApplication);
 
-    if (!this->eventDispatcher) {
-        this->eventDispatcher = eventDispatcher;
-        this->eventDispatcher->setParent(q);
+    if (!QCoreApplicationPrivate::eventDispatcher) {
+        QCoreApplicationPrivate::eventDispatcher = eventDispatcher;
+        QCoreApplicationPrivate::eventDispatcher->setParent(q);
         threadData->eventDispatcher = eventDispatcher;
     }
 
index 35dfe07..b355f4f 100644 (file)
@@ -83,7 +83,7 @@ public:
     virtual QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const;
 
 // Event dispatcher:
-    virtual QAbstractEventDispatcher *createEventDispatcher() const = 0;
+    virtual QAbstractEventDispatcher *guiThreadEventDispatcher() const = 0;
 
 //Deeper window system integrations
     virtual QPlatformFontDatabase *fontDatabase() const;
index 5a30de6..075405a 100644 (file)
@@ -79,13 +79,15 @@ public:
     QPlatformWindow *createPlatformWindow(QWindow *window) const;
     QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const;
     QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const;
-    QAbstractEventDispatcher *createEventDispatcher() const;
+
+    QAbstractEventDispatcher *guiThreadEventDispatcher() const;
 
     QPlatformFontDatabase *fontDatabase() const;
 
     QPlatformNativeInterface *nativeInterface() const;
 private:
     QPlatformFontDatabase *mFontDb;
+    QAbstractEventDispatcher *mEventDispatcher;
 
     QCocoaAutoReleasePool *mPool;
 };
index 2311058..6c10ed6 100644 (file)
@@ -72,6 +72,7 @@ QCocoaScreen::~QCocoaScreen()
 
 QCocoaIntegration::QCocoaIntegration()
     : mFontDb(new QBasicUnixFontDatabase())
+    , mEventDispatcher(new QCocoaEventDispatcher())
 {
     mPool = new QCocoaAutoReleasePool;
 
@@ -117,9 +118,9 @@ QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *wi
     return new QCocoaBackingStore(window);
 }
 
-QAbstractEventDispatcher *QCocoaIntegration::createEventDispatcher() const
+QAbstractEventDispatcher *QCocoaIntegration::guiThreadEventDispatcher() const
 {
-    return new QCocoaEventDispatcher();
+    return mEventDispatcher;
 }
 
 QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
index fb63468..d3ff6d4 100644 (file)
@@ -83,8 +83,8 @@ QOpenWFDDevice::QOpenWFDDevice(QOpenWFDIntegration *integration, WFDint device_e
         }
     }
 
-    int copyFd = wfdDeviceEventGetFD(mDevice,mEvent);
-    mEventSocketNotifier = new QSocketNotifier(copyFd,QSocketNotifier::Read,this);
+    int fd = wfdDeviceEventGetFD(mDevice,mEvent);
+    mEventSocketNotifier = new QSocketNotifier(fd,QSocketNotifier::Read,this);
     connect(mEventSocketNotifier,SIGNAL(activated(int)),SLOT(readEvents()));
 
     mCommitedDevice = true;
index 2494e7f..63d7b6a 100644 (file)
@@ -63,8 +63,9 @@
 QOpenWFDIntegration::QOpenWFDIntegration()
     : QPlatformIntegration()
     , mPrinterSupport(new QGenericUnixPrinterSupport)
+    , mEventDispatcher(createUnixEventDispatcher())
 {
-    QGuiApplicationPrivate::instance()->setEventDispatcher(createEventDispatcher());
+    QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
     int numberOfDevices = wfdEnumerateDevices(0,0,0);
 
     WFDint devices[numberOfDevices];
@@ -118,10 +119,9 @@ QPlatformBackingStore *QOpenWFDIntegration::createPlatformBackingStore(QWindow *
     return new QOpenWFDBackingStore(window);
 }
 
-QAbstractEventDispatcher *QOpenWFDIntegration::createEventDispatcher() const
+QAbstractEventDispatcher *QOpenWFDIntegration::guiThreadEventDispatcher() const
 {
-    QAbstractEventDispatcher *eventDispatcher = createUnixEventDispatcher();
-    return eventDispatcher;
+    return mEventDispatcher;
 }
 
 QPlatformFontDatabase *QOpenWFDIntegration::fontDatabase() const
index 9b7b532..18d87fd 100644 (file)
@@ -62,7 +62,7 @@ public:
     QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const;
 
     //This should not be a factory interface, but rather a accessor
-    QAbstractEventDispatcher *createEventDispatcher() const;
+    QAbstractEventDispatcher *guiThreadEventDispatcher() const;
 
     QPlatformFontDatabase *fontDatabase() const;
 
@@ -78,6 +78,7 @@ private:
     QPlatformFontDatabase *mFontDatabase;
     QPlatformNativeInterface *mNativeInterface;
     QPlatformPrinterSupport *mPrinterSupport;
+    QAbstractEventDispatcher *mEventDispatcher;
 };
 
 QT_END_NAMESPACE
index ca0e657..5880969 100644 (file)
@@ -142,6 +142,13 @@ QWaylandDisplay::QWaylandDisplay(void)
 
     wl_display_add_global_listener(mDisplay, QWaylandDisplay::displayHandleGlobal, this);
 
+    mFd = wl_display_get_fd(mDisplay, sourceUpdate, this);
+    QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher;
+    connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(flushRequests()));
+
+    mReadNotifier = new QSocketNotifier(mFd, QSocketNotifier::Read, this);
+    connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(readEvents()));
+
 #ifdef QT_WAYLAND_GL_SUPPORT
     mEglIntegration = QWaylandGLIntegration::createGLIntegration(this);
 #endif
@@ -156,16 +163,6 @@ QWaylandDisplay::QWaylandDisplay(void)
     mEglIntegration->initialize();
 #endif
 
-    mFd = wl_display_get_fd(mDisplay, sourceUpdate, this);
-}
-
-void QWaylandDisplay::eventDispatcherCreated(QAbstractEventDispatcher *dispatcher)
-{
-    connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(flushRequests()));
-
-    mReadNotifier = new QSocketNotifier(mFd, QSocketNotifier::Read, this);
-    connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(readEvents()));
-
     waitForScreens();
 }
 
index 1481288..2b7f33f 100644 (file)
@@ -92,8 +92,6 @@ public:
 
     QList<QWaylandInputDevice *> inputDevices() const { return mInputDevices; }
 
-    void eventDispatcherCreated(QAbstractEventDispatcher *dispatcher);
-
 public slots:
     void createNewScreen(struct wl_output *output, QRect geometry);
     void readEvents();
index d3d7edf..eb4503c 100644 (file)
@@ -51,6 +51,8 @@
 #include "QtPlatformSupport/private/qgenericunixfontdatabase_p.h"
 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
 
+#include <QtGui/private/qguiapplication_p.h>
+
 #include <QtGui/QWindowSystemInterface>
 #include <QtGui/QPlatformCursor>
 #include <QtGui/QSurfaceFormat>
 
 QWaylandIntegration::QWaylandIntegration()
     : mFontDb(new QGenericUnixFontDatabase())
-    , mDisplay(new QWaylandDisplay())
+    , mEventDispatcher(createUnixEventDispatcher())
     , mNativeInterface(new QWaylandNativeInterface)
 {
+    QGuiApplicationPrivate::instance()->setEventDispatcher(mEventDispatcher);
+    mDisplay = new QWaylandDisplay();
 }
 
 QPlatformNativeInterface * QWaylandIntegration::nativeInterface() const
@@ -116,11 +120,9 @@ QPlatformBackingStore *QWaylandIntegration::createPlatformBackingStore(QWindow *
     return new QWaylandShmBackingStore(window);
 }
 
-QAbstractEventDispatcher *QWaylandIntegration::createEventDispatcher() const
+QAbstractEventDispatcher *QWaylandIntegration::guiThreadEventDispatcher() const
 {
-    QAbstractEventDispatcher *dispatcher = createUnixEventDispatcher();
-    mDisplay->eventDispatcherCreated(dispatcher);
-    return dispatcher;
+    return mEventDispatcher;
 }
 
 QPlatformFontDatabase *QWaylandIntegration::fontDatabase() const
index 3c8b996..209d5da 100644 (file)
@@ -59,7 +59,8 @@ public:
     QPlatformWindow *createPlatformWindow(QWindow *window) const;
     QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
     QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
-    QAbstractEventDispatcher *createEventDispatcher() const;
+
+    QAbstractEventDispatcher *guiThreadEventDispatcher() const;
 
     QList<QPlatformScreen *> screens() const;
 
@@ -73,6 +74,7 @@ public:
 
 private:
     QPlatformFontDatabase *mFontDb;
+    QAbstractEventDispatcher *mEventDispatcher;
     QWaylandDisplay *mDisplay;
     QPlatformNativeInterface *mNativeInterface;
 };
index 7803b3a..0727af4 100644 (file)
@@ -114,6 +114,13 @@ QXcbConnection::QXcbConnection(const char *displayName)
     if (m_connection)
         printf("Successfully connected to display %s\n", m_displayName.constData());
 
+    QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
+    connect(notifier, SIGNAL(activated(int)), this, SLOT(processXcbEvents()));
+
+    QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher;
+    connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processXcbEvents()));
+    connect(dispatcher, SIGNAL(awake()), this, SLOT(processXcbEvents()));
+
     xcb_prefetch_extension_data (m_connection, &xcb_xfixes_id);
 
     m_setup = xcb_get_setup(xcb_connection());
@@ -159,15 +166,6 @@ QXcbConnection::~QXcbConnection()
     delete m_keyboard;
 }
 
-void QXcbConnection::setEventDispatcher(QAbstractEventDispatcher *dispatcher)
-{
-    QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
-    connect(notifier, SIGNAL(activated(int)), this, SLOT(processXcbEvents()));
-
-    connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processXcbEvents()));
-    connect(dispatcher, SIGNAL(awake()), this, SLOT(processXcbEvents()));
-}
-
 void QXcbConnection::addWindow(xcb_window_t id, QXcbWindow *window)
 {
     m_mapper.insert(id, window);
index bc90f5f..6a80f57 100644 (file)
@@ -232,8 +232,6 @@ public:
 
     QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
 
-    void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
-
     const QList<QXcbScreen *> &screens() const { return m_screens; }
     int primaryScreen() const { return m_primaryScreen; }
 
index 313a773..7982f8d 100644 (file)
@@ -57,6 +57,9 @@
 
 #include <stdio.h>
 
+//this has to be included before egl, since egl pulls in X headers
+#include <QtGui/private/qguiapplication_p.h>
+
 #ifdef XCB_USE_EGL
 #include <EGL/egl.h>
 #endif
 
 QXcbIntegration::QXcbIntegration(const QStringList &parameters)
     : m_printerSupport(new QGenericUnixPrinterSupport)
+    , m_eventDispatcher(createUnixEventDispatcher())
 {
+    QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
+
     m_connections << new QXcbConnection;
 
     for (int i = 0; i < parameters.size() - 1; i += 2) {
@@ -94,7 +100,7 @@ QXcbIntegration::QXcbIntegration(const QStringList &parameters)
     m_fontDatabase = new QGenericUnixFontDatabase();
     m_nativeInterface = new QXcbNativeInterface;
 
-    m_inputContext = 0;
+    m_inputContext = new QIBusPlatformInputContext;
 }
 
 QXcbIntegration::~QXcbIntegration()
@@ -149,18 +155,9 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
     }
 }
 
-QAbstractEventDispatcher *QXcbIntegration::createEventDispatcher() const
+QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
 {
-    QAbstractEventDispatcher *eventDispatcher = createUnixEventDispatcher();
-
-    foreach (QXcbConnection *connection, m_connections)
-        connection->setEventDispatcher(eventDispatcher);
-#ifdef XCB_USE_IBUS
-    // A bit hacky to do this here, but we need an eventloop before we can instantiate
-    // the input context.
-    const_cast<QXcbIntegration *>(this)->m_inputContext = new QIBusPlatformInputContext;
-#endif
-    return eventDispatcher;
+    return m_eventDispatcher;
 }
 
 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
index d62878c..29835f4 100644 (file)
@@ -61,7 +61,7 @@ public:
     QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
 
     bool hasCapability(Capability cap) const;
-    QAbstractEventDispatcher *createEventDispatcher() const;
+    QAbstractEventDispatcher *guiThreadEventDispatcher() const;
 
     void moveToScreen(QWindow *window, int screen);
 
@@ -83,6 +83,7 @@ private:
     QPlatformPrinterSupport *m_printerSupport;
 
     QPlatformInputContext *m_inputContext;
+    QAbstractEventDispatcher *m_eventDispatcher;
 };
 
 QT_END_NAMESPACE