Gui: Buggy Wayland custom cursors workaround

Until Qt v6.6 displaying custom cursors on Wayland is broken,
so add a workaround. See also QTBUG-95434.
This commit is contained in:
Ladislav Michl
2024-06-07 09:36:53 +02:00
committed by Chris Hennes
parent 6d21724e20
commit 46cce4bc98

View File

@@ -72,6 +72,10 @@
# include <Inventor/nodes/SoTranslation.h>
# include <QBitmap>
# include <QEventLoop>
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,6,0) && QT_VERSION >= QT_VERSION_CHECK(5,13,0)
# include <QGuiApplication>
# define HAS_QTBUG_95434
#endif
# include <QKeyEvent>
# include <QMessageBox>
# include <QMimeData>
@@ -643,35 +647,43 @@ View3DInventorViewer::~View3DInventorViewer()
delete glAction;
}
void View3DInventorViewer::createStandardCursors(double dpr)
static QCursor createCursor(QBitmap &bitmap, QBitmap &mask, int hotX, int hotY, double dpr)
{
// NOLINTBEGIN
QBitmap cursor = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_bitmap);
QBitmap mask = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_mask_bitmap);
#if defined(Q_OS_WIN32)
cursor.setDevicePixelRatio(dpr);
bitmap.setDevicePixelRatio(dpr);
mask.setDevicePixelRatio(dpr);
#else
Q_UNUSED(dpr)
#endif
spinCursor = QCursor(cursor, mask, ROTATE_HOT_X, ROTATE_HOT_Y);
#ifdef HAS_QTBUG_95434
QPixmap pixmap;
if (qGuiApp->platformName() == QLatin1String("wayland")) {
QImage img = bitmap.toImage();
img.convertTo(QImage::Format_ARGB32);
pixmap = QPixmap::fromImage(img);
} else {
pixmap = bitmap;
}
pixmap.setMask(mask);
return QCursor(pixmap, hotX, hotY);
#else
return QCursor(bitmap, mask, hotX, hotY);
#endif
}
void View3DInventorViewer::createStandardCursors(double dpr)
{
QBitmap cursor = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_bitmap);
QBitmap mask = QBitmap::fromData(QSize(ROTATE_WIDTH, ROTATE_HEIGHT), rotate_mask_bitmap);
spinCursor = createCursor(cursor, mask, ROTATE_HOT_X, ROTATE_HOT_Y, dpr);
cursor = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_bitmap);
mask = QBitmap::fromData(QSize(ZOOM_WIDTH, ZOOM_HEIGHT), zoom_mask_bitmap);
#if defined(Q_OS_WIN32)
cursor.setDevicePixelRatio(dpr);
mask.setDevicePixelRatio(dpr);
#endif
zoomCursor = QCursor(cursor, mask, ZOOM_HOT_X, ZOOM_HOT_Y);
zoomCursor = createCursor(cursor, mask, ZOOM_HOT_X, ZOOM_HOT_Y, dpr);
cursor = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_bitmap);
mask = QBitmap::fromData(QSize(PAN_WIDTH, PAN_HEIGHT), pan_mask_bitmap);
#if defined(Q_OS_WIN32)
cursor.setDevicePixelRatio(dpr);
mask.setDevicePixelRatio(dpr);
#endif
panCursor = QCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y);
// NOLINTEND
panCursor = createCursor(cursor, mask, PAN_HOT_X, PAN_HOT_Y, dpr);
}
void View3DInventorViewer::aboutToDestroyGLContext()