From d3f15a5388da3660678617d12a5082273a563d49 Mon Sep 17 00:00:00 2001 From: Michal Srb Date: Thu, 14 Jun 2018 14:21:41 +0200 Subject: [PATCH] Do not cancel old clipboard selection if it is same as the new one. Summary: GTK applications seem to call wl_data_device::set_selection multiple times with the same wl_data_source object, replacing it with itself. If we cancel it, they will destroy it and the selection will be gone. With this patch it is again possible to copy from GTK applications. BUG: 395366 Test Plan: Patch provided by the reporter, he reported success. Reviewers: #plasma, #frameworks, romangg Reviewed By: #plasma, romangg Subscribers: michalsrb, romangg, graesslin, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D13535 --- src/wayland/autotests/client/test_datadevice.cpp | 6 ++++++ src/wayland/datadevice_interface.cpp | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/wayland/autotests/client/test_datadevice.cpp b/src/wayland/autotests/client/test_datadevice.cpp index eca1cdb9d6..14379f8da1 100644 --- a/src/wayland/autotests/client/test_datadevice.cpp +++ b/src/wayland/autotests/client/test_datadevice.cpp @@ -512,6 +512,12 @@ void TestDataDevice::testReplaceSource() QCOMPARE(selectionOfferedSpy.count(), 2); QVERIFY(sourceCancelled2Spy.isEmpty()); + // replace the data source with itself, ensure that it did not get cancelled + dataDevice->setSelection(1, dataSource2.data()); + QVERIFY(!sourceCancelled2Spy.wait(500)); + QCOMPARE(selectionOfferedSpy.count(), 2); + QVERIFY(sourceCancelled2Spy.isEmpty()); + // create a new DataDevice and replace previous one QScopedPointer dataDevice2(m_dataDeviceManager->getDataDevice(m_seat)); QVERIFY(dataDevice2->isValid()); diff --git a/src/wayland/datadevice_interface.cpp b/src/wayland/datadevice_interface.cpp index add7ac59ac..5408adda68 100644 --- a/src/wayland/datadevice_interface.cpp +++ b/src/wayland/datadevice_interface.cpp @@ -130,6 +130,9 @@ void DataDeviceInterface::Private::setSelection(DataSourceInterface *dataSource) wl_resource_post_error(dataSource->resource(), WL_DATA_SOURCE_ERROR_INVALID_SOURCE, "Data source is for drag and drop"); return; } + if (selection == dataSource) { + return; + } Q_Q(DataDeviceInterface); QObject::disconnect(selectionUnboundConnection); QObject::disconnect(selectionDestroyedConnection);