[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.
This commit is contained in:
parent
4bab721db8
commit
2d68196536
2 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
{
|
||||
return m_dsi.data();
|
||||
}
|
||||
|
||||
Xvisit::Xvisit(WlToXDrag *drag, AbstractClient *target)
|
||||
: QObject(drag),
|
||||
m_drag(drag),
|
||||
|
@ -274,13 +279,18 @@ void Xvisit::enter()
|
|||
|
||||
void Xvisit::sendEnter()
|
||||
{
|
||||
auto drag = m_drag->dataSourceIface();
|
||||
if (!drag) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
KWaylandServer::DataSourceInterface *m_dsi;
|
||||
QPointer<KWaylandServer::DataSourceInterface> m_dsi;
|
||||
Xvisit *m_visit = nullptr;
|
||||
|
||||
Q_DISABLE_COPY(WlToXDrag)
|
||||
|
|
Loading…
Reference in a new issue