Bug 395366 - Copying from GTK applications in Wayland does not work
Summary: Copying from GTK applications in Wayland does not work
Alias: None
Product: frameworks-kwayland
Classification: Frameworks and Libraries
Component: server (show other bugs)
Version: 5.45.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Martin Flöser
URL: https://phabricator.kde.org/D13535
Depends on:
Reported: 2018-06-14 12:32 UTC by Michal Srb
Modified: 2018-06-21 14:42 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:

Do not cancel old clipboard selection if it is same as the new one. (1.24 KB, patch)
2018-06-14 12:32 UTC, Michal Srb
WAYLAND_DEBUG=1 log, CTRL+C in kate vs gedit (3.73 KB, text/plain)
2018-06-14 12:36 UTC, Michal Srb

Note You need to log in before you can comment on or make changes to this bug.
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.

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