From dfd72c6e6c5aab58bd56c8f7854e94df2230bd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 27 Jul 2011 16:54:53 +0200 Subject: Make QPlatformIntegration not have a factory for eventdispatcher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit but rather an accessor for the guiThreadEventDispatcher Change-Id: I1b9ba14efc9f338c5a67e3e24ddb0caf76c07413 Reviewed-on: http://codereview.qt.nokia.com/2321 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 8 ++++---- src/gui/kernel/qplatformintegration_qpa.h | 2 +- src/plugins/platforms/cocoa/qcocoaintegration.h | 4 +++- src/plugins/platforms/cocoa/qcocoaintegration.mm | 5 +++-- src/plugins/platforms/openwfd/qopenwfddevice.cpp | 4 ++-- .../platforms/openwfd/qopenwfdintegration.cpp | 8 ++++---- src/plugins/platforms/openwfd/qopenwfdintegration.h | 3 ++- src/plugins/platforms/wayland/qwaylanddisplay.cpp | 17 +++++++---------- src/plugins/platforms/wayland/qwaylanddisplay.h | 2 -- .../platforms/wayland/qwaylandintegration.cpp | 12 +++++++----- src/plugins/platforms/wayland/qwaylandintegration.h | 4 +++- src/plugins/platforms/xcb/qxcbconnection.cpp | 16 +++++++--------- src/plugins/platforms/xcb/qxcbconnection.h | 2 -- src/plugins/platforms/xcb/qxcbintegration.cpp | 21 +++++++++------------ src/plugins/platforms/xcb/qxcbintegration.h | 3 ++- 15 files changed, 54 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 5a31fb5df1..6442f290d2 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -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; } diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h index 35dfe07140..b355f4ff12 100644 --- a/src/gui/kernel/qplatformintegration_qpa.h +++ b/src/gui/kernel/qplatformintegration_qpa.h @@ -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; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 5a30de697e..075405a9d6 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -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; }; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 23110583c1..6c10ed6692 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -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 diff --git a/src/plugins/platforms/openwfd/qopenwfddevice.cpp b/src/plugins/platforms/openwfd/qopenwfddevice.cpp index fb63468725..d3ff6d45d8 100644 --- a/src/plugins/platforms/openwfd/qopenwfddevice.cpp +++ b/src/plugins/platforms/openwfd/qopenwfddevice.cpp @@ -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; diff --git a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp index 2494e7f030..63d7b6a31f 100644 --- a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp +++ b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp @@ -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 diff --git a/src/plugins/platforms/openwfd/qopenwfdintegration.h b/src/plugins/platforms/openwfd/qopenwfdintegration.h index 9b7b5329dc..18d87fd90e 100644 --- a/src/plugins/platforms/openwfd/qopenwfdintegration.h +++ b/src/plugins/platforms/openwfd/qopenwfdintegration.h @@ -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 diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index ca0e6572cf..588096933c 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -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(); } diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.h b/src/plugins/platforms/wayland/qwaylanddisplay.h index 14812885a3..2b7f33f4f6 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.h +++ b/src/plugins/platforms/wayland/qwaylanddisplay.h @@ -92,8 +92,6 @@ public: QList inputDevices() const { return mInputDevices; } - void eventDispatcherCreated(QAbstractEventDispatcher *dispatcher); - public slots: void createNewScreen(struct wl_output *output, QRect geometry); void readEvents(); diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index d3d7edf0f6..eb4503c829 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -51,6 +51,8 @@ #include "QtPlatformSupport/private/qgenericunixfontdatabase_p.h" #include +#include + #include #include #include @@ -61,9 +63,11 @@ 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 diff --git a/src/plugins/platforms/wayland/qwaylandintegration.h b/src/plugins/platforms/wayland/qwaylandintegration.h index 3c8b996f14..209d5da0da 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.h +++ b/src/plugins/platforms/wayland/qwaylandintegration.h @@ -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 screens() const; @@ -73,6 +74,7 @@ public: private: QPlatformFontDatabase *mFontDb; + QAbstractEventDispatcher *mEventDispatcher; QWaylandDisplay *mDisplay; QPlatformNativeInterface *mNativeInterface; }; diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 7803b3afe9..0727af4b40 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -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); diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index bc90f5fcdc..6a80f57972 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -232,8 +232,6 @@ public: QXcbConnection *connection() const { return const_cast(this); } - void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher); - const QList &screens() const { return m_screens; } int primaryScreen() const { return m_primaryScreen; } diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 313a773c78..7982f8dc0e 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -57,6 +57,9 @@ #include +//this has to be included before egl, since egl pulls in X headers +#include + #ifdef XCB_USE_EGL #include #endif @@ -78,7 +81,10 @@ QXcbIntegration::QXcbIntegration(const QStringList ¶meters) : 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 ¶meters) 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(this)->m_inputContext = new QIBusPlatformInputContext; -#endif - return eventDispatcher; + return m_eventDispatcher; } void QXcbIntegration::moveToScreen(QWindow *window, int screen) diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h index d62878c7af..29835f493f 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.h +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -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 -- cgit v1.2.3