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(int version, QObject *parent);
31 explicit 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>
53{
55
56public:
59 {
60 if constexpr (destruct != nullptr) {
62 if (!isActive()) {
63 std::invoke(destruct, static_cast<T *>(this));
64 }
65 });
66 }
67 }
68
70 {
71 if constexpr (destruct != nullptr) {
72 if (isActive()) {
73 std::invoke(destruct, static_cast<T *>(this));
74 }
75 }
76 }
77
79 {
80 return T::interface();
81 }
82
83 void bind(struct ::wl_registry *registry, int id, int ver) override
84 {
85 T* instance = static_cast<T *>(this);
86 // Make sure lowest version is used of the supplied version from the
87 // developer and the version specified in the protocol and also the
88 // compositor version.
89 if (this->version() > T::interface()->version) {
90 qWarning("Supplied protocol version to QWaylandClientExtensionTemplate is higher "
91 "than the version of the protocol, using protocol version instead.\n"
92 " interface.name: %s",
93 T::interface()->name);
94 }
95 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
98 }
99};
100
101QT_END_NAMESPACE
102
103#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.