Debian Codegraph @

wayland/qtwayland-dev/5.11.3/QtWaylandClient/private/qwaylandclientextension.h

raw symbols SCIP
1 // Copyright (C) 2017 Erik Larsson.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5 #ifndef QWAYLANDCLIENTEXTENSION_H
6 #define QWAYLANDCLIENTEXTENSION_H
7
8 #include <QObject>
9 #include <QtWaylandClient/qtwaylandclientglobal.h>
10
11 struct wl_interface;
12 struct wl_registry;
13
14 QT_BEGIN_NAMESPACE
15
16 namespace QtWaylandClient {
17 class QWaylandIntegration;
18 }
19
20 class QWaylandClientExtensionPrivate;
21 class QWaylandClientExtensionTemplatePrivate;
22
23 class Q_WAYLAND_CLIENT_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)
29 public:
30 QWaylandClientExtension(const int version);
31
32 QtWaylandClient::QWaylandIntegration *integration() const;
33 int version() const;
34 bool isActive() const;
35
36 virtual const struct wl_interface *extensionInterface() const = 0;
37 virtual void bind(struct ::wl_registry *registry, int id, int version) = 0;
38 protected:
39 void setVersion(const int version);
40 Q_SIGNALS:
41 void versionChanged();
42 void activeChanged();
43
44 private Q_SLOTS:
45 void addRegistryListener();
46 };
47
48 template <typename T>
49 class Q_WAYLAND_CLIENT_EXPORT QWaylandClientExtensionTemplate : public QWaylandClientExtension
50 {
51 Q_DECLARE_PRIVATE(QWaylandClientExtensionTemplate)
52 public:
53 QWaylandClientExtensionTemplate(const int ver) :
54 QWaylandClientExtension(ver)
55 {
56 }
57
58 const struct wl_interface *extensionInterface() const override
59 {
60 return T::interface();
61 }
62
63 void bind(struct ::wl_registry *registry, int id, int ver) override
64 {
65 T* instance = static_cast<T *>(this);
66 // Make sure lowest version is used of the supplied version from the
67 // developer and the version specified in the protocol and also the
68 // compositor version.
69 if (this->version() > T::interface()->version) {
70 qWarning("Supplied protocol version to QWaylandClientExtensionTemplate is higher than the version of the protocol, using protocol version instead.");
71 }
72 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
73 setVersion(minVersion);
74 instance->init(registry, id, minVersion);
75 }
76 };
77
78 QT_END_NAMESPACE
79
80 #endif // QWAYLANDCLIENTEXTENSION_H