diff --git a/src/xwayland/dnd.cpp b/src/xwayland/dnd.cpp index 5ac74e1e7f..5c4998441e 100644 --- a/src/xwayland/dnd.cpp +++ b/src/xwayland/dnd.cpp @@ -152,6 +152,11 @@ void Dnd::startDrag() m_currentDrag = new WlToXDrag(); auto source = new WlSource(this); source->setDataSourceIface(dragSource); + connect(dragSource, &KWaylandServer::AbstractDataSource::aboutToBeDestroyed, this, [this, source] { + if (source == wlSource()) { + setWlSource(nullptr); + } + }); setWlSource(source); ownSelection(true); } @@ -160,13 +165,9 @@ void Dnd::endDrag() { Q_ASSERT(m_currentDrag); - if (qobject_cast(m_currentDrag)) { - delete m_currentDrag; - setWlSource(nullptr); - } else { - connect(m_currentDrag, &Drag::finish, this, &Dnd::clearOldDrag); - m_oldDrags << m_currentDrag; - } + connect(m_currentDrag, &Drag::finish, this, &Dnd::clearOldDrag); + m_oldDrags << m_currentDrag; + m_currentDrag = nullptr; } diff --git a/src/xwayland/xwldrophandler.cpp b/src/xwayland/xwldrophandler.cpp index ee8116cdfd..87db157b30 100644 --- a/src/xwayland/xwldrophandler.cpp +++ b/src/xwayland/xwldrophandler.cpp @@ -34,6 +34,12 @@ void XwlDropHandler::drop() bool XwlDropHandler::handleClientMessage(xcb_client_message_event_t *event) { + for (auto visit : m_previousVisits) { + if (visit->handleClientMessage(event)) { + return true; + } + } + if (m_xvisit && m_xvisit->handleClientMessage(event)) { return true; } @@ -52,7 +58,15 @@ void XwlDropHandler::updateDragTarget(KWaylandServer::SurfaceInterface *surface, // leave current target if (m_xvisit) { m_xvisit->leave(); - delete m_xvisit; + if (!m_xvisit->finished()) { + connect(m_xvisit, &Xvisit::finish, this, [this](Xvisit *visit) { + m_previousVisits.removeOne(visit); + delete visit; + }); + m_previousVisits.push_back(m_xvisit); + } else { + delete m_xvisit; + } m_xvisit = nullptr; } if (client) { diff --git a/src/xwayland/xwldrophandler.h b/src/xwayland/xwldrophandler.h index 18169df410..acb71ce177 100644 --- a/src/xwayland/xwldrophandler.h +++ b/src/xwayland/xwldrophandler.h @@ -34,6 +34,7 @@ public: private: void drop() override; Xvisit *m_xvisit = nullptr; + QVector m_previousVisits; }; } }