From 4ccfe7b7347325e801f77e53075a702693cafeb2 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 10 Nov 2020 10:14:22 +0100 Subject: [PATCH] Reset the velocity Kalman filter when the mouse enters a window If we always tracked the mouse, we could always have accurate velocity; but most of the time, when the mouse enters a top-level window, we don't know how fast it was moving at that time, unless the application has requested a window-system mouse grab. It's better to assume that any residual velocity stored in the persistent QEventPoint instance (in QPointingDevicePrivate::activePoints) is inaccurate, and just start over from zero. Especially for the sake of autotest sanity. Task-number: QTBUG-88346 Change-Id: Id6c4fbffb8a86a8ab50a09f09aa62125d10155b4 Reviewed-by: Fabian Kosmale --- src/gui/kernel/qguiapplication.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 268f5cee1d..a57b34a3d9 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2417,7 +2417,19 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En currentMouseWindow = e->enter; + // TODO later: EnterEvent must report _which_ mouse entered the window; for now we assume primaryPointingDevice() QEnterEvent event(e->localPos, e->localPos, e->globalPos); + + // Since we don't always track mouse moves that occur outside a window, any residual velocity + // stored in the persistent QEventPoint may be inaccurate (especially in fast-moving autotests). + // Reset the Kalman filter so that the velocity of the first mouse event after entering the window + // will be based on a zero residual velocity (but the result can still be non-zero if the mouse + // moves to a different position from where this enter event occurred; tests often do that). + const QPointingDevicePrivate *devPriv = QPointingDevicePrivate::get(event.pointingDevice()); + auto epd = devPriv->queryPointById(event.points().first().id()); + Q_ASSERT(epd); + QMutableEventPoint::from(epd->eventPoint).setVelocity({}); + QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event); }