From eedcda282fa47d2e4ae52a432bc74c14599311e3 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 20 Feb 2023 17:20:08 +0100 Subject: [PATCH] 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. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-111170 Change-Id: I82ea23ac9f4fa80c55c9c5c742527dd7ee74fd99 Reviewed-by: Shawn Rutledge --- src/gui/kernel/qguiapplication_p.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 0a5ba0885a..ec63876058 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -207,6 +207,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;