summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qtouchevent
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-31 08:38:16 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-06-16 22:06:56 +0200
commit6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 (patch)
tree61f29061a4cbaf925ef0ab7ba9fafc1db9ee4ef3 /tests/auto/gui/kernel/qtouchevent
parent0a2e3ce85ce788b8a07380a458faf4ed3817d0c0 (diff)
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does not provide enough information: if it is synthesized, it could have come from any device for which mouse events are synthesized, not only from a touchscreen. By providing in every QInputEvent as complete information about the actual source device as possible, we will enable very fine-tuned behavior in the object that handles each event. Further, we would like to support multiple keyboards, pointing devices, and named groups of devices that are known as "seats" in Wayland. In Qt 5, QPA plugins registered each touchscreen as it was discovered. Now we extend this pattern to all input devices. This new requirement can be implemented gradually; for now, if a QTWSI input event is received wtihout a device pointer, a default "core" device will be created on-the-fly, and a warning emitted. In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when multiple devices were in use simultaneously. Now that each event identifies the device it came from, this hack is no longer needed. A stub of the new QPointerEvent is added; it will be developed further in subsequent patches. [ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer to an instance of QInputDevice, or the subclass QPointingDevice in case of mouse, touch and tablet events. Each platform plugin is expected to create the device instances, register them, and provide valid pointers with all input events. If this is not done, warnings are emitted and default devices are created as necessary. When the device has accurate information, it provides the opportunity to fine-tune behavior depending on device type and capabilities: for example if a QMouseEvent is synthesized from a touchscreen, the recipient can see which touchscreen it came from. Each device also has a seatName to distinguish users on multi-user windowing systems. Touchpoint IDs are no longer unique on their own, but the combination of ID and device is. Fixes: QTBUG-46412 Fixes: QTBUG-72167 Task-number: QTBUG-69433 Task-number: QTBUG-52430 Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel/qtouchevent')
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp80
1 files changed, 37 insertions, 43 deletions
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index 4499ba1334..7be68dd699 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -36,7 +36,7 @@
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qwindowsysteminterface_p.h>
#include <private/qhighdpiscaling_p.h>
-#include <private/qtouchdevice_p.h>
+#include <private/qpointingdevice_p.h>
class tst_QTouchEventWidget : public QWidget
{
@@ -46,7 +46,7 @@ public:
bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd;
bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd;
ulong timestamp;
- QTouchDevice *deviceFromEvent;
+ const QPointingDevice *deviceFromEvent;
explicit tst_QTouchEventWidget(QWidget *parent = nullptr) : QWidget(parent)
{
@@ -73,7 +73,7 @@ public:
seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd;
touchBeginPoints = static_cast<QTouchEvent *>(event)->touchPoints();
timestamp = static_cast<QTouchEvent *>(event)->timestamp();
- deviceFromEvent = static_cast<QTouchEvent *>(event)->device();
+ deviceFromEvent = static_cast<QTouchEvent *>(event)->pointingDevice();
event->setAccepted(acceptTouchBegin);
if (deleteInTouchBegin)
delete this;
@@ -84,7 +84,7 @@ public:
seenTouchUpdate = seenTouchBegin && !seenTouchEnd;
touchUpdatePoints = static_cast<QTouchEvent *>(event)->touchPoints();
timestamp = static_cast<QTouchEvent *>(event)->timestamp();
- deviceFromEvent = static_cast<QTouchEvent *>(event)->device();
+ deviceFromEvent = static_cast<QTouchEvent *>(event)->pointingDevice();
event->setAccepted(acceptTouchUpdate);
if (deleteInTouchUpdate)
delete this;
@@ -95,7 +95,7 @@ public:
seenTouchEnd = seenTouchBegin && !seenTouchEnd;
touchEndPoints = static_cast<QTouchEvent *>(event)->touchPoints();
timestamp = static_cast<QTouchEvent *>(event)->timestamp();
- deviceFromEvent = static_cast<QTouchEvent *>(event)->device();
+ deviceFromEvent = static_cast<QTouchEvent *>(event)->pointingDevice();
event->setAccepted(acceptTouchEnd);
if (deleteInTouchEnd)
delete this;
@@ -213,22 +213,21 @@ private slots:
void testMultiDevice();
private:
- QTouchDevice *touchScreenDevice;
- QTouchDevice *secondaryTouchScreenDevice;
- QTouchDevice *touchPadDevice;
+ QPointingDevice *touchScreenDevice;
+ QPointingDevice *secondaryTouchScreenDevice;
+ QPointingDevice *touchPadDevice;
};
tst_QTouchEvent::tst_QTouchEvent()
: touchScreenDevice(QTest::createTouchDevice())
, secondaryTouchScreenDevice(QTest::createTouchDevice())
- , touchPadDevice(QTest::createTouchDevice(QTouchDevice::TouchPad))
+ , touchPadDevice(QTest::createTouchDevice(QInputDevice::DeviceType::TouchPad))
{
}
void tst_QTouchEvent::cleanup()
{
QVERIFY(QGuiApplication::topLevelWindows().isEmpty());
- QWindowSystemInterfacePrivate::clearPointIdMap();
}
void tst_QTouchEvent::qPointerUniqueId()
@@ -641,8 +640,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
- const int touchPointId = (QTouchDevicePrivate::get(touchScreenDevice)->id << 24) + 1;
- QCOMPARE(touchBeginPoint.id(), touchPointId);
+ QCOMPARE(touchBeginPoint.id(), 0);
QCOMPARE(touchBeginPoint.state(), rawTouchPoint.state());
QCOMPARE(touchBeginPoint.position(), pos);
QCOMPARE(touchBeginPoint.pressPosition(), pos);
@@ -678,7 +676,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
QTouchEvent::TouchPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
- QCOMPARE(touchUpdatePoint.id(), touchPointId);
+ QCOMPARE(touchUpdatePoint.id(), 0);
QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state());
QCOMPARE(touchUpdatePoint.position(), pos + delta);
QCOMPARE(touchUpdatePoint.pressPosition(), pos);
@@ -711,7 +709,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchEndPoints.count(), 1);
QTouchEvent::TouchPoint touchEndPoint = touchWidget.touchEndPoints.first();
- QCOMPARE(touchEndPoint.id(), touchPointId);
+ QCOMPARE(touchEndPoint.id(), 0);
QCOMPARE(touchEndPoint.state(), rawTouchPoint.state());
QCOMPARE(touchEndPoint.position(), pos + delta + delta);
QCOMPARE(touchEndPoint.pressPosition(), pos);
@@ -785,7 +783,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(!rightWidget.seenTouchEnd);
QCOMPARE(leftWidget.touchBeginPoints.count(), 1);
QCOMPARE(rightWidget.touchBeginPoints.count(), 1);
- const int touchPointId0 = (QTouchDevicePrivate::get(touchScreenDevice)->id << 24) + 1;
+ const int touchPointId0 = 0;
const int touchPointId1 = touchPointId0 + 1;
{
QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchBeginPoints.first();
@@ -980,7 +978,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QRectF screenGeometry = touchWidget.screen()->geometry();
QVector<QTouchEvent::TouchPoint> rawTouchPoints(3);
- rawTouchPoints[0].setId(0);
+ rawTouchPoints[0].setId(1);
rawTouchPoints[1].setId(10);
rawTouchPoints[2].setId(11);
@@ -1000,9 +998,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
- const int touchPointId = (QTouchDevicePrivate::get(touchScreenDevice)->id << 24) + 1;
- const int secTouchPointId = (QTouchDevicePrivate::get(secondaryTouchScreenDevice)->id << 24) + 2;
- QCOMPARE(touchBeginPoint.id(), touchPointId);
+ QCOMPARE(touchBeginPoint.id(), 1);
QCOMPARE(touchBeginPoint.state(), rawTouchPoints[0].state());
QCOMPARE(touchBeginPoint.position(), pos);
@@ -1020,7 +1016,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
touchBeginPoint = touchWidget.touchBeginPoints[0];
- QCOMPARE(touchBeginPoint.id(), (QTouchDevicePrivate::get(secondaryTouchScreenDevice)->id << 24) + 2);
+ QCOMPARE(touchBeginPoint.id(), 10);
QCOMPARE(touchBeginPoint.state(), rawTouchPoints[1].state());
QCOMPARE(touchBeginPoint.position(), pos);
@@ -1038,7 +1034,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
touchBeginPoint = touchWidget.touchBeginPoints[0];
- QCOMPARE(touchBeginPoint.id(), (QTouchDevicePrivate::get(secondaryTouchScreenDevice)->id << 24) + 3);
+ QCOMPARE(touchBeginPoint.id(), 11);
QCOMPARE(touchBeginPoint.state(), rawTouchPoints[2].state());
QCOMPARE(touchBeginPoint.position(), pos);
@@ -1055,7 +1051,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
QTouchEvent::TouchPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
- QCOMPARE(touchUpdatePoint.id(), touchPointId);
+ QCOMPARE(touchUpdatePoint.id(), 1);
QCOMPARE(touchUpdatePoint.state(), rawTouchPoints[0].state());
QCOMPARE(touchUpdatePoint.position(), pos + delta);
@@ -1072,7 +1068,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchEndPoints.count(), 1);
QTouchEvent::TouchPoint touchEndPoint = touchWidget.touchEndPoints.first();
- QCOMPARE(touchEndPoint.id(), touchPointId);
+ QCOMPARE(touchEndPoint.id(), 1);
QCOMPARE(touchEndPoint.state(), rawTouchPoints[0].state());
QCOMPARE(touchEndPoint.position(), pos + delta + delta);
@@ -1096,8 +1092,8 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(touchWidget.touchUpdatePoints[0].id(), secTouchPointId);
- QCOMPARE(touchWidget.touchUpdatePoints[1].id(), secTouchPointId + 1);
+ QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 10);
+ QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 11);
// releasing the last point on the secondary touchscreen translates to TouchEnd
touchWidget.seenTouchEnd = false;
@@ -1111,7 +1107,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
QVERIFY(touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchEndPoints.count(), 1);
touchEndPoint = touchWidget.touchEndPoints.first();
- QCOMPARE(touchEndPoint.id(), secTouchPointId + 1);
+ QCOMPARE(touchEndPoint.id(), 11);
QCOMPARE(touchEndPoint.state(), rawTouchPoints[2].state());
}
@@ -1394,11 +1390,9 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchBeginPoints.count(), 2);
- const int initialTouchPointId = (QTouchDevicePrivate::get(touchScreenDevice)->id << 24) + 1;
-
for (int i = 0; i < touchWidget.touchBeginPoints.count(); ++i) {
QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.at(i);
- QCOMPARE(touchBeginPoint.id(), initialTouchPointId + i);
+ QCOMPARE(touchBeginPoint.id(), i);
QCOMPARE(touchBeginPoint.state(), rawTouchPoints[i].state());
}
@@ -1417,8 +1411,8 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(touchWidget.touchUpdatePoints.at(0).id(), initialTouchPointId);
- QCOMPARE(touchWidget.touchUpdatePoints.at(1).id(), initialTouchPointId + 1);
+ QCOMPARE(touchWidget.touchUpdatePoints.at(0).id(), 0);
+ QCOMPARE(touchWidget.touchUpdatePoints.at(1).id(), 1);
// release last point
p0.setState(Qt::TouchPointStationary);
@@ -1432,8 +1426,8 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(touchWidget.touchUpdatePoints[0].id(), initialTouchPointId);
- QCOMPARE(touchWidget.touchUpdatePoints[1].id(), initialTouchPointId + 1);
+ QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
+ QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 1);
// Press last point again, id should increase
p1.setState(Qt::TouchPointPressed);
@@ -1446,8 +1440,8 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(touchWidget.touchUpdatePoints[0].id(), initialTouchPointId);
- QCOMPARE(touchWidget.touchUpdatePoints[1].id(), initialTouchPointId + 2);
+ QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
+ QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42);
// release everything
p0.setState(Qt::TouchPointReleased);
@@ -1460,8 +1454,8 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(touchWidget.touchUpdatePoints[0].id(), initialTouchPointId);
- QCOMPARE(touchWidget.touchUpdatePoints[1].id(), initialTouchPointId + 2);
+ QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
+ QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42);
}
void tst_QTouchEvent::deleteInEventHandler()
@@ -1782,7 +1776,7 @@ public:
QList<QTouchEvent::TouchPoint> points;
QEvent::Type lastSeenType;
};
- QMap<QTouchDevice *, TouchInfo> d;
+ QMap<const QPointingDevice *, TouchInfo> d;
};
bool WindowTouchEventFilter::eventFilter(QObject *, QEvent *event)
@@ -1791,7 +1785,7 @@ bool WindowTouchEventFilter::eventFilter(QObject *, QEvent *event)
|| event->type() == QEvent::TouchUpdate
|| event->type() == QEvent::TouchEnd) {
QTouchEvent *te = static_cast<QTouchEvent *>(event);
- TouchInfo &td = d[te->device()];
+ TouchInfo &td = d[te->pointingDevice()];
if (event->type() == QEvent::TouchBegin)
td.points.clear();
td.points.append(te->touchPoints());
@@ -1813,7 +1807,7 @@ void tst_QTouchEvent::testQGuiAppDelivery()
QList<QWindowSystemInterface::TouchPoint> points;
// Pass empty list, should be ignored.
- QWindowSystemInterface::handleTouchEvent(&w, 0, points);
+ QWindowSystemInterface::handleTouchEvent(&w, nullptr, points);
QCoreApplication::processEvents();
QCOMPARE(filter.d.isEmpty(), true);
@@ -1823,8 +1817,8 @@ void tst_QTouchEvent::testQGuiAppDelivery()
tp.area = QRectF(120, 120, 20, 20);
points.append(tp);
- // Pass 0 as device, should be ignored.
- QWindowSystemInterface::handleTouchEvent(&w, 0, points);
+ // Null device: should be ignored.
+ QWindowSystemInterface::handleTouchEvent(&w, nullptr, points);
QCoreApplication::processEvents();
QCOMPARE(filter.d.isEmpty(), true);
@@ -1855,7 +1849,7 @@ void tst_QTouchEvent::testQGuiAppDelivery()
void tst_QTouchEvent::testMultiDevice()
{
- QTouchDevice *deviceTwo = QTest::createTouchDevice();
+ QPointingDevice *deviceTwo = QTest::createTouchDevice();
QWindow w;
w.setGeometry(100, 100, 100, 100);