diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2023-02-20 14:02:23 +0100 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2023-02-22 09:15:35 +0100 |
commit | 45ec1362f8fcb5ade92f4d2d4985b1c24e78c8ba (patch) | |
tree | 51b70cd3591b27dc03e6d3139613e29483706a01 /src | |
parent | a328e2c5e0594ff476a9df2fcdc3b03894ff7a15 (diff) | |
download | qtwayland-45ec1362f8fcb5ade92f4d2d4985b1c24e78c8ba.tar.gz |
Convert cursor bitmap to supported format
The 1-bit image formats QImage::Format_Mono and
QImage::Format_MonoLSB used by cursor bitmaps don't have
a corresponding wl_shm_format.
Therefore, convert to a supported image format as necessary
to make such bitmap cursors work on Wayland as well.
Fixes: QTBUG-95434
Change-Id: I402fd870b301ddc01075251b66f2cf7cc1923133
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/client/qwaylandcursor.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/client/qwaylandcursor.cpp b/src/client/qwaylandcursor.cpp index 67a846df..ec17ed21 100644 --- a/src/client/qwaylandcursor.cpp +++ b/src/client/qwaylandcursor.cpp @@ -214,7 +214,21 @@ QWaylandCursor::QWaylandCursor(QWaylandDisplay *display) QSharedPointer<QWaylandBuffer> QWaylandCursor::cursorBitmapBuffer(QWaylandDisplay *display, const QCursor *cursor) { Q_ASSERT(cursor->shape() == Qt::BitmapCursor); - const QImage &img = cursor->pixmap().toImage(); + QImage img = !cursor->pixmap().isNull() ? cursor->pixmap().toImage() : cursor->bitmap().toImage(); + + // convert to supported format if necessary + if (!display->shm()->formatSupported(img.format())) { + if (cursor->mask().isNull()) { + img.convertTo(QImage::Format_RGB32); + } else { + // preserve mask + img.convertTo(QImage::Format_ARGB32); + QPixmap pixmap = QPixmap::fromImage(img); + pixmap.setMask(cursor->mask()); + img = pixmap.toImage(); + } + } + QSharedPointer<QWaylandShmBuffer> buffer(new QWaylandShmBuffer(display, img.size(), img.format())); memcpy(buffer->image()->bits(), img.bits(), size_t(img.sizeInBytes())); return buffer; |