Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandcursor.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2023 David Edmundson <davidedmundson@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
6
10
11#include <QtGui/private/qguiapplication_p.h>
12#include <qpa/qplatformtheme.h>
13
14#include <QtGui/QImageReader>
15#include <QDebug>
16
17#include <wayland-cursor.h>
18
19#include <algorithm>
20
21QT_BEGIN_NAMESPACE
22
23namespace QtWaylandClient {
24
26{
29
30 if (!theme) {
31 qCWarning(lcQpaWayland) << "Could not load cursor theme" << themeName << "size" << size;
32 return nullptr;
33 }
34
36}
37
39{
41}
42
44{
45 if (struct wl_cursor *cursor = m_cursors[shape])
46 return cursor;
47
48 static Q_CONSTEXPR struct ShapeAndName {
50 const char name[33];
51 } cursorNamesMap[] = {
52 {ArrowCursor, "left_ptr"},
53 {ArrowCursor, "default"},
54 {ArrowCursor, "top_left_arrow"},
55 {ArrowCursor, "left_arrow"},
56
57 {UpArrowCursor, "up_arrow"},
58
59 {CrossCursor, "cross"},
60
61 {WaitCursor, "wait"},
62 {WaitCursor, "watch"},
63 {WaitCursor, "0426c94ea35c87780ff01dc239897213"},
64
65 {IBeamCursor, "ibeam"},
66 {IBeamCursor, "text"},
67 {IBeamCursor, "xterm"},
68
69 {SizeVerCursor, "size_ver"},
70 {SizeVerCursor, "ns-resize"},
71 {SizeVerCursor, "v_double_arrow"},
72 {SizeVerCursor, "00008160000006810000408080010102"},
73
74 {SizeHorCursor, "size_hor"},
75 {SizeHorCursor, "ew-resize"},
76 {SizeHorCursor, "h_double_arrow"},
77 {SizeHorCursor, "028006030e0e7ebffc7f7070c0600140"},
78
79 {SizeBDiagCursor, "size_bdiag"},
80 {SizeBDiagCursor, "nesw-resize"},
81 {SizeBDiagCursor, "50585d75b494802d0151028115016902"},
82 {SizeBDiagCursor, "fcf1c3c7cd4491d801f1e1c78f100000"},
83
84 {SizeFDiagCursor, "size_fdiag"},
85 {SizeFDiagCursor, "nwse-resize"},
86 {SizeFDiagCursor, "38c5dff7c7b8962045400281044508d2"},
87 {SizeFDiagCursor, "c7088f0f3e6c8088236ef8e1e3e70000"},
88
89 {SizeAllCursor, "size_all"},
90
91 {BlankCursor, "blank"},
92
93 {SplitVCursor, "split_v"},
94 {SplitVCursor, "row-resize"},
95 {SplitVCursor, "sb_v_double_arrow"},
96 {SplitVCursor, "2870a09082c103050810ffdffffe0204"},
97 {SplitVCursor, "c07385c7190e701020ff7ffffd08103c"},
98
99 {SplitHCursor, "split_h"},
100 {SplitHCursor, "col-resize"},
101 {SplitHCursor, "sb_h_double_arrow"},
102 {SplitHCursor, "043a9f68147c53184671403ffa811cc5"},
103 {SplitHCursor, "14fef782d02440884392942c11205230"},
104
105 {PointingHandCursor, "pointing_hand"},
106 {PointingHandCursor, "pointer"},
107 {PointingHandCursor, "hand1"},
108 {PointingHandCursor, "e29285e634086352946a0e7090d73106"},
109
110 {ForbiddenCursor, "forbidden"},
111 {ForbiddenCursor, "not-allowed"},
112 {ForbiddenCursor, "crossed_circle"},
113 {ForbiddenCursor, "circle"},
114 {ForbiddenCursor, "03b6e0fcb3499374a867c041f52298f0"},
115
116 {WhatsThisCursor, "whats_this"},
117 {WhatsThisCursor, "help"},
118 {WhatsThisCursor, "question_arrow"},
119 {WhatsThisCursor, "5c6cd98b3f3ebcb1f9c7f1c204630408"},
120 {WhatsThisCursor, "d9ce0ab605698f320427677b458ad60b"},
121
122 {BusyCursor, "left_ptr_watch"},
123 {BusyCursor, "half-busy"},
124 {BusyCursor, "progress"},
125 {BusyCursor, "00000000000000020006000e7e9ffc3f"},
126 {BusyCursor, "08e8e1c95fe2fc01f976f1e063a24ccd"},
127
128 {OpenHandCursor, "openhand"},
129 {OpenHandCursor, "fleur"},
130 {OpenHandCursor, "5aca4d189052212118709018842178c0"},
131 {OpenHandCursor, "9d800788f1b08800ae810202380a0822"},
132
133 {ClosedHandCursor, "closedhand"},
134 {ClosedHandCursor, "grabbing"},
135 {ClosedHandCursor, "208530c400c041818281048008011002"},
136
137 {DragCopyCursor, "dnd-copy"},
138 {DragCopyCursor, "copy"},
139
140 {DragMoveCursor, "dnd-move"},
141 {DragMoveCursor, "move"},
142
143 {DragLinkCursor, "dnd-link"},
144 {DragLinkCursor, "link"},
145
146 {ResizeNorthCursor, "n-resize"},
147 {ResizeNorthCursor, "top_side"},
148
149 {ResizeSouthCursor, "s-resize"},
150 {ResizeSouthCursor, "bottom_side"},
151
152 {ResizeEastCursor, "e-resize"},
153 {ResizeEastCursor, "right_side"},
154
155 {ResizeWestCursor, "w-resize"},
156 {ResizeWestCursor, "left_side"},
157
158 {ResizeNorthWestCursor, "nw-resize"},
159 {ResizeNorthWestCursor, "top_left_corner"},
160
161 {ResizeSouthEastCursor, "se-resize"},
162 {ResizeSouthEastCursor, "bottom_right_corner"},
163
164 {ResizeNorthEastCursor, "ne-resize"},
165 {ResizeNorthEastCursor, "top_right_corner"},
166
167 {ResizeSouthWestCursor, "sw-resize"},
168 {ResizeSouthWestCursor, "bottom_left_corner"},
169 };
170
171 const auto byShape = [](ShapeAndName lhs, ShapeAndName rhs) {
172 return lhs.shape < rhs.shape;
173 };
177 for (auto it = p.first; it != p.second; ++it) {
180 return cursor;
181 }
182 }
183
184 // Fallback to arrow cursor
185 if (shape != ArrowCursor)
187
188 // Give up
189 return nullptr;
190}
191
193{
194 struct wl_cursor *waylandCursor = nullptr;
195
196 if (shape < Qt::BitmapCursor) {
198 } else if (shape == Qt::BitmapCursor) {
199 qCWarning(lcQpaWayland) << "cannot create a wl_cursor_image for a CursorShape";
200 return nullptr;
201 } else {
202 //TODO: Custom cursor logic (for resize arrows)
203 }
204
205 if (!waylandCursor) {
206 qCWarning(lcQpaWayland) << "Could not find cursor for shape" << shape;
207 return nullptr;
208 }
209
210 return waylandCursor;
211}
212
215{}
216
218{
219 destroy();
220}
221
223{
224 using QtWayland::wp_cursor_shape_device_v1;
225
226 switch (cursorShape) {
227 case Qt::BlankCursor:
228 case Qt::CustomCursor:
229 case Qt::BitmapCursor:
230 // these should have been handled separately before using the shape protocol
231 Q_ASSERT(false);
232 break;
233 case Qt::ArrowCursor:
234 return wp_cursor_shape_device_v1::shape_default;
235 case Qt::SizeVerCursor:
236 return wp_cursor_shape_device_v1::shape_ns_resize;
237 case Qt::UpArrowCursor:
238 return wp_cursor_shape_device_v1::shape_n_resize;
239 case Qt::SizeHorCursor:
240 return wp_cursor_shape_device_v1::shape_ew_resize;
241 case Qt::CrossCursor:
242 return wp_cursor_shape_device_v1::shape_crosshair;
243 case Qt::SizeBDiagCursor:
244 return wp_cursor_shape_device_v1::shape_nesw_resize;
245 case Qt::IBeamCursor:
246 return wp_cursor_shape_device_v1::shape_text;
247 case Qt::SizeFDiagCursor:
248 return wp_cursor_shape_device_v1::shape_nwse_resize;
249 case Qt::WaitCursor:
250 return wp_cursor_shape_device_v1::shape_wait;
251 case Qt::SizeAllCursor:
252 return wp_cursor_shape_device_v1::shape_all_scroll;
253 case Qt::BusyCursor:
254 return wp_cursor_shape_device_v1::shape_progress;
255 case Qt::SplitVCursor:
256 return wp_cursor_shape_device_v1::shape_row_resize;
257 case Qt::ForbiddenCursor:
258 return wp_cursor_shape_device_v1::shape_not_allowed;
259 case Qt::SplitHCursor:
260 return wp_cursor_shape_device_v1::shape_col_resize;
261 case Qt::PointingHandCursor:
262 return wp_cursor_shape_device_v1::shape_pointer;
263 case Qt::OpenHandCursor:
264 return wp_cursor_shape_device_v1::shape_grab;
265 case Qt::WhatsThisCursor:
266 return wp_cursor_shape_device_v1::shape_help;
267 case Qt::ClosedHandCursor:
268 return wp_cursor_shape_device_v1::shape_grabbing;
269 case Qt::DragMoveCursor:
270 return wp_cursor_shape_device_v1::shape_move;
271 case Qt::DragCopyCursor:
272 return wp_cursor_shape_device_v1::shape_copy;
273 case Qt::DragLinkCursor:
274 return wp_cursor_shape_device_v1::shape_alias;
275 }
276 return wp_cursor_shape_device_v1::shape_default;
277}
278
280{
282}
283
286{
287}
288
290{
293
294 // convert to supported format if necessary
295 if (!display->shm()->formatSupported(img.format())) {
296 if (cursor->mask().isNull()) {
298 } else {
299 // preserve mask
303 img = pixmap.toImage();
304 }
305 }
306
309 return buffer;
310}
311
313{
315 // Create the buffer here so we don't have to create one per input device
317 if (cursor && cursor->shape() == Qt::BitmapCursor)
319
321 const auto seats = mDisplay->inputDevices();
322 for (auto *seat : seats)
324}
325
327{
329}
330
332{
333 return mLastPos;
334}
335
336void QWaylandCursor::setPos(const QPoint &pos)
337{
338 Q_UNUSED(pos);
339 qCWarning(lcQpaWayland) << "Setting cursor position is not possible on wayland";
340}
341
343{
344 mLastPos = pos;
345}
346
348{
351 return QSize(24, 24);
352}
353
354} // namespace QtWaylandClient
355
356QT_END_NAMESPACE
static QtWayland::wp_cursor_shape_device_v1::shape qtCursorShapeToWaylandShape(Qt::CursorShape cursorShape)