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.
This commit is contained in:
Yifan Zhu 2024-03-14 14:18:36 -07:00
parent ac9b9a6772
commit e68ac506af
3 changed files with 9 additions and 2 deletions

View file

@ -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;
}

View file

@ -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.

View file

@ -22,6 +22,7 @@ class ShakeDetector
public:
ShakeDetector();
void reset();
bool update(QMouseEvent *event);
quint64 interval() const;