Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qxcbeventdispatcher.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#include <QtCore/QCoreApplication>
9
10#include <qpa/qwindowsysteminterface.h>
11
13
19
23
24bool QXcbUnixEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
25{
26 const bool didSendEvents = QEventDispatcherUNIX::processEvents(flags);
27 m_connection->processXcbEvents(flags);
28 // The following line should not be necessary after QTBUG-70095
29 return QWindowSystemInterface::sendWindowSystemEvents(flags) || didSendEvents;
30}
31
32#if QT_CONFIG(glib)
33struct XcbEventSource
34{
35 GSource source;
36 QXcbGlibEventDispatcher *dispatcher;
37 QXcbGlibEventDispatcherPrivate *dispatcher_p;
38 QXcbConnection *connection = nullptr;
39};
40
41static gboolean xcbSourcePrepare(GSource *source, gint *timeout)
42{
43 Q_UNUSED(timeout);
44 auto xcbEventSource = reinterpret_cast<XcbEventSource *>(source);
45 return xcbEventSource->dispatcher_p->wakeUpCalled;
46}
47
48static gboolean xcbSourceCheck(GSource *source)
49{
50 return xcbSourcePrepare(source, nullptr);
51}
52
53static gboolean xcbSourceDispatch(GSource *source, GSourceFunc, gpointer)
54{
55 auto xcbEventSource = reinterpret_cast<XcbEventSource *>(source);
56 QEventLoop::ProcessEventsFlags flags = xcbEventSource->dispatcher->flags();
57 xcbEventSource->connection->processXcbEvents(flags);
58 // The following line should not be necessary after QTBUG-70095
59 QWindowSystemInterface::sendWindowSystemEvents(flags);
60 return true;
61}
62
63QXcbGlibEventDispatcher::QXcbGlibEventDispatcher(QXcbConnection *connection, QObject *parent)
64 : QEventDispatcherGlib(*new QXcbGlibEventDispatcherPrivate(), parent)
65{
66 Q_D(QXcbGlibEventDispatcher);
67
68 m_xcbEventSourceFuncs.prepare = xcbSourcePrepare;
69 m_xcbEventSourceFuncs.check = xcbSourceCheck;
70 m_xcbEventSourceFuncs.dispatch = xcbSourceDispatch;
71 m_xcbEventSourceFuncs.finalize = nullptr;
72
73 GSource *source = g_source_new(&m_xcbEventSourceFuncs, sizeof(XcbEventSource));
74 m_xcbEventSource = reinterpret_cast<XcbEventSource *>(source);
75
76 m_xcbEventSource->dispatcher = this;
77 m_xcbEventSource->dispatcher_p = d_func();
78 m_xcbEventSource->connection = connection;
79
80 d->attachSource(source, "[Qt] XcbEventSource");
81}
82
83QXcbGlibEventDispatcherPrivate::QXcbGlibEventDispatcherPrivate()
84{
85}
86
87QXcbGlibEventDispatcher::~QXcbGlibEventDispatcher()
88{
89 Q_D(QXcbGlibEventDispatcher);
90 d->destroySource(&m_xcbEventSource->source);
91}
92
93bool QXcbGlibEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
94{
95 m_flags = flags;
96 return QEventDispatcherGlib::processEvents(m_flags);
97}
98
99#endif // QT_CONFIG(glib)
100
101QAbstractEventDispatcher *QXcbEventDispatcher::createEventDispatcher(QXcbConnection *connection)
102{
103#if QT_CONFIG(glib)
104 if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") && QEventDispatcherGlib::versionSupported()) {
105 qCDebug(lcQpaXcb, "using glib dispatcher");
106 return new QXcbGlibEventDispatcher(connection);
107 } else
108#endif
109 {
110 qCDebug(lcQpaXcb, "using unix dispatcher");
111 return new QXcbUnixEventDispatcher(connection);
112 }
113}
114
115QT_END_NAMESPACE
116
117#include "moc_qxcbeventdispatcher.cpp"
QObject * parent
Definition qobject.h:74
bool processEvents(QEventLoop::ProcessEventsFlags flags) override
Processes pending events that match flags until there are no more events to process.
Combined button and popup list for selecting options.