11#include <QtGui/private/qguiapplication_p.h>
12#include <qpa/qplatformtheme.h>
14#include <QtGui/QImageReader>
17#include <wayland-cursor.h>
25std::unique_ptr<QWaylandCursorTheme> QWaylandCursorTheme::create(QWaylandShm *shm,
int size,
const QString &
themeName)
28 struct ::wl_cursor_theme *theme = wl_cursor_theme_load(nameBytes.constData(),
size, shm->object());
35 return std::unique_ptr<QWaylandCursorTheme>{
new QWaylandCursorTheme(theme)};
38QWaylandCursorTheme::~QWaylandCursorTheme()
40 wl_cursor_theme_destroy(m_theme);
43wl_cursor *QWaylandCursorTheme::requestCursor(WaylandCursor shape)
45 if (
struct wl_cursor *
cursor = m_cursors[shape])
51 } cursorNamesMap[] = {
63 {
WaitCursor,
"0426c94ea35c87780ff01dc239897213"},
125 {
BusyCursor,
"00000000000000020006000e7e9ffc3f"},
126 {
BusyCursor,
"08e8e1c95fe2fc01f976f1e063a24ccd"},
146 {ResizeNorthCursor,
"n-resize"},
147 {ResizeNorthCursor,
"top_side"},
149 {ResizeSouthCursor,
"s-resize"},
150 {ResizeSouthCursor,
"bottom_side"},
152 {ResizeEastCursor,
"e-resize"},
153 {ResizeEastCursor,
"right_side"},
155 {ResizeWestCursor,
"w-resize"},
156 {ResizeWestCursor,
"left_side"},
158 {ResizeNorthWestCursor,
"nw-resize"},
159 {ResizeNorthWestCursor,
"top_left_corner"},
161 {ResizeSouthEastCursor,
"se-resize"},
162 {ResizeSouthEastCursor,
"bottom_right_corner"},
164 {ResizeNorthEastCursor,
"ne-resize"},
165 {ResizeNorthEastCursor,
"top_right_corner"},
167 {ResizeSouthWestCursor,
"sw-resize"},
168 {ResizeSouthWestCursor,
"bottom_left_corner"},
171 const auto byShape = [](ShapeAndName lhs, ShapeAndName rhs) {
172 return lhs.shape < rhs.shape;
174 Q_ASSERT(std::is_sorted(std::begin(cursorNamesMap), std::end(cursorNamesMap), byShape));
175 const auto p = std::equal_range(std::begin(cursorNamesMap), std::end(cursorNamesMap),
176 ShapeAndName{shape,
""}, byShape);
177 for (
auto it =
p.first;
it !=
p.second; ++
it) {
178 if (wl_cursor *
cursor = wl_cursor_theme_get_cursor(m_theme,
it->name)) {
179 m_cursors[shape] =
cursor;
185 if (shape != ArrowCursor)
186 return requestCursor(ArrowCursor);
194 struct wl_cursor *waylandCursor =
nullptr;
197 waylandCursor = requestCursor(WaylandCursor(shape));
199 qCWarning(lcQpaWayland) <<
"cannot create a wl_cursor_image for a CursorShape";
205 if (!waylandCursor) {
206 qCWarning(lcQpaWayland) <<
"Could not find cursor for shape" << shape;
210 return waylandCursor;
213QWaylandCursorShape::QWaylandCursorShape(::wp_cursor_shape_device_v1 *
object)
217QWaylandCursorShape::~QWaylandCursorShape()
224 using QtWayland::wp_cursor_shape_device_v1;
226 switch (cursorShape) {
234 return wp_cursor_shape_device_v1::shape_default;
236 return wp_cursor_shape_device_v1::shape_ns_resize;
238 return wp_cursor_shape_device_v1::shape_n_resize;
240 return wp_cursor_shape_device_v1::shape_ew_resize;
242 return wp_cursor_shape_device_v1::shape_crosshair;
244 return wp_cursor_shape_device_v1::shape_nesw_resize;
246 return wp_cursor_shape_device_v1::shape_text;
248 return wp_cursor_shape_device_v1::shape_nwse_resize;
250 return wp_cursor_shape_device_v1::shape_wait;
252 return wp_cursor_shape_device_v1::shape_all_scroll;
254 return wp_cursor_shape_device_v1::shape_progress;
256 return wp_cursor_shape_device_v1::shape_row_resize;
258 return wp_cursor_shape_device_v1::shape_not_allowed;
260 return wp_cursor_shape_device_v1::shape_col_resize;
262 return wp_cursor_shape_device_v1::shape_pointer;
264 return wp_cursor_shape_device_v1::shape_grab;
266 return wp_cursor_shape_device_v1::shape_help;
268 return wp_cursor_shape_device_v1::shape_grabbing;
270 return wp_cursor_shape_device_v1::shape_move;
272 return wp_cursor_shape_device_v1::shape_copy;
274 return wp_cursor_shape_device_v1::shape_alias;
276 return wp_cursor_shape_device_v1::shape_default;
279void QWaylandCursorShape::setShape(uint32_t serial,
Qt::CursorShape shape)
281 set_shape(serial, qtCursorShapeToWaylandShape(shape));
284QWaylandCursor::QWaylandCursor(QWaylandDisplay *
display)
289QSharedPointer<QWaylandBuffer> QWaylandCursor::cursorBitmapBuffer(QWaylandDisplay *
display,
const QCursor *
cursor)
295 if (!
display->shm()->formatSupported(
img.format())) {
307 QSharedPointer<QWaylandShmBuffer>
buffer(
new QWaylandShmBuffer(
display,
img.size(),
img.format()));
308 memcpy(
buffer->image()->bits(),
img.bits(),
size_t(
img.sizeInBytes()));
316 QSharedPointer<QWaylandBuffer> bitmapBuffer;
318 bitmapBuffer = cursorBitmapBuffer(mDisplay,
cursor);
320 int fallbackOutputScale = int(
window->devicePixelRatio());
321 const auto seats = mDisplay->inputDevices();
322 for (
auto *seat : seats)
328 mLastPos =
event.globalPosition().toPoint();
331QPoint QWaylandCursor::pos()
const
336void QWaylandCursor::setPos(
const QPoint &
pos)
339 qCWarning(lcQpaWayland) <<
"Setting cursor position is not possible on wayland";
342QSize QWaylandCursor::size()
const
346 return QSize(24, 24);
The QCursor class provides a mouse cursor with an arbitrary shape.
QBitmap bitmap() const
Returns the cursor bitmap, or a null bitmap if it is one of the standard cursors.
QPixmap pixmap() const
Returns the cursor pixmap.
Qt::CursorShape shape() const
Returns the cursor shape identifier.
QBitmap mask() const
Returns the cursor bitmap mask, or a null bitmap if it is one of the standard cursors.
static QPlatformTheme * platformTheme()
void convertTo(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QImage toImage() const
Converts the pixmap to a QImage.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSet< QString >::iterator it
struct wl_display * display
Combined button and popup list for selecting options.
static QtWayland::wp_cursor_shape_device_v1::shape qtCursorShapeToWaylandShape(Qt::CursorShape cursorShape)
#define qCWarning(category,...)
static QString themeName()
GLenum GLuint GLintptr GLsizeiptr size
[1]
item setCursor(Qt::IBeamCursor)
[1]