From fccbe4e02771603885922d15b0e29e9e845b01dd Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 3 Mar 2022 09:09:27 +0000 Subject: [PATCH] Add a methood to fore cancel any drag in progress This is needed to cancel drags by pressing Escape which is resposibility of the compositor CCBUG:405267 --- src/wayland/seat_interface.cpp | 26 +++++++++++++++++--------- src/wayland/seat_interface.h | 5 +++++ src/wayland/seat_interface_p.h | 4 ++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index d9be1a2486..2bdfa5543a 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -195,6 +195,14 @@ KWaylandServer::AbstractDropHandler *SeatInterface::dropHandlerForSurface(Surfac return list.first(); } +void SeatInterface::cancelDrag() +{ + if (d->drag.mode != SeatInterfacePrivate::Drag::Mode::None) { + // cancel the drag, don't drop. serial does not matter + d->cancelDrag(); + } +} + void SeatInterfacePrivate::registerDataControlDevice(DataControlDeviceV1Interface *dataDevice) { Q_ASSERT(dataDevice->seat() == q); @@ -268,16 +276,16 @@ void SeatInterfacePrivate::registerPrimarySelectionDevice(PrimarySelectionDevice } } -void SeatInterfacePrivate::cancelDrag(quint32 serial) +void SeatInterfacePrivate::cancelDrag() { if (drag.target) { - drag.target->updateDragTarget(nullptr, serial); + drag.target->updateDragTarget(nullptr, 0); drag.target = nullptr; } - endDrag(serial); + endDrag(); } -void SeatInterfacePrivate::endDrag(quint32 serial) +void SeatInterfacePrivate::endDrag() { QObject::disconnect(drag.dragSourceDestroyConnection); @@ -295,7 +303,7 @@ void SeatInterfacePrivate::endDrag(quint32 serial) } if (dragTargetDevice) { - dragTargetDevice->updateDragTarget(nullptr, serial); + dragTargetDevice->updateDragTarget(nullptr, 0); } drag = Drag(); @@ -708,7 +716,7 @@ void SeatInterface::notifyPointerButton(quint32 button, PointerButtonState state // not our drag button - ignore return; } - d->endDrag(serial); + d->endDrag(); return; } } @@ -972,7 +980,7 @@ void SeatInterface::notifyTouchCancel() if (d->drag.mode == SeatInterfacePrivate::Drag::Mode::Touch) { // cancel the drag, don't drop. serial does not matter - d->cancelDrag(0); + d->cancelDrag(); } d->globalTouch.ids.clear(); } @@ -1116,7 +1124,7 @@ void SeatInterface::notifyTouchUp(qint32 id) 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 - d->endDrag(serial); + d->endDrag(); } d->touch->sendUp(id, serial); @@ -1336,7 +1344,7 @@ void SeatInterface::startDrag(AbstractDataSource *dragSource, SurfaceInterface * d->drag.source = dragSource; if (dragSource) { d->drag.dragSourceDestroyConnection = QObject::connect(dragSource, &AbstractDataSource::aboutToBeDestroyed, this, [this] { - d->cancelDrag(d->display->nextSerial()); + d->cancelDrag(); }); } d->drag.dragIcon = dragIcon; diff --git a/src/wayland/seat_interface.h b/src/wayland/seat_interface.h index da626e2fbd..4aee61abe0 100644 --- a/src/wayland/seat_interface.h +++ b/src/wayland/seat_interface.h @@ -229,6 +229,11 @@ public: AbstractDropHandler *dropHandlerForSurface(SurfaceInterface *surface) const; + /** + * If there is a current drag in progress, force it to cancel + */ + void cancelDrag(); + /** * @name Pointer related methods */ diff --git a/src/wayland/seat_interface_p.h b/src/wayland/seat_interface_p.h index 0ed2fedb87..a4b2337fd8 100644 --- a/src/wayland/seat_interface_p.h +++ b/src/wayland/seat_interface_p.h @@ -41,8 +41,8 @@ public: void registerPrimarySelectionDevice(PrimarySelectionDeviceV1Interface *primarySelectionDevice); void registerDataDevice(DataDeviceInterface *dataDevice); void registerDataControlDevice(DataControlDeviceV1Interface *dataDevice); - void endDrag(quint32 serial); - void cancelDrag(quint32 serial); + void endDrag(); + void cancelDrag(); SeatInterface *q; QPointer display;