wayland: End the drag properly when user cancels the drag

This commit is contained in:
Sergio Martins
2020-10-15 19:02:46 +01:00
parent d44a173945
commit f3d7400c15
2 changed files with 14 additions and 3 deletions

View File

@@ -307,6 +307,8 @@ StateDraggingWayland::~StateDraggingWayland()
void StateDraggingWayland::onEntry(QEvent *)
{
qCDebug(state) << "StateDragging entered";
if (m_inQDrag) {
// Maybe we can exit the state due to the nested event loop of QDrag::Exec();
qWarning() << Q_FUNC_INFO << "Impossible!";
@@ -331,10 +333,10 @@ void StateDraggingWayland::onEntry(QEvent *)
drag.setMimeData(mimeData);
qApp->installEventFilter(q);
drag.exec();
const Qt::DropAction result = drag.exec();
qApp->removeEventFilter(q);
qDebug() << "Drag ended";
if (result == Qt::IgnoreAction)
Q_EMIT q->dragCanceled();
}
bool StateDraggingWayland::handleMouseButtonRelease(QPoint /*globalPos*/)
@@ -374,6 +376,8 @@ bool StateDraggingWayland::handleDrop(QDropEvent *ev, DropArea *dropArea)
return false; // Not for us, some other user drag.
if (dropArea->drop(q->m_windowBeingDragged.get(), ev->pos())) {
ev->setDropAction(Qt::MoveAction);
ev->accept();
Q_EMIT q->dropped();
} else {
Q_EMIT q->dragCanceled();