From fdbc9e113b7c4361f148508c8332487d9385105d Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 23 Dec 2022 15:30:22 +0200 Subject: Client: Port to QPlatformTheme::{MouseCursorTheme,MouseCursorSize} It allows the platform theme to specify the preferred cursor theme and cursor size without resorting to hacks such as setting XCURSOR_THEME and XCURSOR_SIZE environment variables. Change-Id: I9e44f9c6dddbb5d730f8ac092f2c11fdbccf8d27 Reviewed-by: Liang Qi (cherry picked from commit 1c25db5e3f23d48e330170f41b94fbd532932b02) Reviewed-by: Qt Cherry-pick Bot --- src/client/qwaylandinputdevice.cpp | 33 +++++++++++++++++---------------- src/client/qwaylandinputdevice_p.h | 2 -- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp index 724243cc..30f19757 100644 --- a/src/client/qwaylandinputdevice.cpp +++ b/src/client/qwaylandinputdevice.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -229,19 +230,6 @@ private: QPoint m_hotspot; }; -QString QWaylandInputDevice::Pointer::cursorThemeName() const -{ - static QString themeName = qEnvironmentVariable("XCURSOR_THEME", QStringLiteral("default")); - return themeName; -} - -int QWaylandInputDevice::Pointer::cursorSize() const -{ - constexpr int defaultCursorSize = 24; - static const int xCursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); - return xCursorSize > 0 ? xCursorSize : defaultCursorSize; -} - int QWaylandInputDevice::Pointer::idealCursorScale() const { if (seat()->mQDisplay->compositor()->version() < 3) { @@ -258,17 +246,30 @@ int QWaylandInputDevice::Pointer::idealCursorScale() const void QWaylandInputDevice::Pointer::updateCursorTheme() { + QString cursorThemeName; + QSize cursorSize; + + if (const QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme()) { + cursorThemeName = platformTheme->themeHint(QPlatformTheme::MouseCursorTheme).toString(); + cursorSize = platformTheme->themeHint(QPlatformTheme::MouseCursorSize).toSize(); + } + + if (cursorThemeName.isEmpty()) + cursorThemeName = QStringLiteral("default"); + if (cursorSize.isEmpty()) + cursorSize = QSize(24, 24); + int scale = idealCursorScale(); - int pixelSize = cursorSize() * scale; + int pixelSize = cursorSize.width() * scale; auto *display = seat()->mQDisplay; - mCursor.theme = display->loadCursorTheme(cursorThemeName(), pixelSize); + mCursor.theme = display->loadCursorTheme(cursorThemeName, pixelSize); if (!mCursor.theme) return; // A warning has already been printed in loadCursorTheme if (auto *arrow = mCursor.theme->cursor(Qt::ArrowCursor)) { int arrowPixelSize = qMax(arrow->images[0]->width, arrow->images[0]->height); // Not all cursor themes are square - while (scale > 1 && arrowPixelSize / scale < cursorSize()) + while (scale > 1 && arrowPixelSize / scale < cursorSize.width()) --scale; } else { qCWarning(lcQpaWayland) << "Cursor theme does not support the arrow cursor"; diff --git a/src/client/qwaylandinputdevice_p.h b/src/client/qwaylandinputdevice_p.h index fbc26008..17f01f49 100644 --- a/src/client/qwaylandinputdevice_p.h +++ b/src/client/qwaylandinputdevice_p.h @@ -280,8 +280,6 @@ public: ~Pointer() override; QWaylandWindow *focusWindow() const; #if QT_CONFIG(cursor) - QString cursorThemeName() const; - int cursorSize() const; // in surface coordinates int idealCursorScale() const; void updateCursorTheme(); void updateCursor(); -- cgit v1.2.1