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
26struct wl_surface;
27struct wl_registry;
28
29QT_BEGIN_NAMESPACE
30
31class QWindow;
32
33namespace QtWaylandClient {
34
35class QWaylandWindow;
36class QWaylandDisplay;
37class QWaylandShellSurface;
38
39class Q_WAYLANDCLIENT_EXPORT QWaylandShellIntegration
40{
41public:
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
57template <typename T>
58class Q_WAYLANDCLIENT_EXPORT QWaylandShellIntegrationTemplate : public QWaylandShellIntegration, public QWaylandClientExtension
59{
60public:
61 QWaylandShellIntegrationTemplate(const int ver) :
62 QWaylandClientExtension(ver)
63 {
64 }
65
66 bool initialize(QWaylandDisplay *) override
67 {
68 QWaylandClientExtension::initialize();
69 return isActive();
70 }
71
72 const struct wl_interface *extensionInterface() const override
73 {
74 return T::interface();
75 }
76
77 void bind(struct ::wl_registry *registry, int id, int ver) override
78 {
79 T* instance = static_cast<T *>(this);
80 // Make sure lowest version is used of the supplied version from the
81 // developer and the version specified in the protocol and also the
82 // compositor version.
83 if (this->version() > T::interface()->version) {
84 qWarning(msg: "Supplied protocol version to QWaylandClientExtensionTemplate is higher than the version of the protocol, using protocol version instead.");
85 }
86 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
87 setVersion(minVersion);
88 instance->init(registry, id, minVersion);
89 }
90};
91
92
93}
94
95QT_END_NAMESPACE
96
97#endif // QWAYLANDSHELLINTEGRATION_H
98

source code of qtwayland/src/client/shellintegration/qwaylandshellintegration_p.h