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