diff options
Diffstat (limited to 'src/client/qwaylandcursor.cpp')
-rw-r--r-- | src/client/qwaylandcursor.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/client/qwaylandcursor.cpp b/src/client/qwaylandcursor.cpp index f96b5c1e1..e3e3469be 100644 --- a/src/client/qwaylandcursor.cpp +++ b/src/client/qwaylandcursor.cpp @@ -91,7 +91,8 @@ struct wl_cursor_image *QWaylandCursor::cursorImage(Qt::CursorShape newShape) if (newShape < Qt::BitmapCursor) { waylandCursor = requestCursor((WaylandCursor)newShape); } else if (newShape == Qt::BitmapCursor) { - //TODO: Bitmap cursor logic + // cannot create a wl_cursor_image for a CursorShape + return Q_NULLPTR; } else { //TODO: Custom cursor logic (for resize arrows) } @@ -111,12 +112,28 @@ struct wl_cursor_image *QWaylandCursor::cursorImage(Qt::CursorShape newShape) return image; } +QSharedPointer<QWaylandBuffer> QWaylandCursor::cursorBitmapImage(const QCursor *cursor) +{ + if (cursor->shape() != Qt::BitmapCursor) + return QSharedPointer<QWaylandShmBuffer>(); + + const QImage &img = cursor->pixmap().toImage(); + QSharedPointer<QWaylandShmBuffer> buffer(new QWaylandShmBuffer(mDisplay, img.size(), img.format())); + memcpy(buffer->image()->bits(), img.bits(), img.byteCount()); + return buffer; +} + void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window) { Q_UNUSED(window) const Qt::CursorShape newShape = cursor ? cursor->shape() : Qt::ArrowCursor; + if (newShape == Qt::BitmapCursor) { + mDisplay->setCursor(cursorBitmapImage(cursor), cursor->hotSpot()); + return; + } + struct wl_cursor_image *image = cursorImage(newShape); if (!image) { return; @@ -136,6 +153,16 @@ void QWaylandDisplay::setCursor(struct wl_buffer *buffer, struct wl_cursor_image } } +void QWaylandDisplay::setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot) +{ + /* Qt doesn't tell us which input device we should set the cursor + * for, so set it for all devices. */ + for (int i = 0; i < mInputDevices.count(); i++) { + QWaylandInputDevice *inputDevice = mInputDevices.at(i); + inputDevice->setCursor(buffer, hotSpot); + } +} + QWaylandInputDevice *QWaylandDisplay::defaultInputDevice() const { return mInputDevices.isEmpty() ? 0 : mInputDevices.first(); |