diff options
author | Martin Gräßlin <mgraesslin@kde.org> | 2016-03-02 11:04:10 +0100 |
---|---|---|
committer | Martin Gräßlin <mgraesslin@kde.org> | 2016-03-17 06:40:40 +0000 |
commit | 9cbd553eeb758bb060514f17d4615003da16429a (patch) | |
tree | c5dfb0fbf3f510881155150532bb51c7c1bf49e5 /src/client/qwaylandcursor.cpp | |
parent | 759822f33f56acb3e2bacf19c6431ea4fa2be229 (diff) |
Add support for bitmap cursors
So far QtWayland did not support custom bitmap/pixmap QCursors.
This change adds support for them by creating a QWaylandShmBuffer and
copying the pixmap data into that buffer. The internal API to set
cursors images is changed to not only rely on wl_cursor_image, but also
allow to just set the buffer with a specific size and a hot spot.
The created WaylandShmBuffer is passed around as a shared pointer, so
that it can be automatically cleaned up once the cursor image is no
longer used on any seat.
Task-number: QTBUG-51604
Change-Id: I1f1ee87f03186c3d564468d3e8ea2a3141d7e2fb
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
Reviewed-by: Johan Helsing <johan.helsing@theqtcompany.com>
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 8dfc95c36..8d91e3896 100644 --- a/src/client/qwaylandcursor.cpp +++ b/src/client/qwaylandcursor.cpp @@ -85,7 +85,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) } @@ -105,12 +106,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; @@ -130,6 +147,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(); |