diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-11-10 10:14:22 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-11-10 16:53:31 +0100 |
commit | 4ccfe7b7347325e801f77e53075a702693cafeb2 (patch) | |
tree | 253acd3bfc0d2af6f286226e4fe204c4ac81280b /src/gui/kernel/qguiapplication.cpp | |
parent | 73e64a98c696f516aed204cf79bacce7d2179030 (diff) |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
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); } |