Do not cancel old clipboard selection if it is same as the new one.
ClosedPublic

Authored by fvogt on Jun 14 2018, 12:43 PM.

Details

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.

Diff Detail

Repository
R127 KWayland
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 10
Build 10: arc lint + arc unit
fvogt created this revision.Jun 14 2018, 12:43 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJun 14 2018, 12:43 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
fvogt requested review of this revision.Jun 14 2018, 12:43 PM

I would appreciate a unit test for the issue.

fvogt added a comment.EditedJun 14 2018, 5:25 PM

Yes, a unit test makes sense. I tried to add

// replace the data source with itself, ensure that it did not get cancelled
selectionOfferedSpy.clear();
dataSource2->offer(QStringLiteral("text/plain"));
dataDevice->setSelection(1, dataSource2.data());
QVERIFY(selectionOfferedSpy.wait());
QVERIFY(sourceCancelled2Spy.isEmpty());

in TestDataDevice::testReplaceSource() and it fails without this patch.
With this patch however, the selection isn't offered (is that correct behaviour?) so the wait() times out.
Is there a better way to test this?

in TestDataDevice::testReplaceSource() and it fails without this patch.
With this patch however, the selection isn't offered (is that correct behaviour?) so the wait() times out.
Is there a better way to test this?

I did some research and yes, it's the correct behavior in my opinion: selectionOffered is emitted on receiving a selection event. According to Wayland documentation:

The selection event is sent out to notify the client of a new wl_data_offer for the selection for this device.

Since there is no new selection the old wl_data_source and wl_data_offer do still exist (selection->cancel() just below your insertion was never called) and a new selection event won't get sent.

fvogt updated this revision to Diff 36286.Jun 18 2018, 6:38 PM
  • Add unittest.
romangg accepted this revision.Jun 21 2018, 2:41 PM
This revision is now accepted and ready to land.Jun 21 2018, 2:41 PM
This revision was automatically updated to reflect the committed changes.