From 8af2a010c7bb6c578d453fd3b0fff91b79274631 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 26 Oct 2021 13:32:05 +0200 Subject: [PATCH] Implement drag surface transformation for touch events Reusing the pointer transformation causes drag with touch to send completely incorrect coordinates. So implement the "TODO" item about surface transformation for touch, so we send correct drag events for touch. --- src/wayland/seat_interface.cpp | 9 +++++---- src/wayland/seat_interface_p.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index ca614986d3..8b24797aa3 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -1027,7 +1027,8 @@ void SeatInterface::setFocusedTouchSurface(SurfaceInterface *surface, const QPoi } d->globalTouch.focus = SeatInterfacePrivate::Touch::Focus(); d->globalTouch.focus.surface = surface; - d->globalTouch.focus.offset = surfacePosition; + setFocusedTouchSurfacePosition(surfacePosition); + if (d->globalTouch.focus.surface) { d->globalTouch.focus.destroyConnection = connect(surface, &QObject::destroyed, this, [this]() { if (isTouchSequence()) { @@ -1043,6 +1044,8 @@ void SeatInterface::setFocusedTouchSurface(SurfaceInterface *surface, const QPoi void SeatInterface::setFocusedTouchSurfacePosition(const QPointF &surfacePosition) { d->globalTouch.focus.offset = surfacePosition; + d->globalTouch.focus.transformation = QMatrix4x4(); + d->globalTouch.focus.transformation.translate(-surfacePosition.x(), -surfacePosition.y()); } void SeatInterface::notifyTouchDown(qint32 id, const QPointF &globalPosition) @@ -1322,7 +1325,7 @@ void SeatInterface::startDrag(AbstractDataSource *dragSource, SurfaceInterface * d->drag.transformation = d->globalPointer.focus.transformation; } else if (hasImplicitTouchGrab(dragSerial)) { d->drag.mode = SeatInterfacePrivate::Drag::Mode::Touch; - // TODO: touch transformation + d->drag.transformation = d->globalTouch.focus.transformation; } else { // no implicit grab, abort drag return; @@ -1331,8 +1334,6 @@ void SeatInterface::startDrag(AbstractDataSource *dragSource, SurfaceInterface * // set initial drag target to ourself d->drag.surface = originSurface; - // TODO: transformation needs to be either pointer or touch - d->drag.transformation = d->globalPointer.focus.transformation; d->drag.source = dragSource; if (dragSource) { diff --git a/src/wayland/seat_interface_p.h b/src/wayland/seat_interface_p.h index 00190a5565..aec7d42c69 100644 --- a/src/wayland/seat_interface_p.h +++ b/src/wayland/seat_interface_p.h @@ -108,6 +108,7 @@ public: QMetaObject::Connection destroyConnection; QPointF offset = QPointF(); QPointF firstTouchPos; + QMatrix4x4 transformation; }; Focus focus; QMap ids;