1// Copyright (C) 2019 The Qt Company 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 QPLATFORMINTEGRATION_WAYLAND_H
5#define QPLATFORMINTEGRATION_WAYLAND_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 <qpa/qplatformintegration.h>
20#include <qpa/qplatformopenglcontext.h>
21#include <QtCore/QScopedPointer>
22#include <QtCore/QMutex>
23#include <QtCore/private/qglobal_p.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace QtWaylandClient {
28
29class QWaylandBuffer;
30class QWaylandDisplay;
31class QWaylandClientBufferIntegration;
32class QWaylandServerBufferIntegration;
33class QWaylandShellIntegration;
34class QWaylandInputDeviceIntegration;
35class QWaylandInputDevice;
36class QWaylandScreen;
37class QWaylandCursor;
38class QWaylandPlatformServices;
39
40class Q_WAYLANDCLIENT_EXPORT QWaylandIntegration : public QPlatformIntegration
41#if QT_CONFIG(opengl)
42 , public QNativeInterface::Private::QEGLIntegration
43#endif
44{
45public:
46 QWaylandIntegration(const QString &platformName);
47 ~QWaylandIntegration() override;
48
49 static QWaylandIntegration *instance() { return sInstance; }
50
51 bool init();
52
53 bool hasCapability(QPlatformIntegration::Capability cap) const override;
54 QPlatformWindow *createPlatformWindow(QWindow *window) const override;
55#if QT_CONFIG(opengl)
56 QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
57 QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override;
58#endif
59 QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override;
60
61 QAbstractEventDispatcher *createEventDispatcher() const override;
62 void initialize() override;
63
64 QPlatformFontDatabase *fontDatabase() const override;
65
66 QPlatformNativeInterface *nativeInterface() const override;
67#if QT_CONFIG(clipboard)
68 QPlatformClipboard *clipboard() const override;
69#endif
70#if QT_CONFIG(draganddrop)
71 QPlatformDrag *drag() const override;
72#endif
73 QPlatformInputContext *inputContext() const override;
74
75 QVariant styleHint(StyleHint hint) const override;
76
77#if QT_CONFIG(accessibility)
78 QPlatformAccessibility *accessibility() const override;
79#endif
80
81 QPlatformServices *services() const override;
82
83 QWaylandDisplay *display() const;
84
85 Qt::KeyboardModifiers queryKeyboardModifiers() const override;
86
87 QList<int> possibleKeys(const QKeyEvent *event) const override;
88
89 QStringList themeNames() const override;
90
91 QPlatformTheme *createPlatformTheme(const QString &name) const override;
92
93#if QT_CONFIG(vulkan)
94 QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const override;
95#endif
96
97 void setApplicationBadge(qint64 number) override;
98 void beep() const override;
99
100 virtual QWaylandInputDevice *createInputDevice(QWaylandDisplay *display, int version, uint32_t id) const;
101 virtual QWaylandScreen *createPlatformScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id) const;
102 virtual QWaylandCursor *createPlatformCursor(QWaylandDisplay *display) const;
103
104 virtual QWaylandClientBufferIntegration *clientBufferIntegration() const;
105 virtual QWaylandServerBufferIntegration *serverBufferIntegration() const;
106 virtual QWaylandShellIntegration *shellIntegration() const;
107
108 void reconfigureInputContext();
109
110protected:
111 // NOTE: mDisplay *must* be destructed after mDrag and mClientBufferIntegration
112 // and mShellIntegration.
113 // Do not move this definition into the private section at the bottom.
114 QScopedPointer<QWaylandDisplay> mDisplay;
115
116protected:
117 void reset();
118 virtual QPlatformNativeInterface *createPlatformNativeInterface();
119
120 QScopedPointer<QWaylandClientBufferIntegration> mClientBufferIntegration;
121 QScopedPointer<QWaylandServerBufferIntegration> mServerBufferIntegration;
122 QScopedPointer<QWaylandShellIntegration> mShellIntegration;
123 QScopedPointer<QWaylandInputDeviceIntegration> mInputDeviceIntegration;
124
125 QScopedPointer<QPlatformInputContext> mInputContext;
126
127private:
128 void initializePlatform();
129 void initializeClientBufferIntegration();
130 void initializeServerBufferIntegration();
131 void initializeShellIntegration();
132 void initializeInputDeviceIntegration();
133 QWaylandShellIntegration *createShellIntegration(const QString& interfaceName);
134
135 const QString mPlatformName;
136 QScopedPointer<QPlatformFontDatabase> mFontDb;
137#if QT_CONFIG(clipboard)
138 QScopedPointer<QPlatformClipboard> mClipboard;
139#endif
140#if QT_CONFIG(draganddrop)
141 QScopedPointer<QPlatformDrag> mDrag;
142#endif
143 QScopedPointer<QPlatformNativeInterface> mNativeInterface;
144#if QT_CONFIG(accessibility)
145 mutable QScopedPointer<QPlatformAccessibility> mAccessibility;
146#endif
147 QScopedPointer<QWaylandPlatformServices> mPlatformServices;
148 QMutex mClientBufferInitLock;
149 bool mClientBufferIntegrationInitialized = false;
150 bool mServerBufferIntegrationInitialized = false;
151 bool mShellIntegrationInitialized = false;
152
153 static QWaylandIntegration *sInstance;
154
155 friend class QWaylandDisplay;
156};
157
158}
159
160QT_END_NAMESPACE
161
162#endif
163

source code of qtbase/src/plugins/platforms/wayland/qwaylandintegration_p.h