1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWAYLANDEXTENSION_H
5#define QWAYLANDEXTENSION_H
6
7#include <QtWaylandCompositor/qtwaylandcompositorglobal.h>
8#include <QtWaylandCompositor/qtwaylandqmlinclude.h>
9
10#include <QtCore/QObject>
11
12struct wl_interface;
13
14QT_BEGIN_NAMESPACE
15
16class QWaylandCompositor;
17class QWaylandCompositorExtension;
18class QWaylandCompositorExtensionPrivate;
19
20class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandObject : public QObject
21{
22 Q_OBJECT
23public:
24 ~QWaylandObject() override;
25
26 QWaylandCompositorExtension *extension(const QByteArray &name);
27 QWaylandCompositorExtension *extension(const wl_interface *interface);
28 QList<QWaylandCompositorExtension *> extensions() const;
29 void addExtension(QWaylandCompositorExtension *extension);
30 void removeExtension(QWaylandCompositorExtension *extension);
31
32protected:
33 QWaylandObject(QObject *parent = nullptr);
34 QWaylandObject(QObjectPrivate &d, QObject *parent = nullptr);
35 QList<QWaylandCompositorExtension *> extension_vector;
36};
37
38class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositorExtension : public QWaylandObject
39{
40 Q_OBJECT
41 Q_DECLARE_PRIVATE(QWaylandCompositorExtension)
42 QML_NAMED_ELEMENT(WaylandExtension)
43 QML_ADDED_IN_VERSION(1, 0)
44 QML_UNCREATABLE("")
45public:
46 QWaylandCompositorExtension();
47 QWaylandCompositorExtension(QWaylandObject *container);
48 ~QWaylandCompositorExtension() override;
49
50 QWaylandObject *extensionContainer() const;
51 void setExtensionContainer(QWaylandObject *container);
52
53 virtual void initialize();
54 bool isInitialized() const;
55
56 virtual const struct wl_interface *extensionInterface() const = 0;
57
58protected:
59 QWaylandCompositorExtension(QWaylandCompositorExtensionPrivate &dd);
60 QWaylandCompositorExtension(QWaylandObject *container, QWaylandCompositorExtensionPrivate &dd);
61
62 bool event(QEvent *event) override;
63};
64
65template <typename T>
66class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositorExtensionTemplate : public QWaylandCompositorExtension
67{
68public:
69 QWaylandCompositorExtensionTemplate()
70 : QWaylandCompositorExtension()
71 { }
72
73 QWaylandCompositorExtensionTemplate(QWaylandObject *container)
74 : QWaylandCompositorExtension(container)
75 { }
76
77 const struct wl_interface *extensionInterface() const override
78 {
79 return T::interface();
80 }
81
82 static T *findIn(QWaylandObject *container)
83 {
84 if (!container) return nullptr;
85 return qobject_cast<T *>(container->extension(T::interfaceName()));
86 }
87
88protected:
89 QWaylandCompositorExtensionTemplate(QWaylandCompositorExtensionPrivate &dd)
90 : QWaylandCompositorExtension(dd)
91 { }
92
93 QWaylandCompositorExtensionTemplate(QWaylandObject *container, QWaylandCompositorExtensionPrivate &dd)
94 : QWaylandCompositorExtension(container,dd)
95 { }
96};
97
98QT_END_NAMESPACE
99
100#endif
101

source code of qtwayland/src/compositor/global/qwaylandcompositorextension.h