Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwaylandclientextension.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 Erik Larsson.
2
// Copyright (C) 2021 David Redondo <qt@david-redondo.de>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
include
"qwaylandclientextension.h"
7
#
include
"qwaylandclientextension_p.h"
8
#
include
<
QtWaylandClient
/
private
/
qwaylanddisplay_p
.
h
>
9
#
include
<
QtWaylandClient
/
private
/
qwaylandintegration_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
using
RegistryGlobal = QtWaylandClient::QWaylandDisplay::RegistryGlobal;
14
using
namespace
Qt::StringLiterals;
15
16
QWaylandClientExtensionPrivate::QWaylandClientExtensionPrivate()
17
{
18
// Keep the possibility to use a custom waylandIntegration as a plugin,
19
// but also add the possibility to run it as a QML component.
20
waylandIntegration = QtWaylandClient::QWaylandIntegration::instance();
21
if
(!waylandIntegration)
22
waylandIntegration =
new
QtWaylandClient::QWaylandIntegration(
"wayland"_L1
);
23
}
24
25
void
QWaylandClientExtensionPrivate::globalAdded(
const
RegistryGlobal &global)
26
{
27
Q_Q(QWaylandClientExtension);
28
if
(!active && global.interface == QLatin1String(q->extensionInterface()->name)) {
29
q->bind(global.registry, global.id, global.version);
30
active =
true
;
31
emit q->activeChanged();
32
}
33
}
34
35
void
QWaylandClientExtensionPrivate::globalRemoved(
const
RegistryGlobal &global)
36
{
37
Q_Q(QWaylandClientExtension);
38
if
(active && global.interface == QLatin1String(q->extensionInterface()->name)) {
39
active =
false
;
40
emit q->activeChanged();
41
}
42
}
43
44
/*!
45
\class QWaylandClientExtensionTemplate
46
\brief A class for implementing custom extensions on the Wayland protocol.
47
\inmodule QtWaylandClient
48
49
The QWaylandClientExtensionTemplate is a convenience class for creating
50
the client-side implementation of custom Wayland protocols. Typical usage
51
involves inheriting this class and instantiating it with its own subclass.
52
53
See the \l{Custom Extension} example in \l{Qt Wayland Compositor} for a
54
concrete use of this class.
55
*/
56
57
/*!
58
\class QWaylandClientExtension
59
\brief A class for implementing custom extensions on the Wayland protocol.
60
\inmodule QtWaylandClient
61
62
The QWaylandClientExtension class can be used to implement custom extensions
63
for Wayland protocol. The extension must also be supported by the compositor
64
in order to be usable. See the \l{Custom Extension} example in
65
\l{Qt Wayland Compositor} for an example that implements both the compositor
66
and client sides of a custom extension.
67
68
This class is usually not inherited directly, but through
69
QWaylandClientExtensionTemplate for convenience.
70
*/
71
72
/*!
73
\internal
74
*/
75
void
QWaylandClientExtension::initialize()
76
{
77
Q_D(QWaylandClientExtension);
78
if
(d->active) {
79
return
;
80
}
81
const
QtWaylandClient::QWaylandDisplay *display = d->waylandIntegration->display();
82
const
auto
globals = display->globals();
83
auto
global =
84
std::find_if(globals.cbegin(), globals.cend(), [
this
](
const
RegistryGlobal &global) {
85
return
global.interface == QLatin1String(extensionInterface()->name);
86
});
87
if
(global != globals.cend()) {
88
bind(global->registry, global->id, global->version);
89
d->active =
true
;
90
emit activeChanged();
91
}
92
}
93
94
/*!
95
\since 6.12
96
Constructs the client extension and sets its version to \a ver and makes the extension a
97
child of \a parent.
98
*/
99
QWaylandClientExtension::QWaylandClientExtension(
int
ver, QObject *parent)
100
: QObject(*
new
QWaylandClientExtensionPrivate(), parent)
101
{
102
Q_D(QWaylandClientExtension);
103
d->version = ver;
104
auto
display = d->waylandIntegration->display();
105
QObjectPrivate::connect(display, &QtWaylandClient::QWaylandDisplay::globalAdded, d,
106
&QWaylandClientExtensionPrivate::globalAdded);
107
QObjectPrivate::connect(display, &QtWaylandClient::QWaylandDisplay::globalRemoved, d,
108
&QWaylandClientExtensionPrivate::globalRemoved);
109
// This function uses virtual functions and we don't want it to be called from the constructor.
110
QMetaObject::invokeMethod(
this
,
"initialize"
, Qt::QueuedConnection);
111
}
112
113
/*!
114
Constructs the client extension and sets its version to \a ver. Equivalent to
115
QWaylandClientExtension(ver, nullptr).
116
*/
117
QWaylandClientExtension::QWaylandClientExtension(
const
int
ver)
118
: QWaylandClientExtension(ver,
nullptr
)
119
{
120
}
121
122
/*!
123
Destroys the client extension.
124
*/
125
QWaylandClientExtension::~QWaylandClientExtension()
126
{
127
}
128
129
/*!
130
\internal
131
*/
132
QtWaylandClient::QWaylandIntegration *QWaylandClientExtension::integration()
const
133
{
134
Q_D(
const
QWaylandClientExtension);
135
return
d->waylandIntegration;
136
}
137
138
/*!
139
\fn const struct wl_interface *extensionInterface() const
140
\internal
141
*/
142
143
/*!
144
\fn void bind(struct ::wl_registry *registry, int id, int version)
145
\internal
146
*/
147
148
/*!
149
\property QWaylandClientExtension::protocolVersion
150
\brief The version of the protocol.
151
152
This property holds the version of the protocol that has been requested.
153
*/
154
int
QWaylandClientExtension::version()
const
155
{
156
Q_D(
const
QWaylandClientExtension);
157
return
d->version;
158
}
159
160
void
QWaylandClientExtension::setVersion(
const
int
ver)
161
{
162
Q_D(QWaylandClientExtension);
163
if
(d->version != ver) {
164
d->version = ver;
165
emit versionChanged();
166
}
167
}
168
169
/*!
170
\property QWaylandClientExtension::active
171
\brief The active state of the extension.
172
173
Set to \c true if the extension is currently active. Otherwise this
174
property is \c false.
175
*/
176
177
bool
QWaylandClientExtension::isActive()
const
178
{
179
Q_D(
const
QWaylandClientExtension);
180
return
d->active;
181
}
182
183
QT_END_NAMESPACE
184
185
#
include
"moc_qwaylandclientextension.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
plugins
platforms
wayland
global
qwaylandclientextension.cpp
Generated on
for Qt by
1.18.0