diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-06-15 17:33:21 +0200 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-06-15 17:33:21 +0200 |
| commit | 46ef6653be90f1a3e2a8cecc1fd9112dc3c6f464 (patch) | |
| tree | cd621a64b3bceccc4caf28c48ad96818c79a6ec8 /src/protocols/core/DataDevice.cpp | |
| parent | fb82f6bcd7d829a3ab2d2cb7d9a27f3837abfb80 (diff) | |
data-device: abort drag on unaccepted offers
fixes #6509
Diffstat (limited to 'src/protocols/core/DataDevice.cpp')
| -rw-r--r-- | src/protocols/core/DataDevice.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp index c1de8f83..86b372bf 100644 --- a/src/protocols/core/DataDevice.cpp +++ b/src/protocols/core/DataDevice.cpp @@ -13,13 +13,17 @@ CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataS return; resource->setDestroy([this](CWlDataOffer* r) { - if (!dead) + if (!dead && (recvd || accepted)) PROTO::data->completeDrag(); + else + PROTO::data->abortDrag(); PROTO::data->destroyResource(this); }); resource->setOnDestroy([this](CWlDataOffer* r) { - if (!dead) + if (!dead && (recvd || accepted)) PROTO::data->completeDrag(); + else + PROTO::data->abortDrag(); PROTO::data->destroyResource(this); }); @@ -592,6 +596,11 @@ void CWLDataDeviceProtocol::dropDrag() { return; } + if (!wasDragSuccessful()) { + abortDrag(); + return; + } + dnd.currentSource->sendDndDropPerformed(); dnd.focusedDevice->sendDrop(); dnd.focusedDevice->sendLeave(); @@ -603,6 +612,21 @@ void CWLDataDeviceProtocol::dropDrag() { dnd.overriddenCursor = false; } +bool CWLDataDeviceProtocol::wasDragSuccessful() { + if (!dnd.focusedDevice || !dnd.currentSource) + return false; + + for (auto& o : m_vOffers) { + if (o->dead || !o->source || !o->source->hasDnd()) + continue; + + if (o->recvd || o->accepted) + return true; + } + + return false; +} + void CWLDataDeviceProtocol::completeDrag() { resetDndState(); |
