From e68ac506af0fd39f35906eb53765ba2df1d05c8c Mon Sep 17 00:00:00 2001 From: Yifan Zhu Date: Thu, 14 Mar 2024 14:18:36 -0700 Subject: [PATCH] plugins/shakecursor: reset detector on mouse press A sequence of mouse moves shouldn't trigger the effect if the user presses any mouse button during the mouse moves. --- src/plugins/shakecursor/shakecursor.cpp | 5 +++-- src/plugins/shakecursor/shakedetector.cpp | 5 +++++ src/plugins/shakecursor/shakedetector.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/shakecursor/shakecursor.cpp b/src/plugins/shakecursor/shakecursor.cpp index 926298726c..048dac8a0d 100644 --- a/src/plugins/shakecursor/shakecursor.cpp +++ b/src/plugins/shakecursor/shakecursor.cpp @@ -94,11 +94,12 @@ void ShakeCursorEffect::animateTo(qreal magnification) void ShakeCursorEffect::pointerEvent(MouseEvent *event) { - if (event->type() != QEvent::MouseMove || event->buttons() != Qt::NoButton) { + if (event->buttons() != Qt::NoButton) { + m_shakeDetector.reset(); return; } - if (input()->pointer()->isConstrained()) { + if (input()->pointer()->isConstrained() || event->type() != QEvent::MouseMove) { return; } diff --git a/src/plugins/shakecursor/shakedetector.cpp b/src/plugins/shakecursor/shakedetector.cpp index 10962ba49d..146879e5f7 100644 --- a/src/plugins/shakecursor/shakedetector.cpp +++ b/src/plugins/shakecursor/shakedetector.cpp @@ -39,6 +39,11 @@ static inline bool sameSign(qreal a, qreal b) return (a >= -tolerance && b >= -tolerance) || (a <= tolerance && b <= tolerance); } +void ShakeDetector::reset() +{ + m_history.clear(); +} + bool ShakeDetector::update(QMouseEvent *event) { // Prune the old entries in the history. diff --git a/src/plugins/shakecursor/shakedetector.h b/src/plugins/shakecursor/shakedetector.h index 25f40a7560..4ec7289f29 100644 --- a/src/plugins/shakecursor/shakedetector.h +++ b/src/plugins/shakecursor/shakedetector.h @@ -22,6 +22,7 @@ class ShakeDetector public: ShakeDetector(); + void reset(); bool update(QMouseEvent *event); quint64 interval() const;