diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-02-20 17:20:08 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-28 13:31:46 +0000 |
commit | 73e139c447ab01f0c48e5c6253ca5f2244cddb2c (patch) | |
tree | ef88189736d578b8f2f29f8a8e69ba9615547ff3 /src/gui | |
parent | bae383002a9d064f6565caccac43f0f82c2c737a (diff) | |
download | qtbase-73e139c447ab01f0c48e5c6253ca5f2244cddb2c.tar.gz |
QtGui: Use single precision for mouseMove detection
QGuiApplication::lastCursorPosition is a QPointF, and (at least on macOS)
compares always different from the QPointF stored in the event. This
might be due to the translation from system coordinates to QPointF
introducing noise.
The result is that even a simple button press causes mouseMove events
to be delivered.
To prevent this event noise, overload equality operators for the special
QLastCursorPosition type when comparing with QPointF to explicitly use
single precision comparison.
Fixes: QTBUG-111170
Change-Id: I82ea23ac9f4fa80c55c9c5c742527dd7ee74fd99
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 519e3963fad0761bac5629b1f6eabc58060265c0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 404b55950a..40caf3ba56 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -206,6 +206,28 @@ public: constexpr void reset() noexcept { *this = QLastCursorPosition{}; } + // QGuiApplicationPrivate::lastCursorPosition is used for mouse-move detection + // but even QPointF's qFuzzCompare on doubles is too precise, and causes move-noise + // e.g. on macOS (see QTBUG-111170). So we specialize the equality operators here + // to use single-point precision. + friend constexpr bool operator==(const QLastCursorPosition &p1, const QPointF &p2) noexcept + { + return qFuzzyCompare(float(p1.x()), float(p2.x())) + && qFuzzyCompare(float(p1.y()), float(p2.y())); + } + friend constexpr bool operator!=(const QLastCursorPosition &p1, const QPointF &p2) noexcept + { + return !(p1 == p2); + } + friend constexpr bool operator==(const QPointF &p1, const QLastCursorPosition &p2) noexcept + { + return p2 == p1; + } + friend constexpr bool operator!=(const QPointF &p1, const QLastCursorPosition &p2) noexcept + { + return !(p2 == p1); + } + private: QPointF thePoint; } lastCursorPosition; |