AA_SynthesizeTouchForUnhandledMouseEvents: keep correct coordinates
QGuiApplicationPrivate::processMouseEvent() sends a QWindowSystemInterfacePrivate::TouchEvent if the mouse event is not accepted and AA_SynthesizeTouchForUnhandledMouseEvents is enabled. A QPA TouchEvent always contains native touch points, which is why it calls QWindowSystemInterfacePrivate::fromNativeTouchPoints to translate the QMouseEvent's device-independent position back to the raw position that it would have had if it came from a real touchscreen. Therefore we must give that function touchpoints that are actually in native coordinates. It may be that some of this transformation could be avoided entirely, but here we prove that the existing way works correctly, by adding coordinate checking to the tst_QWindow::mouseToTouchTranslation() test. Task-number: QTBUG-86165 Change-Id: I4c9ca2b11e9eb76d79712c187db3eb9865da581a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit aeeac48cbdea744406f0c8abefe271f571b61d07) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ca4f26320d
commit
5d0c1fc29f
@ -2269,7 +2269,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
|
||||
QList<QWindowSystemInterface::TouchPoint> points;
|
||||
QWindowSystemInterface::TouchPoint point;
|
||||
point.id = 1;
|
||||
point.area = QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4);
|
||||
point.area = QHighDpi::toNativePixels(QRectF(globalPoint.x() - 2, globalPoint.y() - 2, 4, 4), window);
|
||||
|
||||
// only translate left button related events to
|
||||
// avoid strange touch event sequences when several
|
||||
|
@ -1033,11 +1033,16 @@ public:
|
||||
touchEventType = event->type();
|
||||
QList<QTouchEvent::TouchPoint> points = event->points();
|
||||
for (int i = 0; i < points.count(); ++i) {
|
||||
switch (points.at(i).state()) {
|
||||
const auto &point = points.at(i);
|
||||
switch (point.state()) {
|
||||
case QEventPoint::State::Pressed:
|
||||
++touchPressedCount;
|
||||
if (spinLoopWhenPressed)
|
||||
QCoreApplication::processEvents();
|
||||
if (i == 0) {
|
||||
touchPressLocalPos = point.position();
|
||||
touchPressGlobalPos = point.globalPosition();
|
||||
}
|
||||
break;
|
||||
case QEventPoint::State::Released:
|
||||
++touchReleasedCount;
|
||||
@ -1082,6 +1087,7 @@ public:
|
||||
int mousePressedCount = 0, mouseReleasedCount = 0, mouseMovedCount = 0, mouseDoubleClickedCount = 0;
|
||||
QString mouseSequenceSignature;
|
||||
QPointF mousePressScreenPos, mouseMoveScreenPos, mousePressLocalPos;
|
||||
QPointF touchPressGlobalPos, touchPressLocalPos;
|
||||
int touchPressedCount = 0, touchReleasedCount = 0, touchMovedCount = 0;
|
||||
QEvent::Type touchEventType = QEvent::None;
|
||||
int enterEventCount = 0, leaveEventCount = 0;
|
||||
@ -1307,7 +1313,8 @@ void tst_QWindow::mouseToTouchTranslation()
|
||||
window.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
||||
|
||||
QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
|
||||
const QPoint localPos(10, 10);
|
||||
QTest::mouseClick(&window, Qt::LeftButton, {}, localPos);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
|
||||
@ -1316,12 +1323,14 @@ void tst_QWindow::mouseToTouchTranslation()
|
||||
QTRY_COMPARE(window.touchReleasedCount, 1);
|
||||
QCOMPARE(window.mouseDevice, window.touchDevice);
|
||||
QCOMPARE(window.touchDevice->type(), QInputDevice::DeviceType::Mouse);
|
||||
QCOMPARE(window.touchPressLocalPos.toPoint(), localPos);
|
||||
QCOMPARE(window.touchPressGlobalPos.toPoint(), window.mapToGlobal(localPos));
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);
|
||||
|
||||
window.ignoreMouse = false;
|
||||
|
||||
QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
|
||||
QTest::mouseClick(&window, Qt::LeftButton, {}, localPos);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
|
||||
@ -1332,14 +1341,12 @@ void tst_QWindow::mouseToTouchTranslation()
|
||||
|
||||
window.ignoreMouse = true;
|
||||
|
||||
QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
|
||||
QTest::mouseClick(&window, Qt::LeftButton, {}, localPos);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// touch event synthesis disabled
|
||||
QTRY_COMPARE(window.touchPressedCount, 1);
|
||||
QTRY_COMPARE(window.touchReleasedCount, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void tst_QWindow::mouseToTouchLoop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user