diff options
author | Aleix Pol <aleixpol@kde.org> | 2018-04-26 17:38:10 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-05-15 09:43:58 +0000 |
commit | 687cf7c7d1d2f809de56787e16c73a4eb64766fc (patch) | |
tree | 07ef5647ae435d06b1542e577830b481f189a7ba /src/client/qwaylandcursor.cpp | |
parent | 83084f717ccf6e7c1930c7b61de3bfec2cc48bc3 (diff) |
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 <johan.helsing@qt.io>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
Diffstat (limited to 'src/client/qwaylandcursor.cpp')
-rw-r--r-- | src/client/qwaylandcursor.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
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<QWaylandBuffer> 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) |