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

source code of qtwayland/src/client/qwaylandintegration_p.h