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.h
Go to the documentation of this file.
1// Copyright (C) 2017 Erik Larsson.
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
5#ifndef QWAYLANDCLIENTEXTENSION_H
6#define QWAYLANDCLIENTEXTENSION_H
7
8#include <QtCore/QObject>
9#include <QtWaylandClient/qtwaylandclientglobal.h>
10
11struct wl_interface;
12struct wl_registry;
13
14QT_BEGIN_NAMESPACE
15
16namespace QtWaylandClient {
17class QWaylandIntegration;
18}
19
20class QWaylandClientExtensionPrivate;
21class QWaylandClientExtensionTemplatePrivate;
22
23class Q_WAYLANDCLIENT_EXPORT QWaylandClientExtension : public QObject
24{
25 Q_OBJECT
26 Q_DECLARE_PRIVATE(QWaylandClientExtension)
27 Q_PROPERTY(int protocolVersion READ version NOTIFY versionChanged)
28 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
29public:
30 QWaylandClientExtension(const int version);
31 ~QWaylandClientExtension();
32
33 QtWaylandClient::QWaylandIntegration *integration() const;
34 int version() const;
35 bool isActive() const;
36
37 virtual const struct wl_interface *extensionInterface() const = 0;
38 virtual void bind(struct ::wl_registry *registry, int id, int version) = 0;
39protected:
40 void setVersion(const int version);
41Q_SIGNALS:
42 void versionChanged();
43 void activeChanged();
44
45protected Q_SLOTS:
46 void initialize();
47};
48
49
50template<typename T, auto destruct = nullptr>
51class Q_WAYLANDCLIENT_EXPORT QWaylandClientExtensionTemplate : public QWaylandClientExtension
52{
53 Q_DECLARE_PRIVATE(QWaylandClientExtensionTemplate)
54
55public:
56 QWaylandClientExtensionTemplate(const int ver) : QWaylandClientExtension(ver)
57 {
58 if constexpr (destruct != nullptr) {
59 connect(this, &QWaylandClientExtensionTemplate::activeChanged, this, [this] {
60 if (!isActive()) {
61 std::invoke(destruct, static_cast<T *>(this));
62 }
63 });
64 }
65 }
66
67 ~QWaylandClientExtensionTemplate()
68 {
69 if constexpr (destruct != nullptr) {
70 if (isActive()) {
71 std::invoke(destruct, static_cast<T *>(this));
72 }
73 }
74 }
75
76 const struct wl_interface *extensionInterface() const override
77 {
78 return T::interface();
79 }
80
81 void bind(struct ::wl_registry *registry, int id, int ver) override
82 {
83 T* instance = static_cast<T *>(this);
84 // Make sure lowest version is used of the supplied version from the
85 // developer and the version specified in the protocol and also the
86 // compositor version.
87 if (this->version() > T::interface()->version) {
88 qWarning("Supplied protocol version to QWaylandClientExtensionTemplate is higher "
89 "than the version of the protocol, using protocol version instead.\n"
90 " interface.name: %s",
91 T::interface()->name);
92 }
93 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
94 setVersion(minVersion);
95 instance->init(registry, id, minVersion);
96 }
97};
98
99QT_END_NAMESPACE
100
101#endif // QWAYLANDCLIENTEXTENSION_H
A class for implementing custom extensions on the Wayland protocol.
A class for implementing custom extensions on the Wayland protocol.
Combined button and popup list for selecting options.