Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/wayland/wayland_backend.h
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> | 5 | Copyright 2019 Roman Gilg <subdiff@gmail.com> | ||
6 | Copyright 2013 Martin Gräßlin <mgraesslin@kde.org> | ||||
6 | 7 | | |||
7 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | 11 | (at your option) any later version. | ||
11 | 12 | | |||
12 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 24 Lines | |||||
38 | 39 | | |||
39 | namespace KWayland | 40 | namespace KWayland | ||
40 | { | 41 | { | ||
41 | namespace Client | 42 | namespace Client | ||
42 | { | 43 | { | ||
43 | class Buffer; | 44 | class Buffer; | ||
44 | class ShmPool; | 45 | class ShmPool; | ||
45 | class Compositor; | 46 | class Compositor; | ||
46 | class ConfinedPointer; | | |||
47 | class ConnectionThread; | 47 | class ConnectionThread; | ||
48 | class EventQueue; | 48 | class EventQueue; | ||
49 | class Keyboard; | 49 | class Keyboard; | ||
50 | class Pointer; | 50 | class Pointer; | ||
51 | class PointerConstraints; | 51 | class PointerConstraints; | ||
52 | class PointerGestures; | 52 | class PointerGestures; | ||
53 | class PointerSwipeGesture; | 53 | class PointerSwipeGesture; | ||
54 | class PointerPinchGesture; | 54 | class PointerPinchGesture; | ||
55 | class Registry; | 55 | class Registry; | ||
56 | class RelativePointer; | ||||
57 | class RelativePointerManager; | ||||
56 | class Seat; | 58 | class Seat; | ||
57 | class Shell; | 59 | class Shell; | ||
58 | class ShellSurface; | 60 | class SubCompositor; | ||
61 | class SubSurface; | ||||
59 | class Surface; | 62 | class Surface; | ||
60 | class Touch; | 63 | class Touch; | ||
61 | class XdgShell; | 64 | class XdgShell; | ||
62 | class XdgShellSurface; | | |||
63 | } | 65 | } | ||
64 | } | 66 | } | ||
65 | 67 | | |||
66 | namespace KWin | 68 | namespace KWin | ||
67 | { | 69 | { | ||
68 | class WaylandCursorTheme; | 70 | class WaylandCursorTheme; | ||
69 | 71 | | |||
70 | namespace Wayland | 72 | namespace Wayland | ||
71 | { | 73 | { | ||
72 | 74 | | |||
73 | class WaylandBackend; | 75 | class WaylandBackend; | ||
74 | class WaylandSeat; | 76 | class WaylandSeat; | ||
77 | class WaylandOutput; | ||||
78 | | ||||
79 | class WaylandCursor : public QObject | ||||
80 | { | ||||
81 | Q_OBJECT | ||||
82 | public: | ||||
83 | explicit WaylandCursor(WaylandBackend *backend); | ||||
84 | virtual ~WaylandCursor(); | ||||
85 | | ||||
86 | virtual void init(); | ||||
87 | virtual void move(const QPointF &globalPosition) { | ||||
88 | Q_UNUSED(globalPosition) | ||||
89 | } | ||||
90 | | ||||
91 | void installImage(); | ||||
92 | | ||||
93 | protected: | ||||
94 | void resetSurface(); | ||||
95 | virtual void doInstallImage(wl_buffer *image, const QSize &size); | ||||
96 | void drawSurface(wl_buffer *image, const QSize &size); | ||||
97 | | ||||
98 | KWayland::Client::Surface *surface() const { | ||||
99 | return m_surface; | ||||
100 | } | ||||
101 | WaylandBackend *backend() const { | ||||
102 | return m_backend; | ||||
103 | } | ||||
104 | | ||||
105 | private: | ||||
106 | WaylandBackend *m_backend; | ||||
107 | KWayland::Client::Pointer *m_pointer; | ||||
108 | KWayland::Client::Surface *m_surface = nullptr; | ||||
109 | }; | ||||
110 | | ||||
111 | class WaylandSubSurfaceCursor : public WaylandCursor | ||||
112 | { | ||||
113 | Q_OBJECT | ||||
114 | public: | ||||
115 | explicit WaylandSubSurfaceCursor(WaylandBackend *backend); | ||||
116 | virtual ~WaylandSubSurfaceCursor(); | ||||
117 | | ||||
118 | void init() override; | ||||
119 | | ||||
120 | void move(const QPointF &globalPosition) override; | ||||
121 | | ||||
122 | private: | ||||
123 | void changeOutput(WaylandOutput *output); | ||||
124 | void doInstallImage(wl_buffer *image, const QSize &size) override; | ||||
125 | void createSubSurface(); | ||||
126 | | ||||
127 | QPointF absoluteToRelativePosition(const QPointF &position); | ||||
128 | WaylandOutput *m_output = nullptr; | ||||
129 | KWayland::Client::SubSurface *m_subSurface = nullptr; | ||||
130 | }; | ||||
75 | 131 | | |||
76 | class WaylandSeat : public QObject | 132 | class WaylandSeat : public QObject | ||
77 | { | 133 | { | ||
78 | Q_OBJECT | 134 | Q_OBJECT | ||
79 | public: | 135 | public: | ||
80 | WaylandSeat(wl_seat *seat, WaylandBackend *backend); | 136 | WaylandSeat(wl_seat *seat, WaylandBackend *backend); | ||
81 | virtual ~WaylandSeat(); | 137 | virtual ~WaylandSeat(); | ||
82 | 138 | | |||
83 | void installCursorImage(wl_buffer *image, const QSize &size, const QPoint &hotspot); | | |||
84 | void installCursorImage(const QImage &image, const QPoint &hotspot); | | |||
85 | void setInstallCursor(bool install); | | |||
86 | bool isInstallCursor() const { | | |||
87 | return m_installCursor; | | |||
88 | } | | |||
89 | | ||||
90 | KWayland::Client::Pointer *pointer() const { | 139 | KWayland::Client::Pointer *pointer() const { | ||
91 | return m_pointer; | 140 | return m_pointer; | ||
92 | } | 141 | } | ||
93 | 142 | | |||
94 | void installGesturesInterface(KWayland::Client::PointerGestures *gesturesInterface) { | 143 | void installGesturesInterface(KWayland::Client::PointerGestures *gesturesInterface) { | ||
95 | m_gesturesInterface = gesturesInterface; | 144 | m_gesturesInterface = gesturesInterface; | ||
96 | setupPointerGestures(); | 145 | setupPointerGestures(); | ||
97 | } | 146 | } | ||
98 | 147 | | |||
99 | private: | 148 | private: | ||
100 | void destroyPointer(); | 149 | void destroyPointer(); | ||
101 | void destroyKeyboard(); | 150 | void destroyKeyboard(); | ||
102 | void destroyTouch(); | 151 | void destroyTouch(); | ||
103 | void setupPointerGestures(); | 152 | void setupPointerGestures(); | ||
153 | | ||||
104 | KWayland::Client::Seat *m_seat; | 154 | KWayland::Client::Seat *m_seat; | ||
105 | KWayland::Client::Pointer *m_pointer; | 155 | KWayland::Client::Pointer *m_pointer; | ||
106 | KWayland::Client::Keyboard *m_keyboard; | 156 | KWayland::Client::Keyboard *m_keyboard; | ||
107 | KWayland::Client::Touch *m_touch; | 157 | KWayland::Client::Touch *m_touch; | ||
108 | KWayland::Client::Surface *m_cursor; | | |||
109 | KWayland::Client::PointerGestures *m_gesturesInterface = nullptr; | 158 | KWayland::Client::PointerGestures *m_gesturesInterface = nullptr; | ||
110 | KWayland::Client::PointerPinchGesture *m_pinchGesture = nullptr; | 159 | KWayland::Client::PointerPinchGesture *m_pinchGesture = nullptr; | ||
111 | KWayland::Client::PointerSwipeGesture *m_swipeGesture = nullptr; | 160 | KWayland::Client::PointerSwipeGesture *m_swipeGesture = nullptr; | ||
161 | | ||||
112 | uint32_t m_enteredSerial; | 162 | uint32_t m_enteredSerial; | ||
163 | | ||||
113 | WaylandBackend *m_backend; | 164 | WaylandBackend *m_backend; | ||
114 | bool m_installCursor; | | |||
115 | }; | 165 | }; | ||
116 | 166 | | |||
117 | /** | 167 | /** | ||
118 | * @brief Class encapsulating all Wayland data structures needed by the Egl backend. | 168 | * @brief Class encapsulating all Wayland data structures needed by the Egl backend. | ||
119 | * | 169 | * | ||
120 | * It creates the connection to the Wayland Compositor, sets up the registry and creates | 170 | * It creates the connection to the Wayland Compositor, sets up the registry and creates | ||
121 | * the Wayland surface and its shell mapping. | 171 | * the Wayland output surfaces and its shell mappings. | ||
122 | **/ | 172 | */ | ||
123 | class KWIN_EXPORT WaylandBackend : public Platform | 173 | class KWIN_EXPORT WaylandBackend : public Platform | ||
124 | { | 174 | { | ||
125 | Q_OBJECT | 175 | Q_OBJECT | ||
126 | Q_INTERFACES(KWin::Platform) | 176 | Q_INTERFACES(KWin::Platform) | ||
127 | Q_PLUGIN_METADATA(IID "org.kde.kwin.Platform" FILE "wayland.json") | 177 | Q_PLUGIN_METADATA(IID "org.kde.kwin.Platform" FILE "wayland.json") | ||
128 | public: | 178 | public: | ||
129 | explicit WaylandBackend(QObject *parent = nullptr); | 179 | explicit WaylandBackend(QObject *parent = nullptr); | ||
130 | virtual ~WaylandBackend(); | 180 | virtual ~WaylandBackend(); | ||
131 | void init() override; | 181 | void init() override; | ||
132 | wl_display *display(); | 182 | wl_display *display(); | ||
133 | KWayland::Client::Compositor *compositor(); | 183 | KWayland::Client::Compositor *compositor(); | ||
184 | KWayland::Client::SubCompositor *subCompositor(); | ||||
134 | KWayland::Client::ShmPool *shmPool(); | 185 | KWayland::Client::ShmPool *shmPool(); | ||
135 | 186 | | |||
136 | KWayland::Client::Surface *surface() const; | | |||
137 | QSize shellSurfaceSize() const; | | |||
138 | | ||||
139 | Screens *createScreens(QObject *parent = nullptr) override; | 187 | Screens *createScreens(QObject *parent = nullptr) override; | ||
140 | OpenGLBackend *createOpenGLBackend() override; | 188 | OpenGLBackend *createOpenGLBackend() override; | ||
141 | QPainterBackend *createQPainterBackend() override; | 189 | QPainterBackend *createQPainterBackend() override; | ||
142 | 190 | | |||
143 | QSize screenSize() const override { | 191 | void flush(); | ||
144 | return shellSurfaceSize(); | 192 | | ||
193 | WaylandSeat *seat() const { | ||||
194 | return m_seat; | ||||
195 | } | ||||
196 | KWayland::Client::PointerConstraints *pointerConstraints() const { | ||||
197 | return m_pointerConstraints; | ||||
145 | } | 198 | } | ||
146 | 199 | | |||
147 | void flush(); | 200 | void pointerMotionRelativeToOutput(const QPointF &position, quint32 time); | ||
148 | 201 | | |||
149 | void togglePointerConfinement(); | 202 | bool supportsPointerLock(); | ||
203 | void togglePointerLock(); | ||||
204 | bool pointerIsLocked(); | ||||
150 | 205 | | |||
151 | QVector<CompositingType> supportedCompositors() const override; | 206 | QVector<CompositingType> supportedCompositors() const override; | ||
152 | 207 | | |||
208 | void checkBufferSwap(); | ||||
209 | | ||||
210 | WaylandOutput* getOutputAt(const QPointF globalPosition); | ||||
211 | Outputs outputs() const override; | ||||
212 | Outputs enabledOutputs() const override; | ||||
213 | QVector<WaylandOutput*> waylandOutputs() const { | ||||
214 | return m_outputs; | ||||
215 | } | ||||
216 | | ||||
153 | Q_SIGNALS: | 217 | Q_SIGNALS: | ||
154 | void shellSurfaceSizeChanged(const QSize &size); | 218 | void outputAdded(WaylandOutput *output); | ||
219 | void outputRemoved(WaylandOutput *output); | ||||
220 | | ||||
155 | void systemCompositorDied(); | 221 | void systemCompositorDied(); | ||
156 | void connectionFailed(); | 222 | void connectionFailed(); | ||
223 | | ||||
224 | void pointerLockSupportedChanged(); | ||||
225 | void pointerLockChanged(bool locked); | ||||
226 | | ||||
157 | private: | 227 | private: | ||
158 | void initConnection(); | 228 | void initConnection(); | ||
159 | void createSurface(); | 229 | void createOutputs(); | ||
160 | template <class T> | 230 | | ||
161 | void setupSurface(T *surface); | 231 | void updateScreenSize(WaylandOutput *output); | ||
162 | void updateWindowTitle(); | 232 | void relativeMotionHandler(const QSizeF &delta, const QSizeF &deltaNonAccelerated, quint64 timestamp); | ||
233 | | ||||
163 | wl_display *m_display; | 234 | wl_display *m_display; | ||
164 | KWayland::Client::EventQueue *m_eventQueue; | 235 | KWayland::Client::EventQueue *m_eventQueue; | ||
165 | KWayland::Client::Registry *m_registry; | 236 | KWayland::Client::Registry *m_registry; | ||
166 | KWayland::Client::Compositor *m_compositor; | 237 | KWayland::Client::Compositor *m_compositor; | ||
238 | KWayland::Client::SubCompositor *m_subCompositor; | ||||
167 | KWayland::Client::Shell *m_shell; | 239 | KWayland::Client::Shell *m_shell; | ||
168 | KWayland::Client::Surface *m_surface; | | |||
169 | KWayland::Client::ShellSurface *m_shellSurface; | | |||
170 | KWayland::Client::XdgShell *m_xdgShell = nullptr; | 240 | KWayland::Client::XdgShell *m_xdgShell = nullptr; | ||
171 | KWayland::Client::XdgShellSurface *m_xdgShellSurface = nullptr; | | |||
172 | QScopedPointer<WaylandSeat> m_seat; | | |||
173 | KWayland::Client::ShmPool *m_shm; | 241 | KWayland::Client::ShmPool *m_shm; | ||
174 | KWayland::Client::ConnectionThread *m_connectionThreadObject; | 242 | KWayland::Client::ConnectionThread *m_connectionThreadObject; | ||
243 | | ||||
244 | WaylandSeat *m_seat = nullptr; | ||||
245 | KWayland::Client::RelativePointer *m_relativePointer = nullptr; | ||||
246 | KWayland::Client::RelativePointerManager *m_relativePointerManager = nullptr; | ||||
175 | KWayland::Client::PointerConstraints *m_pointerConstraints = nullptr; | 247 | KWayland::Client::PointerConstraints *m_pointerConstraints = nullptr; | ||
176 | KWayland::Client::ConfinedPointer *m_pointerConfinement = nullptr; | 248 | | ||
177 | QThread *m_connectionThread; | 249 | QThread *m_connectionThread; | ||
178 | bool m_isPointerConfined = false; | 250 | QVector<WaylandOutput*> m_outputs; | ||
251 | | ||||
252 | WaylandCursor *m_waylandCursor = nullptr; | ||||
253 | | ||||
254 | bool m_pointerLockRequested = false; | ||||
179 | }; | 255 | }; | ||
180 | 256 | | |||
181 | inline | 257 | inline | ||
182 | wl_display *WaylandBackend::display() | 258 | wl_display *WaylandBackend::display() | ||
183 | { | 259 | { | ||
184 | return m_display; | 260 | return m_display; | ||
185 | } | 261 | } | ||
186 | 262 | | |||
187 | inline | 263 | inline | ||
188 | KWayland::Client::Compositor *WaylandBackend::compositor() | 264 | KWayland::Client::Compositor *WaylandBackend::compositor() | ||
189 | { | 265 | { | ||
190 | return m_compositor; | 266 | return m_compositor; | ||
191 | } | 267 | } | ||
192 | 268 | | |||
193 | inline | 269 | inline | ||
194 | KWayland::Client::ShmPool* WaylandBackend::shmPool() | 270 | KWayland::Client::SubCompositor *WaylandBackend::subCompositor() | ||
195 | { | 271 | { | ||
196 | return m_shm; | 272 | return m_subCompositor; | ||
197 | } | 273 | } | ||
198 | 274 | | |||
199 | inline | 275 | inline | ||
200 | KWayland::Client::Surface *WaylandBackend::surface() const | 276 | KWayland::Client::ShmPool* WaylandBackend::shmPool() | ||
201 | { | 277 | { | ||
202 | return m_surface; | 278 | return m_shm; | ||
203 | } | 279 | } | ||
204 | 280 | | |||
205 | } // namespace Wayland | 281 | } // namespace Wayland | ||
206 | } // namespace KWin | 282 | } // namespace KWin | ||
207 | 283 | | |||
208 | #endif // KWIN_WAYLAND_BACKEND_H | 284 | #endif // KWIN_WAYLAND_BACKEND_H |