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, QObject *parent);
31 QWaylandClientExtension(const int version);
32 ~QWaylandClientExtension();
33
34 QtWaylandClient::QWaylandIntegration *integration() const;
35 int version() const;
36 bool isActive() const;
37
38 virtual const struct wl_interface *extensionInterface() const = 0;
39 virtual void bind(struct ::wl_registry *registry, int id, int version) = 0;
40protected:
41 void setVersion(const int version);
42Q_SIGNALS:
43 void versionChanged();
44 void activeChanged();
45
46protected Q_SLOTS:
47 void initialize();
48};
49
50
51template<typename T, auto destruct = nullptr>
52class Q_WAYLANDCLIENT_EXPORT QWaylandClientExtensionTemplate : public QWaylandClientExtension
53{
54 Q_DECLARE_PRIVATE(QWaylandClientExtensionTemplate)
55
56public:
57 QWaylandClientExtensionTemplate(const int ver, QObject *parent)
58 : QWaylandClientExtension(ver, parent)
59 {
60 if constexpr (destruct != nullptr) {
61 connect(this, &QWaylandClientExtensionTemplate::activeChanged, this, [this] {
62 if (!isActive()) {
63 std::invoke(destruct, static_cast<T *>(this));
64 }
65 });
66 }
67 }
68
69 QWaylandClientExtensionTemplate(const int ver)
70 : QWaylandClientExtensionTemplate(ver, nullptr)
71 {
72 }
73
74 ~QWaylandClientExtensionTemplate()
75 {
76 if constexpr (destruct != nullptr) {
77 if (isActive()) {
78 std::invoke(destruct, static_cast<T *>(this));
79 }
80 }
81 }
82
83 const struct wl_interface *extensionInterface() const override
84 {
85 return T::interface();
86 }
87
88 void bind(struct ::wl_registry *registry, int id, int ver) override
89 {
90 T* instance = static_cast<T *>(this);
91 // Make sure lowest version is used of the supplied version from the
92 // developer and the version specified in the protocol and also the
93 // compositor version.
94 if (this->version() > T::interface()->version) {
95 qWarning("Supplied protocol version to QWaylandClientExtensionTemplate is higher "
96 "than the version of the protocol, using protocol version instead.\n"
97 " interface.name: %s",
98 T::interface()->name);
99 }
100 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
101 setVersion(minVersion);
102 instance->init(registry, id, minVersion);
103 }
104};
105
106QT_END_NAMESPACE
107
108#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.