summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-02-20 17:20:08 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-28 12:44:44 +0000
commit3e1b877b95eddcb7efd33e5149c904dae3911617 (patch)
tree8f20da0fc5de5853f8bd9da2f2d8816774396684
parent911e1496deccb99f5b0f00373200110cad9f3828 (diff)
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>
-rw-r--r--src/gui/kernel/qguiapplication_p.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 72a3fc78d0..c7319a92ba 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -203,6 +203,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;