diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-11-06 11:24:49 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-11-06 22:03:51 +0100 |
commit | 604adc01c00bee770485308cbe0e2b2897b45fa7 (patch) | |
tree | aa53fef67b248003cbfa4008c24e3de5313d8358 /src | |
parent | 832e44b2320925b3011d1c2b1518fda7f4077bb6 (diff) |
Fix mouse velocity calculation
The mouse event that is sent to QPlatformCursor is in native pixels,
but the QSinglePointEvent constructor sets QEventPoint::globalLastPosition
every time, and velocity is calculated by delta from globalLastPosition
to globalPosition. We plan to rely on this velocity being correct
in Qt Quick, in Flickable for example. So globalLastPosition and
globalPosition need to be in the same coordinate system at the time
QPointerEvent::setTimestamp() is called.
Change-Id: I39f97a43f55f47a70cbd574861e920f3106e2125
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 1499c4b57e..3dcd0650e3 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2151,6 +2151,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo bool positionChanged = QGuiApplicationPrivate::lastCursorPosition != e->globalPos; bool mouseMove = false; bool mousePress = false; + const QPointF lastGlobalPosition = QGuiApplicationPrivate::lastCursorPosition; QPointF globalPoint = e->globalPos; if (qIsNaN(e->globalPos.x()) || qIsNaN(e->globalPos.y())) { @@ -2279,13 +2280,19 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen); QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint, button, e->buttons, e->modifiers, e->source, device); - ev.setTimestamp(e->timestamp); + // avoid incorrect velocity calculation: ev is in the native coordinate system, + // but we need to consistently use the logical coordinate system for velocity + // whenever QEventPoint::setTimestamp() is called + ev.QInputEvent::setTimestamp(e->timestamp); cursor->pointerEvent(ev); } } #endif QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device); + // restore globalLastPosition to avoid invalidating the velocity calculations, + // because the QPlatformCursor mouse event above was in native coordinates + QMutableEventPoint::from(persistentEPD->eventPoint).setGlobalLastPosition(lastGlobalPosition); // ev now contains a detached copy of the QEventPoint from QPointingDevicePrivate::activePoints ev.setTimestamp(e->timestamp); if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) { |