From 1330abc93dd6d9ba5b27f4107b31c1a6125bd78e Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 13 Jul 2020 19:05:34 +0300 Subject: [PATCH] Provide hotspot in the device independent pixels Currently, the trend is to get the coordinates of the hotspot and map it to the device independent pixels at the call site. This change makes the KXcursorSprite return the coordinates of the hotspot in the device independent pixels to reduce the amount of duplicated code. --- autotests/integration/pointer_input.cpp | 1 - pointer_input.cpp | 1 - xcursortheme.cpp | 2 +- xcursortheme.h | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp index 0f7ddccb75..6e64205f7b 100644 --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -64,7 +64,6 @@ static PlatformCursorImage loadReferenceThemeCursor_helper(const KXcursorTheme & cursorImage.setDevicePixelRatio(theme.devicePixelRatio()); QPoint cursorHotspot = sprites.first().hotspot(); - cursorHotspot /= theme.devicePixelRatio(); return PlatformCursorImage(cursorImage, cursorHotspot); } diff --git a/pointer_input.cpp b/pointer_input.cpp index 1d35f86311..c79aa0b59c 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -1322,7 +1322,6 @@ bool WaylandCursorImage::loadThemeCursor_helper(const QByteArray &name, Image *c cursorImage->image.setDevicePixelRatio(m_cursorTheme.devicePixelRatio()); cursorImage->hotspot = sprites.first().hotspot(); - cursorImage->hotspot /= m_cursorTheme.devicePixelRatio(); return true; } diff --git a/xcursortheme.cpp b/xcursortheme.cpp index d0893ea82a..fb33c50cd1 100644 --- a/xcursortheme.cpp +++ b/xcursortheme.cpp @@ -96,7 +96,7 @@ static void load_callback(XcursorImages *images, void *data) QImage data(nativeCursorImage->width, nativeCursorImage->height, QImage::Format_ARGB32); memcpy(data.bits(), nativeCursorImage->pixels, data.sizeInBytes()); - sprites.append(KXcursorSprite(data, hotspot, delay)); + sprites.append(KXcursorSprite(data, hotspot / themePrivate->devicePixelRatio, delay)); } themePrivate->registry.insert(images->name, sprites); diff --git a/xcursortheme.h b/xcursortheme.h index 0436d87e2e..e61718d74f 100644 --- a/xcursortheme.h +++ b/xcursortheme.h @@ -71,7 +71,7 @@ public: /** * Returns the hotspot for this sprite. (0, 0) corresponds to the upper left corner. * - * The coordinates of the hotspot are in device pixels. + * The coordinates of the hotspot are in device independent pixels. */ QPoint hotspot() const;