From 6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 31 May 2019 08:38:16 +0200 Subject: 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 --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 2 +- .../qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 2 +- .../graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 4 ++-- .../auto/widgets/kernel/qapplication/tst_qapplication.cpp | 2 +- .../kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp | 4 ++-- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 14 +++++++------- tests/auto/widgets/util/qscroller/tst_qscroller.cpp | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 9ae127dbe0..94575e174d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -490,7 +490,7 @@ private slots: private: GraphicsItems paintedItems; - QTouchDevice *m_touchDevice = nullptr; + QPointingDevice *m_touchDevice = nullptr; }; void tst_QGraphicsItem::initMain() diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 8c2d89e34b..e0f4b67d50 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3871,7 +3871,7 @@ void tst_QGraphicsProxyWidget::forwardTouchEvent() EventSpy eventSpy(widget); - QTouchDevice *device = QTest::createTouchDevice(); + QPointingDevice *device = QTest::createTouchDevice(); QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 0); QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 0); diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index f0a276b9e7..7798bb52dc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -4849,8 +4849,8 @@ void tst_QGraphicsScene::focusOnTouch() scene.setFocusOnTouch(false); - QTouchDevice device; - device.setType(QTouchDevice::TouchPad); + QPointingDevice device; + device.setType(QInputDevice::DeviceType::TouchPad); QList touchPoints; QTouchEvent::TouchPoint point; point.setScenePos(QPointF(10, 10)); diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index b0689f5c16..a4a8eb956c 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1910,7 +1910,7 @@ void tst_QApplication::touchEventPropagation() release.setState(Qt::TouchPointReleased); releasedTouchPoints << release; - QTouchDevice *device = QTest::createTouchDevice(); + QPointingDevice *device = QTest::createTouchDevice(); { // touch event behavior on a window diff --git a/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp b/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp index bcf48c21df..e2dc7006b3 100644 --- a/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp +++ b/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -57,7 +57,7 @@ private Q_SLOTS: private: const int m_fingerDistance; - QTouchDevice *m_touchDevice; + QPointingDevice *m_touchDevice; }; tst_QGestureRecognizer::tst_QGestureRecognizer() diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index b05d6cd96e..c029e58acc 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -428,7 +428,7 @@ private: QPoint m_availableTopLeft; QPoint m_safeCursorPos; const bool m_windowsAnimationsEnabled; - QTouchDevice *m_touchScreen; + QPointingDevice *m_touchScreen; const int m_fuzz; }; @@ -11447,7 +11447,7 @@ void tst_QWidget::tabletTracking() qint64 uid = 1234UL; QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, - QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); + int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 1); QCOMPARE(widget.uid, uid); @@ -11456,7 +11456,7 @@ void tst_QWidget::tabletTracking() deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, - QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); + int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 2); @@ -11465,7 +11465,7 @@ void tst_QWidget::tabletTracking() QTRY_COMPARE(widget.trackingChangeEventCount, 2); QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, - QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); + int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.pressEventCount, 1); @@ -11473,12 +11473,12 @@ void tst_QWidget::tabletTracking() deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, - QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); + int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 3); QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, - QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); + int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.releaseEventCount, 1); @@ -11486,7 +11486,7 @@ void tst_QWidget::tabletTracking() deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, - QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); + int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 3); } diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index 5e71c1888d..83ff5ed668 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -128,7 +128,7 @@ private slots: void multipleWindows(); private: - QTouchDevice *m_touchScreen = QTest::createTouchDevice(); + QPointingDevice *m_touchScreen = QTest::createTouchDevice(); }; /*! \internal -- cgit v1.2.3