diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-31 08:38:16 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-06-16 22:06:56 +0200 |
commit | 6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 (patch) | |
tree | 61f29061a4cbaf925ef0ab7ba9fafc1db9ee4ef3 /src/widgets | |
parent | 0a2e3ce85ce788b8a07380a458faf4ed3817d0c0 (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 'src/widgets')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsscene.cpp | 12 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 22 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication_p.h | 8 | ||||
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 8 | ||||
-rw-r--r-- | src/widgets/util/qflickgesture.cpp | 4 |
5 files changed, 26 insertions, 28 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index e64f7cda9d..71bfff2ef5 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -235,7 +235,7 @@ #include <QtGui/qpainterpath.h> #include <QtGui/qpixmapcache.h> #include <QtGui/qpolygon.h> -#include <QtGui/qtouchdevice.h> +#include <QtGui/qpointingdevice.h> #include <QtWidgets/qstyleoption.h> #if QT_CONFIG(tooltip) #include <QtWidgets/qtooltip.h> @@ -5859,7 +5859,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) // update state QGraphicsItem *item = nullptr; if (touchPoint.state() == Qt::TouchPointPressed) { - if (sceneTouchEvent->device()->type() == QTouchDevice::TouchPad) { + if (sceneTouchEvent->pointingDevice()->type() == QInputDevice::DeviceType::TouchPad) { // on touch-pad devices, send all touch points to the same item item = itemForTouchPointId.isEmpty() ? 0 @@ -5874,7 +5874,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.constFirst(); } - if (sceneTouchEvent->device()->type() == QTouchDevice::TouchScreen) { + if (sceneTouchEvent->pointingDevice()->type() == QInputDevice::DeviceType::TouchScreen) { // on touch-screens, combine this touch point with the closest one we find int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePosition()); QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId); @@ -5938,13 +5938,11 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) break; } - QTouchEvent touchEvent(eventType); + QTouchEvent touchEvent(eventType, sceneTouchEvent->pointingDevice(), sceneTouchEvent->modifiers(), it.value().first, it.value().second); + // TODO more constructor args and fewer setters? touchEvent.setWindow(sceneTouchEvent->window()); touchEvent.setTarget(sceneTouchEvent->target()); - touchEvent.setDevice(sceneTouchEvent->device()); touchEvent.setModifiers(sceneTouchEvent->modifiers()); - touchEvent.setTouchPointStates(it.value().first); - touchEvent.setTouchPoints(it.value().second); touchEvent.setTimestamp(sceneTouchEvent->timestamp()); switch (touchEvent.type()) { diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 1af94efdf9..a2862a56e1 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -79,7 +79,7 @@ #include <QtGui/qstylehints.h> #include <QtGui/qinputmethod.h> #include <QtGui/private/qwindow_p.h> -#include <QtGui/qtouchdevice.h> +#include <QtGui/qpointingdevice.h> #include <qpa/qplatformtheme.h> #if QT_CONFIG(whatsthis) #include <QtWidgets/QWhatsThis> @@ -3120,11 +3120,10 @@ bool QApplication::notify(QObject *receiver, QEvent *e) QPointF relpos = tablet->position(); bool eventAccepted = tablet->isAccepted(); while (w) { - QTabletEvent te(tablet->type(), relpos, tablet->globalPosition(), - tablet->deviceType(), tablet->pointerType(), + QTabletEvent te(tablet->type(), tablet->pointingDevice(), relpos, tablet->globalPosition(), tablet->pressure(), tablet->xTilt(), tablet->yTilt(), tablet->tangentialPressure(), tablet->rotation(), tablet->z(), - tablet->modifiers(), tablet->uniqueId(), tablet->button(), tablet->buttons()); + tablet->modifiers(), tablet->button(), tablet->buttons()); te.spont = e->spontaneous(); te.setAccepted(false); res = d->notify_helper(w, w == receiver ? tablet : &te); @@ -3975,7 +3974,7 @@ void QApplicationPrivate::cleanupMultitouch_sys() { } -QWidget *QApplicationPrivate::findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint) +QWidget *QApplicationPrivate::findClosestTouchPointTarget(const QPointingDevice *device, const QTouchEvent::TouchPoint &touchPoint) { const QPointF screenPos = touchPoint.globalPosition(); int closestTouchPointId = -1; @@ -4007,12 +4006,13 @@ void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent for (int i = 0, tc = touchEvent->touchPoints().count(); i < tc; ++i) { const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i); - activeTouchPoints[QGuiApplicationPrivate::ActiveTouchPointsKey(touchEvent->device(), touchPoint.id())].target = widget; + activeTouchPoints[QGuiApplicationPrivate::ActiveTouchPointsKey( + touchEvent->pointingDevice(), touchPoint.id())].target = widget; } } bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, - QTouchDevice *device, + const QPointingDevice *device, const QList<QTouchEvent::TouchPoint> &touchPoints, ulong timestamp) { @@ -4032,7 +4032,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, ActiveTouchPointsKey touchInfoKey(device, touchPoint.id()); ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey]; if (touchPoint.state() == Qt::TouchPointPressed) { - if (device->type() == QTouchDevice::TouchPad) { + if (device->type() == QInputDevice::DeviceType::TouchPad) { // on touch-pads, send all touch points to the same widget target = d->activeTouchPoints.isEmpty() ? QPointer<QObject>() @@ -4050,7 +4050,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, target = window; } - if (device->type() == QTouchDevice::TouchScreen) { + if (device->type() == QInputDevice::DeviceType::TouchScreen) { QWidget *closestWidget = d->findClosestTouchPointTarget(device, touchPoint); QWidget *widget = static_cast<QWidget *>(target.data()); if (closestWidget @@ -4073,7 +4073,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, // Single-touch events are normally not sent unless WA_TouchPadAcceptSingleTouchEvents is set. // In Qt 4 this check was in OS X-only code. That behavior is preserved here by the #ifdef. if (touchPoints.count() == 1 - && device->type() == QTouchDevice::TouchPad + && device->type() == QInputDevice::DeviceType::TouchPad && !targetWidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents)) continue; #endif @@ -4153,7 +4153,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, return accepted; } -void QApplicationPrivate::translateTouchCancel(QTouchDevice *device, ulong timestamp) +void QApplicationPrivate::translateTouchCancel(const QPointingDevice *device, ulong timestamp) { QTouchEvent touchEvent(QEvent::TouchCancel, device, QGuiApplication::keyboardModifiers()); touchEvent.setTimestamp(timestamp); diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index e1e391b13d..e9595a9fbb 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -81,7 +81,7 @@ class QGraphicsScene; class QObject; class QWidget; class QSocketNotifier; -class QTouchDevice; +class QPointingDevice; #ifndef QT_NO_GESTURES class QGestureManager; #endif @@ -247,15 +247,15 @@ public: void initializeMultitouch_sys(); void cleanupMultitouch(); void cleanupMultitouch_sys(); - QWidget *findClosestTouchPointTarget(QTouchDevice *device, const QTouchEvent::TouchPoint &touchPoint); + QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QTouchEvent::TouchPoint &touchPoint); void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint); void removeTouchPoint(int touchPointId); void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent); static bool translateRawTouchEvent(QWidget *widget, - QTouchDevice *device, + const QPointingDevice *device, const QList<QTouchEvent::TouchPoint> &touchPoints, ulong timestamp); - static void translateTouchCancel(QTouchDevice *device, ulong timestamp); + static void translateTouchCancel(const QPointingDevice *device, ulong timestamp); QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override; private: diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index be840e24eb..2faedccc20 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -692,14 +692,14 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) void QWidgetWindow::handleTouchEvent(QTouchEvent *event) { if (event->type() == QEvent::TouchCancel) { - QApplicationPrivate::translateTouchCancel(event->device(), event->timestamp()); + QApplicationPrivate::translateTouchCancel(event->pointingDevice(), event->timestamp()); event->accept(); } else if (QApplicationPrivate::inPopupMode()) { // Ignore touch events for popups. This will cause QGuiApplication to synthesise mouse // events instead, which QWidgetWindow::handleMouseEvent will forward correctly: event->ignore(); } else { - event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event->device(), event->touchPoints(), event->timestamp())); + event->setAccepted(QApplicationPrivate::translateRawTouchEvent(m_widget, event->pointingDevice(), event->touchPoints(), event->timestamp())); } } @@ -1071,9 +1071,9 @@ void QWidgetWindow::handleTabletEvent(QTabletEvent *event) if (widget) { QPointF delta = event->globalPosition() - event->globalPosition().toPoint(); QPointF mapped = widget->mapFromGlobal(event->globalPosition().toPoint()) + delta; - QTabletEvent ev(event->type(), mapped, event->globalPosition(), event->deviceType(), event->pointerType(), + QTabletEvent ev(event->type(), event->pointingDevice(), mapped, event->globalPosition(), event->pressure(), event->xTilt(), event->yTilt(), event->tangentialPressure(), - event->rotation(), event->z(), event->modifiers(), event->uniqueId(), event->button(), event->buttons()); + event->rotation(), event->z(), event->modifiers(), event->button(), event->buttons()); ev.setTimestamp(event->timestamp()); ev.setAccepted(false); QGuiApplication::forwardEvent(widget, &ev, event); diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp index ecaf43e207..7ebd37d854 100644 --- a/src/widgets/util/qflickgesture.cpp +++ b/src/widgets/util/qflickgesture.cpp @@ -48,7 +48,7 @@ #include "qgraphicsview.h" #endif #include "qscroller.h" -#include <QtGui/qtouchdevice.h> +#include <QtGui/qpointingdevice.h> #include "private/qapplication_p.h" #include "private/qevent_p.h" #include "private/qflickgesture_p.h" @@ -547,7 +547,7 @@ QGestureRecognizer::Result QFlickGestureRecognizer::recognize(QGesture *state, if (!inputType) inputType = QScroller::InputMove; - if (te->device()->type() == QTouchDevice::TouchPad) { + if (te->pointingDevice()->type() == QInputDevice::DeviceType::TouchPad) { if (te->touchPoints().count() != 2) // 2 fingers on pad return Ignore; |