[xwl] Fix clipboard clearing after externally changed

1c2f23d31c 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
This commit is contained in:
David Edmundson 2020-06-11 23:33:28 +01:00
parent e9c68f36bd
commit 83f5362925
2 changed files with 15 additions and 6 deletions

View file

@ -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();

View file

@ -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)