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 g_source_set_name(source, "[Qt] XcbEventSource");
75 m_xcbEventSource = reinterpret_cast<XcbEventSource *>(source);
76
77 m_xcbEventSource->dispatcher = this;
78 m_xcbEventSource->dispatcher_p = d_func();
79 m_xcbEventSource->connection = connection;
80
81 g_source_set_can_recurse(&m_xcbEventSource->source, true);
82 g_source_attach(&m_xcbEventSource->source, d->mainContext);
83}
84
85QXcbGlibEventDispatcherPrivate::QXcbGlibEventDispatcherPrivate()
86{
87}
88
89QXcbGlibEventDispatcher::~QXcbGlibEventDispatcher()
90{
91 g_source_destroy(&m_xcbEventSource->source);
92 g_source_unref(&m_xcbEventSource->source);
93}
94
95bool QXcbGlibEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
96{
97 m_flags = flags;
98 return QEventDispatcherGlib::processEvents(m_flags);
99}
100
101#endif // QT_CONFIG(glib)
102
103QAbstractEventDispatcher *QXcbEventDispatcher::createEventDispatcher(QXcbConnection *connection)
104{
105#if QT_CONFIG(glib)
106 if (qEnvironmentVariableIsEmpty("QT_NO_GLIB") && QEventDispatcherGlib::versionSupported()) {
107 qCDebug(lcQpaXcb, "using glib dispatcher");
108 return new QXcbGlibEventDispatcher(connection);
109 } else
110#endif
111 {
112 qCDebug(lcQpaXcb, "using unix dispatcher");
113 return new QXcbUnixEventDispatcher(connection);
114 }
115}
116
117QT_END_NAMESPACE
118
119#include "moc_qxcbeventdispatcher.cpp"
QObject * parent
Definition qobject.h:73
bool processEvents(QEventLoop::ProcessEventsFlags flags) override
Processes pending events that match flags until there are no more events to process.