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
qeventdispatcher_glib.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
6
8
9#include "qplatformdefs.h"
10
11#include <glib.h>
12#include "private/qguiapplication_p.h"
13
15
22
23static gboolean userEventSourcePrepare(GSource *source, gint *timeout)
24{
25 Q_UNUSED(timeout);
26 GUserEventSource *userEventSource = reinterpret_cast<GUserEventSource *>(source);
27 return userEventSource->d->wakeUpCalled;
28}
29
30static gboolean userEventSourceCheck(GSource *source)
31{
32 return userEventSourcePrepare(source, nullptr);
33}
34
36{
37 GUserEventSource *userEventSource = reinterpret_cast<GUserEventSource *>(source);
38 QPAEventDispatcherGlib *dispatcher = userEventSource->q;
39 QWindowSystemInterface::sendWindowSystemEvents(dispatcher->m_flags);
40 return true;
41}
42
44 userEventSourcePrepare,
45 userEventSourceCheck,
46 userEventSourceDispatch,
47 NULL,
48 NULL,
49 NULL
50};
51
52QPAEventDispatcherGlibPrivate::QPAEventDispatcherGlibPrivate(GMainContext *context)
53 : QEventDispatcherGlibPrivate(context)
54{
55 Q_Q(QPAEventDispatcherGlib);
56
57 GSource *source = g_source_new(&userEventSourceFuncs, sizeof(GUserEventSource));
58 g_source_set_name(source, "[Qt] GUserEventSource");
59 userEventSource = reinterpret_cast<GUserEventSource *>(source);
60
61 userEventSource->q = q;
62 userEventSource->d = this;
63 g_source_set_can_recurse(&userEventSource->source, true);
64 g_source_attach(&userEventSource->source, mainContext);
65}
66
68 = default;
69
70QPAEventDispatcherGlib::QPAEventDispatcherGlib(QObject *parent)
71 : QEventDispatcherGlib(*new QPAEventDispatcherGlibPrivate, parent)
72 , m_flags(QEventLoop::AllEvents)
73{
74 Q_D(QPAEventDispatcherGlib);
75 d->userEventSource->q = this;
76}
77
78QPAEventDispatcherGlib::~QPAEventDispatcherGlib()
79{
80 Q_D(QPAEventDispatcherGlib);
81
82 g_source_destroy(&d->userEventSource->source);
83 g_source_unref(&d->userEventSource->source);
84 d->userEventSource = nullptr;
85}
86
87bool QPAEventDispatcherGlib::processEvents(QEventLoop::ProcessEventsFlags flags)
88{
89 m_flags = flags;
90 return QEventDispatcherGlib::processEvents(m_flags);
91}
92
93QT_END_NAMESPACE
94
95#include "moc_qeventdispatcher_glib_p.cpp"
~QPAEventDispatcherGlibPrivate() override
static GSourceFuncs userEventSourceFuncs
static gboolean userEventSourcePrepare(GSource *source, gint *timeout)
static gboolean userEventSourceDispatch(GSource *source, GSourceFunc, gpointer)
static gboolean userEventSourceCheck(GSource *source)
QPAEventDispatcherGlib * q
QPAEventDispatcherGlibPrivate * d