From 687cf7c7d1d2f809de56787e16c73a4eb64766fc Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 26 Apr 2018 17:38:10 +0200 Subject: Adapt the cursor size per screen Adapt the cursor size to the screen's devicePixelRatio, so we are not forced to have a tiny cursor on a high dpi screen or a huge cursor on external low-dpi displays. Change-Id: I3712dc64e5c5e2e05d0dc5943bd49ba5c1335cd3 Reviewed-by: Johan Helsing Reviewed-by: Pier Luigi Fiorini --- src/client/qwaylandcursor.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/client/qwaylandcursor.cpp') diff --git a/src/client/qwaylandcursor.cpp b/src/client/qwaylandcursor.cpp index 21a6c0811..a356950c3 100644 --- a/src/client/qwaylandcursor.cpp +++ b/src/client/qwaylandcursor.cpp @@ -60,11 +60,14 @@ QWaylandCursor::QWaylandCursor(QWaylandScreen *screen) QByteArray cursorTheme = qgetenv("XCURSOR_THEME"); if (cursorTheme.isEmpty()) cursorTheme = QByteArray("default"); - QByteArray cursorSizeFromEnv = qgetenv("XCURSOR_SIZE"); - bool hasCursorSize = false; - int cursorSize = cursorSizeFromEnv.toInt(&hasCursorSize); - if (!hasCursorSize || cursorSize <= 0) + int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); + if (cursorSize <= 0) cursorSize = 32; + + // wl_surface.set_buffer_scale is not supported on earlier versions + if (mDisplay->compositorVersion() >= 3) + cursorSize *= screen->devicePixelRatio(); + mCursorTheme = wl_cursor_theme_load(cursorTheme, cursorSize, mDisplay->shm()->object()); if (!mCursorTheme) qDebug() << "Could not load theme" << cursorTheme; @@ -84,7 +87,7 @@ struct wl_cursor_image *QWaylandCursor::cursorImage(Qt::CursorShape newShape) /* Hide cursor */ if (newShape == Qt::BlankCursor) { - mDisplay->setCursor(nullptr, nullptr); + mDisplay->setCursor(nullptr, nullptr, 1); return nullptr; } @@ -125,12 +128,10 @@ QSharedPointer QWaylandCursor::cursorBitmapImage(const QCursor * 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()); + mDisplay->setCursor(cursorBitmapImage(cursor), cursor->hotSpot(), window->screen()->devicePixelRatio()); return; } @@ -140,7 +141,7 @@ void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window) } struct wl_buffer *buffer = wl_cursor_image_get_buffer(image); - mDisplay->setCursor(buffer, image); + mDisplay->setCursor(buffer, image, window->screen()->devicePixelRatio()); } void QWaylandCursor::pointerEvent(const QMouseEvent &event) -- cgit v1.2.3