data-device: abort drag on unaccepted offers

fixes #6509
This commit is contained in:
Vaxry 2024-06-15 17:33:21 +02:00
parent fb82f6bcd7
commit 46ef6653be
2 changed files with 27 additions and 2 deletions

View file

@ -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();

View file

@ -175,6 +175,7 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
void dropDrag();
void completeDrag();
void resetDndState();
bool wasDragSuccessful();
//
SP<CWLDataDeviceResource> dataDeviceForClient(wl_client*);