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
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
8#include <QtWaylandClient/private/qwaylanddisplay_p.h>
9#include <QtWaylandClient/private/qwaylandintegration_p.h>
10
12
13using RegistryGlobal = QtWaylandClient::QWaylandDisplay::RegistryGlobal;
14using namespace Qt::StringLiterals;
15
16QWaylandClientExtensionPrivate::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
25void 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
35void 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*/
75void 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 Constructs the client extension and sets its version to \a ver.
96*/
97QWaylandClientExtension::QWaylandClientExtension(const int ver)
98 : QObject(*new QWaylandClientExtensionPrivate())
99{
100 Q_D(QWaylandClientExtension);
101 d->version = ver;
102 auto display = d->waylandIntegration->display();
103 QObjectPrivate::connect(display, &QtWaylandClient::QWaylandDisplay::globalAdded, d,
104 &QWaylandClientExtensionPrivate::globalAdded);
105 QObjectPrivate::connect(display, &QtWaylandClient::QWaylandDisplay::globalRemoved, d,
106 &QWaylandClientExtensionPrivate::globalRemoved);
107 // This function uses virtual functions and we don't want it to be called from the constructor.
108 QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection);
109}
110
111/*!
112 Destroys the client extension.
113*/
114QWaylandClientExtension::~QWaylandClientExtension()
115{
116}
117
118/*!
119 \internal
120*/
121QtWaylandClient::QWaylandIntegration *QWaylandClientExtension::integration() const
122{
123 Q_D(const QWaylandClientExtension);
124 return d->waylandIntegration;
125}
126
127/*!
128 \fn const struct wl_interface *extensionInterface() const
129 \internal
130*/
131
132/*!
133 \fn void bind(struct ::wl_registry *registry, int id, int version)
134 \internal
135*/
136
137/*!
138 \property QWaylandClientExtension::protocolVersion
139 \brief The version of the protocol.
140
141 This property holds the version of the protocol that has been requested.
142*/
143int QWaylandClientExtension::version() const
144{
145 Q_D(const QWaylandClientExtension);
146 return d->version;
147}
148
149void QWaylandClientExtension::setVersion(const int ver)
150{
151 Q_D(QWaylandClientExtension);
152 if (d->version != ver) {
153 d->version = ver;
154 emit versionChanged();
155 }
156}
157
158/*!
159 \property QWaylandClientExtension::active
160 \brief The active state of the extension.
161
162 Set to \c true if the extension is currently active. Otherwise this
163 property is \c false.
164*/
165
166bool QWaylandClientExtension::isActive() const
167{
168 Q_D(const QWaylandClientExtension);
169 return d->active;
170}
171
172QT_END_NAMESPACE
173
174#include "moc_qwaylandclientextension.cpp"
Combined button and popup list for selecting options.