Bug 395366

Summary: Copying from GTK applications in Wayland does not work
Product: [Frameworks and Libraries] frameworks-kwayland Reporter: Michal Srb <michalsrb>
Component: serverAssignee: Martin Flöser <mgraesslin>
Status: RESOLVED FIXED    
Severity: normal CC: bugseforuns, fabian, nate
Priority: NOR    
Version: 5.45.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
URL: https://phabricator.kde.org/D13535
Latest Commit: Version Fixed In:
Attachments: Do not cancel old clipboard selection if it is same as the new one.
WAYLAND_DEBUG=1 log, CTRL+C in kate vs gedit

Description Michal Srb 2018-06-14 12:32:38 UTC
Created attachment 113311 [details]
Do not cancel old clipboard selection if it is same as the new one.

In Plasma Wayland session if I start kate and gedit, I can copy-paste from kate into kate and from kate into gedit, but not from gedit into anywhere else. Pressing CTRL+C in gedit seems to empty the clipboard and CTRL+V then pastes nothing.

When testing, make sure to run both kate and gedit in Wayland mode, not in X mode under Xwayland. It can be ensured for example by starting them like this:

> unset DISPLAY
> QT_QPA_PLATFORM=wayland kate &
> GDK_BACKEND=wayland gedit &


If I try the same thing in Gnome Wayland or in Weston, copy and paste works between kate and gedit in all directions.

If I run gedit in X mode, copy paste works normally between it and kate in Wayland mode.

I have checked the output of kwin using WAYLAND_DEBUG=1 and the issue is that gedit calls `wl_data_device::set_selection` multiple times with the same `wl_data_source`. In kwayland it gets into `DataDeviceInterface::Private::setSelection` which sees that there is existing selection, so it cancels it before accepting the new one. But since the new is the same as the old one, it cancels them "both".

I made patch that prevents the cancellation if the new selection is the same as the old one. Copying works again with that patch.
Comment 1 Michal Srb 2018-06-14 12:36:19 UTC
Created attachment 113312 [details]
WAYLAND_DEBUG=1 log, CTRL+C in kate vs gedit
Comment 2 Fabian Vogt 2018-06-14 12:43:48 UTC
I imported the patch to phab: https://phabricator.kde.org/D13535
Comment 3 Fabian Vogt 2018-06-21 14:42:49 UTC
Git commit 0e580ae9bdc5bef0c845d58e7c647bfac05364aa by Fabian Vogt, on behalf of Michal Srb.
Committed on 21/06/2018 at 14:42.
Pushed by fvogt into branch 'master'.

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.

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

M  +6    -0    autotests/client/test_datadevice.cpp
M  +3    -0    src/server/datadevice_interface.cpp

https://commits.kde.org/kwayland/0e580ae9bdc5bef0c845d58e7c647bfac05364aa