From 83f5362925102d2f8502a45c5c6de7a0e837182f Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 11 Jun 2020 23:33:28 +0100 Subject: [PATCH] [xwl] Fix clipboard clearing after externally changed 1c2f23d31c5cc266ff7b1a244b38258a81ef41d6 swapped round things so we manage a dataSource rather than a dataDevice which may or may not have a source. In introduced a bug on clear. We only want to clear the wayland's clipboard if xwayland owns the current clipboard. Otherwise we reset the clipboard if some other client sets the selection. There's also no need to wait for this to go through from our internal client to the server representation - we can just clear immediately --- xwl/clipboard.cpp | 16 ++++++++++------ xwl/clipboard.h | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xwl/clipboard.cpp b/xwl/clipboard.cpp index 4a51ff3397..46b357ca4c 100644 --- a/xwl/clipboard.cpp +++ b/xwl/clipboard.cpp @@ -73,15 +73,11 @@ Clipboard::Clipboard(xcb_atom_t atom, QObject *parent) 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::AbstractDataSource *dsi) { - if (dsi && dsi->client() != DataBridge::self()->dataDeviceIface()->client()->client()) { + if (dsi && !ownsSelection(dsi)) { // Wayland native client provides new selection if (!m_checkConnection) { m_checkConnection = connect(workspace(), &Workspace::clientActivated, @@ -96,6 +92,11 @@ void Clipboard::wlSelectionChanged(KWaylandServer::AbstractDataSource *dsi) checkWlSource(); } +bool Clipboard::ownsSelection(KWaylandServer::AbstractDataSource *dsi) const +{ + return dsi->client() == DataBridge::self()->dataDeviceIface()->client()->client(); +} + void Clipboard::checkWlSource() { auto dsi = waylandServer()->seat()->selection(); @@ -185,7 +186,10 @@ void Clipboard::x11OffersChanged(const QStringList &added, const QStringList &re } } } else { - DataBridge::self()->dataDevice()->setSelection(0); + KWaylandServer::AbstractDataSource *currentSelection = waylandServer()->seat()->selection(); + if (currentSelection && !ownsSelection(currentSelection)) { + waylandServer()->seat()->setSelection(nullptr); + } } waylandServer()->internalClientConection()->flush(); diff --git a/xwl/clipboard.h b/xwl/clipboard.h index 2cd16881b0..c3f63fb722 100644 --- a/xwl/clipboard.h +++ b/xwl/clipboard.h @@ -56,6 +56,11 @@ private: */ void checkWlSource(); + /** + * Returns of dsi is managed by our data bridge + */ + bool ownsSelection(KWaylandServer::AbstractDataSource *dsi) const; + QMetaObject::Connection m_checkConnection; Q_DISABLE_COPY(Clipboard)