diff --git a/xwl/clipboard.h b/xwl/clipboard.h --- a/xwl/clipboard.h +++ b/xwl/clipboard.h @@ -24,7 +24,7 @@ namespace KWaylandServer { -class DataDeviceInterface; +class AbstractDataSource; } namespace KWin @@ -49,7 +49,7 @@ /** * React to Wl selection change. */ - void wlSelectionChanged(KWaylandServer::DataDeviceInterface *ddi); + void wlSelectionChanged(KWaylandServer::AbstractDataSource *dsi); /** * Check the current state of the selection and if a source needs * to be created or destroyed. diff --git a/xwl/clipboard.cpp b/xwl/clipboard.cpp --- a/xwl/clipboard.cpp +++ b/xwl/clipboard.cpp @@ -69,11 +69,19 @@ connect(waylandServer()->seat(), &KWaylandServer::SeatInterface::selectionChanged, this, &Clipboard::wlSelectionChanged); + + connect(DataBridge::self()->dataDeviceIface(), &KWaylandServer::DataDeviceInterface::selectionChanged, this, [](KWaylandServer::DataSourceInterface *selection) { + waylandServer()->seat()->setSelection(selection); + }); + + connect(DataBridge::self()->dataDeviceIface(), &KWaylandServer::DataDeviceInterface::selectionCleared, this, []() { + waylandServer()->seat()->setSelection(nullptr); + }); } -void Clipboard::wlSelectionChanged(KWaylandServer::DataDeviceInterface *ddi) +void Clipboard::wlSelectionChanged(KWaylandServer::AbstractDataSource *dsi) { - if (ddi && ddi != DataBridge::self()->dataDeviceIface()) { + if (dsi && dsi->client() != DataBridge::self()->dataDeviceIface()->client()) { // Wayland native client provides new selection if (!m_checkConnection) { m_checkConnection = connect(workspace(), &Workspace::clientActivated, @@ -90,7 +98,7 @@ void Clipboard::checkWlSource() { - auto ddi = waylandServer()->seat()->selection(); + auto dsi = waylandServer()->seat()->selection(); auto removeSource = [this] { if (wlSource()) { setWlSource(nullptr); @@ -107,7 +115,7 @@ // Otherwise the Wayland source gets destroyed to shield // against snooping X clients. - if (!ddi || DataBridge::self()->dataDeviceIface() == ddi) { + if (!dsi || (DataBridge::self()->dataDeviceIface()->client() == dsi->client())) { // Xwayland source or no source disconnect(m_checkConnection); m_checkConnection = QMetaObject::Connection(); @@ -124,14 +132,11 @@ // source already exists, nothing more to do return; } - auto *wls = new WlSource(this, ddi); + auto *wls = new WlSource(this); setWlSource(wls); - auto *dsi = ddi->selection(); if (dsi) { wls->setDataSourceIface(dsi); } - connect(ddi, &KWaylandServer::DataDeviceInterface::selectionChanged, - wls, &WlSource::setDataSourceIface); ownSelection(true); } @@ -174,14 +179,13 @@ // also offers directly the currently available types source->setDataSource(dataSource); DataBridge::self()->dataDevice()->setSelection(0, dataSource); - waylandServer()->seat()->setSelection(DataBridge::self()->dataDeviceIface()); } else if (auto *dataSource = source->dataSource()) { for (const QString &mime : added) { dataSource->offer(mime); } } } else { - waylandServer()->seat()->setSelection(nullptr); + DataBridge::self()->dataDevice()->setSelection(0); } waylandServer()->internalClientConection()->flush(); diff --git a/xwl/dnd.cpp b/xwl/dnd.cpp --- a/xwl/dnd.cpp +++ b/xwl/dnd.cpp @@ -35,6 +35,7 @@ #include #include +#include #include @@ -200,7 +201,7 @@ // New Wl to X drag, init drag and Wl source. m_currentDrag = new WlToXDrag(); - auto source = new WlSource(this, ddi); + auto source = new WlSource(this); source->setDataSourceIface(ddi->dragSource()); setWlSource(source); ownSelection(true); diff --git a/xwl/selection_source.h b/xwl/selection_source.h --- a/xwl/selection_source.h +++ b/xwl/selection_source.h @@ -41,6 +41,7 @@ { class DataDeviceInterface; class DataSourceInterface; +class AbstractDataSource; } namespace KWin @@ -93,8 +94,8 @@ Q_OBJECT public: - WlSource(Selection *selection, KWaylandServer::DataDeviceInterface *ddi); - void setDataSourceIface(KWaylandServer::DataSourceInterface *dsi); + WlSource(Selection *selection); + void setDataSourceIface(KWaylandServer::AbstractDataSource *dsi); bool handleSelectionRequest(xcb_selection_request_event_t *event); void sendTargets(xcb_selection_request_event_t *event); @@ -109,8 +110,7 @@ private: bool checkStartTransfer(xcb_selection_request_event_t *event); - KWaylandServer::DataDeviceInterface *m_ddi = nullptr; - KWaylandServer::DataSourceInterface *m_dsi = nullptr; + KWaylandServer::AbstractDataSource *m_dsi = nullptr; QVector m_offers; QMetaObject::Connection m_offerConnection; diff --git a/xwl/selection_source.cpp b/xwl/selection_source.cpp --- a/xwl/selection_source.cpp +++ b/xwl/selection_source.cpp @@ -49,14 +49,12 @@ { } -WlSource::WlSource(Selection *selection, KWaylandServer::DataDeviceInterface *ddi) +WlSource::WlSource(Selection *selection) : SelectionSource(selection) - , m_ddi(ddi) { - Q_ASSERT(ddi); } -void WlSource::setDataSourceIface(KWaylandServer::DataSourceInterface *dsi) +void WlSource::setDataSourceIface(KWaylandServer::AbstractDataSource *dsi) { if (m_dsi == dsi) { return; @@ -135,7 +133,7 @@ bool WlSource::checkStartTransfer(xcb_selection_request_event_t *event) { // check interfaces available - if (!m_ddi || !m_dsi) { + if (!m_dsi) { return false; }