Commit 2952bd8b authored by David Edmundson's avatar David Edmundson
Browse files

[xwl] Cache KWaylandServer::DataSourceInterface as a QPointer

Seat correctly emits dragEnded when a DataSourceInterface is destroyed,
and stops the drag.

However WlToXSource lives slightly longer to finish handling any other
visits. See the guarded delete statement in Dnd::endDrag.

With recent fixes use is mostly a hypothetical, but we still don't want
dangling pointers in our code.

(cherry picked from commit 2d681965)
parent f375b152
......@@ -20,8 +20,8 @@
#include <KWayland/Client/datadevice.h>
#include <KWayland/Client/datasource.h>
#include <KWaylandServer/datadevice_interface.h>
#include <KWaylandServer/datasource_interface.h>
#include <KWaylandServer/datadevice_interface.h>
#include <KWaylandServer/seat_interface.h>
#include <KWaylandServer/surface_interface.h>
......@@ -91,6 +91,11 @@ bool WlToXDrag::end()
return false;
KWaylandServer::DataSourceInterface *WlToXDrag::dataSourceIface() const
Xvisit::Xvisit(WlToXDrag *drag, AbstractClient *target)
: QObject(drag),
......@@ -274,13 +279,18 @@ void Xvisit::enter()
void Xvisit::sendEnter()
auto drag = m_drag->dataSourceIface();
if (!drag) {
xcb_client_message_data_t data = {};
data.data32[0] = DataBridge::self()->dnd()->window();
data.data32[1] = m_version << 24;
// TODO: replace this with the mime type getter from m_dataOffer,
// then we can get rid of m_drag.
const auto mimeTypesNames = m_drag->dataSourceIface()->mimeTypes();
const auto mimeTypesNames = drag->mimeTypes();
const int mimesCount = mimeTypesNames.size();
size_t cnt = 0;
size_t totalCnt = 0;
......@@ -56,12 +56,10 @@ public:
bool end() override;
KWaylandServer::DataSourceInterface *dataSourceIface() const {
return m_dsi;
KWaylandServer::DataSourceInterface *dataSourceIface() const;
KWaylandServer::DataSourceInterface *m_dsi;
QPointer<KWaylandServer::DataSourceInterface> m_dsi;
Xvisit *m_visit = nullptr;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment