From 62637c1a92f6a590bc9d2501fb45f046cb7080c3 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sat, 19 Feb 2022 23:10:01 +0100 Subject: [PATCH] seat: Do not assert on corner touch cases Consider the cases where we get a touch move or touch up but we never received a touch down before. In the case of move, we'll simulate a touchDown right there and move on with reality. In the case of touch up, we'll just ignore the event as simulating could just be more confusing. BUG: 450338 --- src/wayland/seat_interface.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index 0d75828131..d9be1a2486 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -1072,7 +1072,12 @@ void SeatInterface::notifyTouchMotion(qint32 id, const QPointF &globalPosition) if (!d->touch) { return; } - Q_ASSERT(d->globalTouch.ids.contains(id)); + auto itTouch = d->globalTouch.ids.constFind(id); + if (itTouch == d->globalTouch.ids.constEnd()) { + // This can happen in cases where the interaction started while the device was asleep + qCWarning(KWAYLAND_SERVER) << "Detected a touch move that never has been down, discarding"; + return; + } const auto pos = globalPosition - d->globalTouch.focus.offset; if (isDragTouch()) { @@ -1093,7 +1098,7 @@ void SeatInterface::notifyTouchMotion(qint32 id, const QPointF &globalPosition) } } } - Q_EMIT touchMoved(id, d->globalTouch.ids[id], globalPosition); + Q_EMIT touchMoved(id, *itTouch, globalPosition); } void SeatInterface::notifyTouchUp(qint32 id) @@ -1101,7 +1106,13 @@ void SeatInterface::notifyTouchUp(qint32 id) if (!d->touch) { return; } - Q_ASSERT(d->globalTouch.ids.contains(id)); + + auto itTouch = d->globalTouch.ids.find(id); + if (itTouch == d->globalTouch.ids.end()) { + // This can happen in cases where the interaction started while the device was asleep + qCWarning(KWAYLAND_SERVER) << "Detected a touch that never started, discarding"; + return; + } const qint32 serial = d->display->nextSerial(); if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch && d->drag.dragImplicitGrabSerial == d->globalTouch.ids.value(id)) { // the implicitly grabbing touch point has been upped @@ -1119,7 +1130,7 @@ void SeatInterface::notifyTouchUp(qint32 id) } } - d->globalTouch.ids.remove(id); + d->globalTouch.ids.erase(itTouch); } void SeatInterface::notifyTouchFrame()