Debian Codegraph @

src/plugins/platforms/wayland/shellintegration/qwaylandshellintegration_p.h

raw
1 // Copyright (C) 2016 Jolla Ltd
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4 #ifndef QWAYLANDSHELLINTEGRATION_H
5 #define QWAYLANDSHELLINTEGRATION_H
6
7 //
8 // W A R N I N G
9 // -------------
10 //
11 // This file is not part of the Qt API. It exists purely as an
12 // implementation detail. This header file may change from version to
13 // version without notice, or even be removed.
14 //
15 // We mean it.
16 //
17
18 #include <QtWaylandClient/qtwaylandclientglobal.h>
19 #include <QtWaylandClient/qwaylandclientextension.h>
20
21
22
23 #include <QDebug>
24 #include <private/qglobal_p.h>
25
26 struct wl_surface;
27 struct wl_registry;
28
29 QT_BEGIN_NAMESPACE
30
31 class QWindow;
32
33 namespace QtWaylandClient {
34
35 class QWaylandWindow;
36 class QWaylandDisplay;
37 class QWaylandShellSurface;
38
39 class Q_WAYLANDCLIENT_EXPORT QWaylandShellIntegration
40 {
41 public:
42 QWaylandShellIntegration() {}
43 virtual ~QWaylandShellIntegration();
44
45 virtual bool initialize(QWaylandDisplay *display) = 0;
46 virtual QWaylandShellSurface *createShellSurface(QWaylandWindow *window) = 0;
47 virtual void *nativeResourceForWindow(const QByteArray &resource, QWindow *window) {
48 Q_UNUSED(resource);
49 Q_UNUSED(window);
50 return nullptr;
51 }
52
53 static wl_surface *wlSurfaceForWindow(QWaylandWindow *window);
54
55 };
56
57 template <typename T>
58 class Q_WAYLANDCLIENT_EXPORT QWaylandShellIntegrationTemplate
59 : public QWaylandClientExtension,
60 public QWaylandShellIntegration
61 {
62 public:
63 QWaylandShellIntegrationTemplate(const int ver) :
64 QWaylandClientExtension(ver)
65 {
66 }
67
68 bool initialize(QWaylandDisplay *) override
69 {
70 QWaylandClientExtension::initialize();
71 return isActive();
72 }
73
74 const struct wl_interface *extensionInterface() const override
75 {
76 return T::interface();
77 }
78
79 void bind(struct ::wl_registry *registry, int id, int ver) override
80 {
81 T* instance = static_cast<T *>(this);
82 // Make sure lowest version is used of the supplied version from the
83 // developer and the version specified in the protocol and also the
84 // compositor version.
85 if (this->version() > T::interface()->version) {
86 qWarning("Supplied protocol version to QWaylandClientExtensionTemplate is higher "
87 "than the version of the protocol, using protocol version instead.\n"
88 " interface.name: %s",
89 T::interface()->name);
90 }
91 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
92 setVersion(minVersion);
93 instance->init(registry, id, minVersion);
94 }
95 };
96
97
98 }
99
100 QT_END_NAMESPACE
101
102 #endif // QWAYLANDSHELLINTEGRATION_H