xwayland: Handle drag being cancelled

There was no handling for the drop being cancelled at all, leading to
leaked WlVisit and XtoWlDrag objects. X clients could also be confused
about the state of the drag and for example not being able to start another
drag.
BUG:449362
This commit is contained in:
David Redondo 2022-02-03 14:26:05 +01:00
parent 843cee3d66
commit b1d0928c8e
2 changed files with 12 additions and 1 deletions

View file

@ -47,12 +47,17 @@ public:
void dndFinished() override {
Q_EMIT finished();
}
void dndCancelled() override {
Q_EMIT cancelled();
}
bool isAccepted() const override;
Q_SIGNALS:
void dataRequested(const QString &mimeType, qint32 fd);
void dropped();
void finished();
void cancelled();
private:
QStringList m_mimeTypes;

View file

@ -101,6 +101,12 @@ XToWlDrag::XToWlDrag(X11Source *source)
connect(&m_selectionSource, &XwlDataSource::finished, this, [this] {
checkForFinished();
});
connect(&m_selectionSource, &XwlDataSource::cancelled, this, [this] {
if (m_visit && !m_visit->leave()) {
connect(m_visit, &WlVisit::finish, this, &XToWlDrag::checkForFinished);
}
checkForFinished();
});
connect(&m_selectionSource, &XwlDataSource::dataRequested, source, &X11Source::startTransfer);
auto *seat = waylandServer()->seat();
@ -229,7 +235,7 @@ bool XToWlDrag::checkForFinished()
if (!m_visit->finished()) {
return false;
}
if (m_dataRequests.size() == 0) {
if (m_dataRequests.size() == 0 && m_selectionSource.isAccepted()) {
// need to wait for first data request
return false;
}