KWin
Loading...
Searching...
No Matches
wayland_backend.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
6 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10#pragma once
11
12#include <config-kwin.h>
13// KWin
14#include "core/inputbackend.h"
15#include "core/inputdevice.h"
16#include "core/outputbackend.h"
17#include "effect/globals.h"
19// Qt
20#include <QHash>
21#include <QImage>
22#include <QObject>
23#include <QPoint>
24#include <QSize>
25
26struct wl_buffer;
27struct wl_display;
28struct gbm_device;
29
30namespace KWayland
31{
32namespace Client
33{
34class Keyboard;
35class Pointer;
36class PointerSwipeGesture;
37class PointerPinchGesture;
38class RelativePointer;
39class Seat;
40class Surface;
41class Touch;
42}
43}
44
45namespace KWin
46{
47class GraphicsBuffer;
48
49namespace Wayland
50{
51
52class WaylandBackend;
53class WaylandSeat;
54class WaylandOutput;
55class WaylandEglBackend;
56class WaylandDisplay;
57
59{
60 Q_OBJECT
61
62public:
63 WaylandInputDevice(KWayland::Client::Touch *touch, WaylandSeat *seat);
64 WaylandInputDevice(KWayland::Client::Keyboard *keyboard, WaylandSeat *seat);
65 WaylandInputDevice(KWayland::Client::RelativePointer *relativePointer, WaylandSeat *seat);
66 WaylandInputDevice(KWayland::Client::Pointer *pointer, WaylandSeat *seat);
67 ~WaylandInputDevice() override;
68
69 QString sysName() const override;
70 QString name() const override;
71
72 bool isEnabled() const override;
73 void setEnabled(bool enabled) override;
74
75 LEDs leds() const override;
76 void setLeds(LEDs leds) override;
77
78 bool isKeyboard() const override;
79 bool isPointer() const override;
80 bool isTouchpad() const override;
81 bool isTouch() const override;
82 bool isTabletTool() const override;
83 bool isTabletPad() const override;
84 bool isTabletModeSwitch() const override;
85 bool isLidSwitch() const override;
86
87 KWayland::Client::Pointer *nativePointer() const;
88
89private:
90 WaylandSeat *const m_seat;
91
92 std::unique_ptr<KWayland::Client::Keyboard> m_keyboard;
93 std::unique_ptr<KWayland::Client::Touch> m_touch;
94 std::unique_ptr<KWayland::Client::RelativePointer> m_relativePointer;
95 std::unique_ptr<KWayland::Client::Pointer> m_pointer;
96 std::unique_ptr<KWayland::Client::PointerPinchGesture> m_pinchGesture;
97 std::unique_ptr<KWayland::Client::PointerSwipeGesture> m_swipeGesture;
98
99 QSet<quint32> m_pressedKeys;
100};
101
103{
104 Q_OBJECT
105
106public:
107 explicit WaylandInputBackend(WaylandBackend *backend, QObject *parent = nullptr);
108
109 void initialize() override;
110
111private:
112 WaylandBackend *m_backend;
113};
114
115class WaylandSeat : public QObject
116{
117 Q_OBJECT
118public:
119 WaylandSeat(KWayland::Client::Seat *nativeSeat, WaylandBackend *backend);
120 ~WaylandSeat() override;
121
123 {
124 return m_backend;
125 }
126
128 {
129 return m_pointerDevice.get();
130 }
132 {
133 return m_relativePointerDevice.get();
134 }
136 {
137 return m_keyboardDevice.get();
138 }
140 {
141 return m_touchDevice.get();
142 }
143
146
147Q_SIGNALS:
150
151private:
152 void createPointerDevice();
153 void destroyPointerDevice();
154 void createKeyboardDevice();
155 void destroyKeyboardDevice();
156 void createTouchDevice();
157 void destroyTouchDevice();
158
159 KWayland::Client::Seat *m_seat;
160 WaylandBackend *m_backend;
161
162 std::unique_ptr<WaylandInputDevice> m_pointerDevice;
163 std::unique_ptr<WaylandInputDevice> m_relativePointerDevice;
164 std::unique_ptr<WaylandInputDevice> m_keyboardDevice;
165 std::unique_ptr<WaylandInputDevice> m_touchDevice;
166};
167
168class WaylandBuffer : public QObject
169{
170 Q_OBJECT
171
172public:
173 WaylandBuffer(wl_buffer *handle, GraphicsBuffer *graphicsBuffer);
174 ~WaylandBuffer() override;
175
176 wl_buffer *handle() const;
177
178 void lock();
179 void unlock();
180
181Q_SIGNALS:
182 void defunct();
183
184private:
185 GraphicsBuffer *m_graphicsBuffer;
186 wl_buffer *m_handle;
187 bool m_locked = false;
188};
189
191{
192 QString socketName;
193 int outputCount = 1;
194 qreal outputScale = 1;
195 QSize outputSize = QSize(1024, 768);
196};
197
204class KWIN_EXPORT WaylandBackend : public OutputBackend
205{
206 Q_OBJECT
207
208public:
209 explicit WaylandBackend(const WaylandBackendOptions &options, QObject *parent = nullptr);
210 ~WaylandBackend() override;
211 bool initialize() override;
212
213 std::unique_ptr<InputBackend> createInputBackend() override;
214 std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
215 std::unique_ptr<QPainterBackend> createQPainterBackend() override;
216
218 {
219 return m_display.get();
220 }
222 {
223 return m_seat.get();
224 }
225
226 bool supportsPointerLock();
227 void togglePointerLock();
228
229 QList<CompositingType> supportedCompositors() const override;
230
231 WaylandOutput *findOutput(KWayland::Client::Surface *nativeSurface) const;
232 Outputs outputs() const override;
233 QList<WaylandOutput *> waylandOutputs() const
234 {
235 return m_outputs;
236 }
237
238 Output *createVirtualOutput(const QString &name, const QSize &size, double scale) override;
239 void removeVirtualOutput(Output *output) override;
240
241 wl_buffer *importBuffer(GraphicsBuffer *graphicsBuffer);
242
243 gbm_device *gbmDevice() const
244 {
245 return m_gbmDevice;
246 }
247
249 {
250 m_eglBackend = eglBackend;
251 }
252 void setEglDisplay(std::unique_ptr<EglDisplay> &&display);
253 EglDisplay *sceneEglDisplayObject() const override;
254
255Q_SIGNALS:
256 void pointerLockChanged(bool locked);
257
258private:
259 void createOutputs();
260 void destroyOutputs();
261 WaylandOutput *createOutput(const QString &name, const QSize &size, qreal scale);
262
263 WaylandBackendOptions m_options;
264 std::unique_ptr<WaylandDisplay> m_display;
265 std::unique_ptr<WaylandSeat> m_seat;
266 WaylandEglBackend *m_eglBackend = nullptr;
267 QList<WaylandOutput *> m_outputs;
268 bool m_pointerLockRequested = false;
269 FileDescriptor m_drmFileDescriptor;
270 gbm_device *m_gbmDevice = nullptr;
271 std::unique_ptr<EglDisplay> m_eglDisplay;
272 std::map<GraphicsBuffer *, std::unique_ptr<WaylandBuffer>> m_buffers;
273};
274
275} // namespace Wayland
276} // namespace KWin
The Client class encapsulates a window decoration frame.
Class encapsulating all Wayland data structures needed by the Egl backend.
void setEglBackend(WaylandEglBackend *eglBackend)
WaylandDisplay * display() const
QList< WaylandOutput * > waylandOutputs() const
void pointerLockChanged(bool locked)
gbm_device * gbmDevice() const
WaylandBuffer(wl_buffer *handle, GraphicsBuffer *graphicsBuffer)
OpenGL Backend using Egl on a Wayland surface.
WaylandInputBackend(WaylandBackend *backend, QObject *parent=nullptr)
void setEnabled(bool enabled) override
KWayland::Client::Pointer * nativePointer() const
bool isTabletModeSwitch() const override
WaylandInputDevice(KWayland::Client::Touch *touch, WaylandSeat *seat)
WaylandInputDevice * pointerDevice() const
WaylandInputDevice * keyboardDevice() const
void deviceRemoved(WaylandInputDevice *device)
WaylandInputDevice * touchDevice() const
WaylandSeat(KWayland::Client::Seat *nativeSeat, WaylandBackend *backend)
void deviceAdded(WaylandInputDevice *device)
WaylandBackend * backend() const
WaylandInputDevice * relativePointerDevice() const
Options * options
Definition main.cpp:73