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
This commit is contained in:
Michal Srb 2018-06-14 14:21:41 +02:00 committed by Fabian Vogt
parent b8381f3718
commit d3f15a5388
2 changed files with 9 additions and 0 deletions

View file

@ -512,6 +512,12 @@ void TestDataDevice::testReplaceSource()
QCOMPARE(selectionOfferedSpy.count(), 2); QCOMPARE(selectionOfferedSpy.count(), 2);
QVERIFY(sourceCancelled2Spy.isEmpty()); 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 // create a new DataDevice and replace previous one
QScopedPointer<DataDevice> dataDevice2(m_dataDeviceManager->getDataDevice(m_seat)); QScopedPointer<DataDevice> dataDevice2(m_dataDeviceManager->getDataDevice(m_seat));
QVERIFY(dataDevice2->isValid()); QVERIFY(dataDevice2->isValid());

View file

@ -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"); wl_resource_post_error(dataSource->resource(), WL_DATA_SOURCE_ERROR_INVALID_SOURCE, "Data source is for drag and drop");
return; return;
} }
if (selection == dataSource) {
return;
}
Q_Q(DataDeviceInterface); Q_Q(DataDeviceInterface);
QObject::disconnect(selectionUnboundConnection); QObject::disconnect(selectionUnboundConnection);
QObject::disconnect(selectionDestroyedConnection); QObject::disconnect(selectionDestroyedConnection);