File 0001-Do-not-cancel-old-clipboard-selection-if-it-is-same-.patch of Package kwayland

From 0e580ae9bdc5bef0c845d58e7c647bfac05364aa Mon Sep 17 00:00:00 2001
From: Michal Srb <michalsrb@gmail.com>
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
---
 autotests/client/test_datadevice.cpp | 6 ++++++
 src/server/datadevice_interface.cpp  | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/autotests/client/test_datadevice.cpp b/autotests/client/test_datadevice.cpp
index eca1cdb..14379f8 100644
--- a/autotests/client/test_datadevice.cpp
+++ b/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<DataDevice> dataDevice2(m_dataDeviceManager->getDataDevice(m_seat));
     QVERIFY(dataDevice2->isValid());
diff --git a/src/server/datadevice_interface.cpp b/src/server/datadevice_interface.cpp
index add7ac5..5408add 100644
--- a/src/server/datadevice_interface.cpp
+++ b/src/server/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);
-- 
2.17.1

openSUSE Build Service is sponsored by