diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbeventdispatcher.cpp | 161 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbeventdispatcher.h | 117 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbeventqueue.cpp | 4 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 4 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/xcb_qpa_lib.pro | 10 |
7 files changed, 289 insertions, 11 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 29a233496b..3fb64f01a4 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -495,12 +495,11 @@ public: QXcbGlIntegration *glIntegration() const; void flush() { xcb_flush(m_connection); } + void processXcbEvents(); protected: bool event(QEvent *e) override; - void processXcbEvents(); - private: void initializeAllAtoms(); void initializeShm(); diff --git a/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp b/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp new file mode 100644 index 0000000000..252c1c62e3 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qxcbeventdispatcher.h" +#include "qxcbconnection.h" + +#include <QtCore/QCoreApplication> + +#include <qpa/qwindowsysteminterface.h> + +QT_BEGIN_NAMESPACE + +QXcbUnixEventDispatcher::QXcbUnixEventDispatcher(QXcbConnection *connection, QObject *parent) + : QEventDispatcherUNIX(parent) + , m_connection(connection) +{ +} + +QXcbUnixEventDispatcher::~QXcbUnixEventDispatcher() +{ +} + +bool QXcbUnixEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) +{ + const bool didSendEvents = QEventDispatcherUNIX::processEvents(flags); + m_connection->processXcbEvents(); + // The following line should not be necessary after QTBUG-70095 + return QWindowSystemInterface::sendWindowSystemEvents(flags) || didSendEvents; +} + +bool QXcbUnixEventDispatcher::hasPendingEvents() +{ + extern uint qGlobalPostedEventsCount(); + return qGlobalPostedEventsCount() || QWindowSystemInterface::windowSystemEventsQueued(); +} + +void QXcbUnixEventDispatcher::flush() +{ + if (qApp) + qApp->sendPostedEvents(); +} + +#if QT_CONFIG(glib) +struct XcbEventSource +{ + GSource source; + QXcbGlibEventDispatcher *dispatcher; + QXcbGlibEventDispatcherPrivate *dispatcher_p; + QXcbConnection *connection = nullptr; +}; + +static gboolean xcbSourcePrepare(GSource *source, gint *timeout) +{ + Q_UNUSED(timeout) + auto xcbEventSource = reinterpret_cast<XcbEventSource *>(source); + return xcbEventSource->dispatcher_p->wakeUpCalled; +} + +static gboolean xcbSourceCheck(GSource *source) +{ + return xcbSourcePrepare(source, nullptr); +} + +static gboolean xcbSourceDispatch(GSource *source, GSourceFunc, gpointer) +{ + auto xcbEventSource = reinterpret_cast<XcbEventSource *>(source); + xcbEventSource->connection->processXcbEvents(); + // The following line should not be necessary after QTBUG-70095 + QWindowSystemInterface::sendWindowSystemEvents(xcbEventSource->dispatcher->flags()); + return true; +} + +QXcbGlibEventDispatcher::QXcbGlibEventDispatcher(QXcbConnection *connection, QObject *parent) + : QEventDispatcherGlib(*new QXcbGlibEventDispatcherPrivate(), parent) +{ + Q_D(QXcbGlibEventDispatcher); + + m_xcbEventSourceFuncs.prepare = xcbSourcePrepare; + m_xcbEventSourceFuncs.check = xcbSourceCheck; + m_xcbEventSourceFuncs.dispatch = xcbSourceDispatch; + m_xcbEventSourceFuncs.finalize = nullptr; + + m_xcbEventSource = reinterpret_cast<XcbEventSource *>( + g_source_new(&m_xcbEventSourceFuncs, sizeof(XcbEventSource))); + + m_xcbEventSource->dispatcher = this; + m_xcbEventSource->dispatcher_p = d_func(); + m_xcbEventSource->connection = connection; + + g_source_set_can_recurse(&m_xcbEventSource->source, true); + g_source_attach(&m_xcbEventSource->source, d->mainContext); +} + +QXcbGlibEventDispatcherPrivate::QXcbGlibEventDispatcherPrivate() +{ +} + +QXcbGlibEventDispatcher::~QXcbGlibEventDispatcher() +{ + g_source_destroy(&m_xcbEventSource->source); + g_source_unref(&m_xcbEventSource->source); +} + +bool QXcbGlibEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) +{ + m_flags = flags; + return QEventDispatcherGlib::processEvents(m_flags); +} + +#endif // QT_CONFIG(glib) + +QAbstractEventDispatcher *QXcbEventDispatcher::createEventDispatcher(QXcbConnection *connection) +{ +#if QT_CONFIG(glib) + if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") && QEventDispatcherGlib::versionSupported()) { + qCDebug(lcQpaXcb, "using glib dispatcher"); + return new QXcbGlibEventDispatcher(connection); + } else +#endif + { + qCDebug(lcQpaXcb, "using unix dispatcher"); + return new QXcbUnixEventDispatcher(connection); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbeventdispatcher.h b/src/plugins/platforms/xcb/qxcbeventdispatcher.h new file mode 100644 index 0000000000..6aadd63a70 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbeventdispatcher.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QXCBEVENTDISPATCHER_H +#define QXCBEVENTDISPATCHER_H + +#include <QtCore/QObject> +#include <QtCore/QEventLoop> + +#include <QtCore/private/qeventdispatcher_unix_p.h> +#if QT_CONFIG(glib) +#include <QtCore/private/qeventdispatcher_glib_p.h> +#include <glib.h> +#endif + +QT_BEGIN_NAMESPACE + +class QXcbConnection; + +class QXcbUnixEventDispatcher : public QEventDispatcherUNIX +{ + Q_OBJECT +public: + explicit QXcbUnixEventDispatcher(QXcbConnection *connection, QObject *parent = nullptr); + ~QXcbUnixEventDispatcher(); + bool processEvents(QEventLoop::ProcessEventsFlags flags) override; + + // Maybe some user code depends on deprecated QUnixEventDispatcherQPA:: + // hasPendingEvents() / flush() implementation, so keep it around until + // Qt 6. These methods are deprecated in QAbstractEventDispatcher. + bool hasPendingEvents() override; // ### Qt 6 remove + void flush() override; // ### Qt 6 remove + +private: + QXcbConnection *m_connection; +}; + +#if QT_CONFIG(glib) + +struct XcbEventSource; +class QXcbGlibEventDispatcherPrivate; + +class QXcbGlibEventDispatcher : public QEventDispatcherGlib +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QXcbGlibEventDispatcher) + +public: + explicit QXcbGlibEventDispatcher(QXcbConnection *connection, QObject *parent = nullptr); + ~QXcbGlibEventDispatcher(); + + bool processEvents(QEventLoop::ProcessEventsFlags flags) override; + QEventLoop::ProcessEventsFlags flags() const { return m_flags; } + +private: + XcbEventSource *m_xcbEventSource; + GSourceFuncs m_xcbEventSourceFuncs; + QEventLoop::ProcessEventsFlags m_flags; +}; + +class QXcbGlibEventDispatcherPrivate : public QEventDispatcherGlibPrivate +{ + Q_DECLARE_PUBLIC(QXcbGlibEventDispatcher) + +public: + QXcbGlibEventDispatcherPrivate(); +}; + +#endif // QT_CONFIG(glib) + +class QXcbEventDispatcher +{ +public: + static QAbstractEventDispatcher *createEventDispatcher(QXcbConnection *connection); + +private: + QXcbConnection *m_connection; +}; + +QT_END_NAMESPACE + +#endif // QXCBEVENTDISPATCHER_H diff --git a/src/plugins/platforms/xcb/qxcbeventqueue.cpp b/src/plugins/platforms/xcb/qxcbeventqueue.cpp index e530928ccb..6d8b001faa 100644 --- a/src/plugins/platforms/xcb/qxcbeventqueue.cpp +++ b/src/plugins/platforms/xcb/qxcbeventqueue.cpp @@ -76,7 +76,6 @@ QT_BEGIN_NAMESPACE QXcbEventQueue::QXcbEventQueue(QXcbConnection *connection) : m_connection(connection) { - connect(this, &QXcbEventQueue::eventsPending, m_connection, &QXcbConnection::processXcbEvents, Qt::QueuedConnection); connect(this, &QXcbEventQueue::finished, m_connection, &QXcbConnection::processXcbEvents); // Lets init the list with one node, so we don't have to check for @@ -105,8 +104,7 @@ QXcbEventQueue::~QXcbEventQueue() void QXcbEventQueue::registerEventDispatcher(QAbstractEventDispatcher *dispatcher) { - // Flush the xcb connection before the event dispatcher is going to block. - connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, m_connection, &QXcbConnection::flush); + connect(this, &QXcbEventQueue::eventsPending, dispatcher, &QAbstractEventDispatcher::wakeUp, Qt::QueuedConnection); } xcb_generic_event_t *QXcbEventQueue::takeFirst() diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index b1a1ed93cd..8f6d35dc5b 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -47,6 +47,7 @@ #include "qxcbnativeinterface.h" #include "qxcbclipboard.h" #include "qxcbeventqueue.h" +#include "qxcbeventdispatcher.h" #if QT_CONFIG(draganddrop) #include "qxcbdrag.h" #endif @@ -58,7 +59,6 @@ #include <xcb/xcb.h> -#include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> #include <QtServiceSupport/private/qgenericunixservices_p.h> @@ -343,7 +343,7 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const QAbstractEventDispatcher *QXcbIntegration::createEventDispatcher() const { - QAbstractEventDispatcher *dispatcher = createUnixEventDispatcher(); + QAbstractEventDispatcher *dispatcher = QXcbEventDispatcher::createEventDispatcher(defaultConnection()); for (int i = 0; i < m_connections.size(); i++) m_connections[i]->eventQueue()->registerEventDispatcher(dispatcher); return dispatcher; diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h index 69e49cb7f6..a8dd6402f6 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.h +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE class QXcbConnection; class QAbstractEventDispatcher; class QXcbNativeInterface; -class QXcbScreen; class Q_XCB_EXPORT QXcbIntegration : public QPlatformIntegration { diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index fbda8c39b9..a747b25c88 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -5,7 +5,7 @@ DEFINES += QT_NO_FOREACH QT += \ core-private gui-private \ service_support-private theme_support-private \ - eventdispatcher_support-private fontdatabase_support-private \ + fontdatabase_support-private \ edid_support-private qtHaveModule(linuxaccessibility_support-private): \ @@ -13,6 +13,8 @@ qtHaveModule(linuxaccessibility_support-private): \ qtConfig(vulkan): QT += vulkan_support-private +qtConfig(glib) : QMAKE_USE_PRIVATE += glib + SOURCES = \ qxcbclipboard.cpp \ qxcbconnection.cpp \ @@ -28,7 +30,8 @@ SOURCES = \ qxcbimage.cpp \ qxcbxsettings.cpp \ qxcbsystemtraytracker.cpp \ - qxcbeventqueue.cpp + qxcbeventqueue.cpp \ + qxcbeventdispatcher.cpp HEADERS = \ qxcbclipboard.h \ @@ -47,7 +50,8 @@ HEADERS = \ qxcbxsettings.h \ qxcbsystemtraytracker.h \ qxcbxkbcommon.h \ - qxcbeventqueue.h + qxcbeventqueue.h \ + qxcbeventdispatcher.h qtConfig(draganddrop) { SOURCES += qxcbdrag.cpp |