Bug 422426

Summary: Implement Wayland Primary Selection Protocol bridge with XWayland
Product: [Plasma] kwin Reporter: Méven Car <meven.car>
Component: platform-wayland-nestedAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: a.samirh78, alex765, anssi.hannula, bart, bernie, bugseforuns, bugtracker+kde, butirsky, CoelacanthusHex, creideiki+kdebugs, cruzki123, dennis.lissov, dkxls23, ethan.reesor, flying-sheep, geisserml, goeran, greg.martyn, hsantanna, inglessi, j5lx, jansen, jappleii, kai.kasurinen, kde, kde, kevin.kofler, kiril, kleagg, lee295012, lilydjwg, lubimov.maxim+kde, ludo.aelbrecht+kde, luizluca, m.weghorn, matej, nate, postix, rdieter, robert.mader, s1994928, subdiff, theivorytower
Priority: NOR Keywords: wayland
Version: 5.21.2   
Target Milestone: ---   
Platform: Other   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=436246
Latest Commit: Version Fixed In: 5.23

Description Méven Car 2020-06-03 15:44:46 UTC
SUMMARY

We now have support for the Wayland Primary Selection Protocol.
Except it needs Application i.e toolkit support.
Qt has it.
Gtk should have it https://bugzilla.gnome.org/show_bug.cgi?id=762560.

We need a bridge for XWayland applications.

KWin and KWayland-server patches for reference:

https://invent.kde.org/plasma/kwayland-server/-/merge_requests/15/diffs?commit_id=c82b0db029f35e0c853f7170cf03c81d09cd25c7
https://invent.kde.org/plasma/kwin/-/merge_requests/27/diffs?commit_id=d0d1ad8c858fae31f8f9ab26aa516c6e0416ea27
Comment 1 David Edmundson 2020-06-08 09:50:17 UTC
Just to clarify on the GTK situation.

GTK does not implement zwp_primary_selection they implement a forerunner gtk_primary_selection. Basically identical but with a different name.

GTK devs have said they would be willing to use the newer one within the GTK3 lifespan. At which point there's no point us implementing that.

We still need our bridge though :)
Comment 2 Bernie Innocenti 2020-08-16 05:06:52 UTC
Perhaps this is the cause of this bug I'm seeing in Wayland sessions.

How to reproduce:
1. select any text in a Qt app such as konsole or kate
2. middle-click in a GTK app such as Chrome or Tilix

Expected result: pastes the text selected at (1)
Actual result: pastes the last selection made in any GTK app
Comment 3 Bernie Innocenti 2020-08-16 05:08:27 UTC
Is there any hack / workaround we could put in place if GTK takes their time to add zwp_primary_selection?

This is quite a showstopper for moving to Wayland, at least for me.
Comment 4 John Apple II 2020-08-17 00:12:11 UTC
(In reply to bernie from comment #3)
> Is there any hack / workaround we could put in place if GTK takes their time
> to add zwp_primary_selection?
> 
> This is quite a showstopper for moving to Wayland, at least for me.

Same here - I use this feature so much in my day-to-day work that I cannot switch to Wayland from X, yet.
Comment 5 Roman Gilg 2020-08-17 09:07:08 UTC
What's the problem now?

a) Xwayland bridge does not exist.
b) GTK Wayland clients do not support zwp_primary_selection.

Or both?

Solution for (a) is adding the bridge, solution for (b) is to talk to someone from Gnome/GTK team to implement it.
Comment 6 Kevin Kofler 2020-08-17 10:07:45 UTC
How hard would it be to implement the legacy GTK version of the protocol in addition to the standardized version? I assume they only differ by naming, don't they? So it should not be too hard to support the legacy version, or is it?
Comment 7 David Edmundson 2020-08-19 21:03:27 UTC
Both.

Bridge as you say is simple just missing but I have a pending rewrite of the brige to get rid of the internal connection, so I want to finish that first. Then it should be just a few lines.

I had spoken to someone from the GTK team about implementing it. 
Paraphrasing the response it was "we should eventually, patches welcome"

>So it should not be too hard to support the legacy version, or is it?

Not hard, but it'd take about as much effort as just patching GTK ourselves, so it's where I'd rather see time spent.
Comment 8 Denis Lisov 2020-10-16 16:15:56 UTC
Update on the GTK situation: according to GNOME/gtk#2591 (https://gitlab.gnome.org/GNOME/gtk/-/issues/2591), support for the standard protocol has landed and will be shipped in 3.24.23 and 3.99.2/4.0.
Comment 9 Bernie Innocenti 2020-11-15 15:53:13 UTC
I have GTK 3.24.23 and all of KDE built from git (synced yesterday), but primary-selection still isn't working between chromium and konsole.

Is there a way to inspect the wayland protocol?
Comment 10 Bernie Innocenti 2020-11-15 16:18:12 UTC
Ok, the patch adding zwp_primary_selection didn't land on the gtk-3-24 branch in time for the 3.24.23 release:

 https://gitlab.gnome.org/GNOME/gtk/-/issues/2591#note_961946
Comment 11 Bernie Innocenti 2020-11-20 13:59:33 UTC
GTK devs say on https://chat.gnome.org/channel/gtk that there aren't any more gtk3 releases planned until after gtk 4.0 is out. Instead of waiting, they recommend requesting a distro patch.

So I went ahead and filed one for Arch Linux:
https://bugs.archlinux.org/task/68667
Comment 12 Bernie Innocenti 2021-03-14 12:56:13 UTC
gtk3-3.24.27 includes support for primary-selection-unstable-v1 (*), and yet middle-click paste between gtk and qt apps still doesn't work with plasma 5.21.2.

How could I help debug this issue?

(*) https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/2627
Comment 13 Bernie Innocenti 2021-03-14 13:06:17 UTC
Perhaps it doesn't work because this followup change is missing on the gtk-3-24 branch:
  https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/2630
Comment 14 Bernie Innocenti 2021-03-25 11:17:28 UTC
Vlad seems to have found the root cause in GTK:
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/2630#note_1065234
Comment 15 Bernie Innocenti 2021-03-25 17:55:47 UTC
Now there's a GTK bug:
https://gitlab.gnome.org/GNOME/gtk/-/issues/3791

This comment has some more detail:
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/2630#note_1065144
Comment 16 Robert Mader 2021-03-27 15:18:53 UTC
Can anyone test https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3357 and confirm that it fixes the issue on kwin?
Comment 18 Ahmad Samir 2021-03-30 14:21:07 UTC
(I haven't tested yet, but thanks for the fixes and for the heads up, both are much appreciated o/ ).
Comment 19 Nate Graham 2021-03-30 17:09:11 UTC
Since all three of those are merged, does this mean that full primary selection functionality with GTK apps is now achieved?
Comment 20 Robert Mader 2021-03-30 17:23:14 UTC
(In reply to Nate Graham from comment #19)
> Since all three of those are merged, does this mean that full primary
> selection functionality with GTK apps is now achieved?

If I understood Vlad correctly, then yes :)
Would be good if somebody could confirm this - and also test Firefox if possible.
Comment 21 Nate Graham 2021-03-30 18:09:10 UTC
Awesome, let's mark as fixed and re-open if anyone finds it still broken. Great work Robert and Vlad! Robert, do you know what GTK version your merge requests will be released with?
Comment 22 Robert Mader 2021-03-30 18:16:35 UTC
(In reply to Nate Graham from comment #21)
> Awesome, let's mark as fixed and re-open if anyone finds it still broken.
> Great work Robert and Vlad! Robert, do you know what GTK version your merge
> requests will be released with?

That would be 4.2.x/4.3 and 3.24.29 :)

However, that's actually not what this bug is about IIUC - Xwayland still needs a helping hand from kwin.
Comment 23 Nate Graham 2021-03-30 18:18:02 UTC
(In reply to Robert Mader from comment #22)
> That would be 4.2.x/4.3 and 3.24.29 :)
> 
> However, that's actually not what this bug is about IIUC - Xwayland still
> needs a helping hand from kwin.
What do you mean exactly? "that" == what?
Comment 24 Robert Mader 2021-03-30 19:05:02 UTC
(In reply to Nate Graham from comment #23)
> What do you mean exactly? "that" == what?

The bug title is "Implement Wayland Primary Selection Protocol bridge with XWayland", which actually has little to do with "make primary selection work in the GTK Wayland backend" apart from both being about primary selection.

Primary selection will still not work between QT-Wayland and e.g. Chromium or Pidgin. In order to fix that kwin will need to translate between primary selection of Wayland and X11 - that's not yet done, so the bug should get reopened.

I/we just high jacked this bug and talked about the protocol not working between QT-Wayland and GTK-Wayland because it (this bug) was linked in the GTK issue :)
Comment 25 Nate Graham 2021-03-30 19:50:30 UTC
Oh okay, sorry.
Comment 26 Henrique Sant'Anna 2021-05-12 16:51:25 UTC
Seems related to Bug 436246.
Comment 27 Patrick Silva 2021-08-08 12:29:20 UTC
*** Bug 440706 has been marked as a duplicate of this bug. ***
Comment 28 Bernie Innocenti 2021-08-08 21:36:18 UTC
This is more of a regression than a wish: in X11, users were able to copy-paste across all apps. Once they switch to a Wayland session, Qt5 and GTK3 apps switch to Wayland native, while several other popular apps use XWayland's legacy protocol.

Copy-pasting not working between the two groups breaks very basic workflows. For me, it's usually copying text between Chrome and Konsole. This is why I'm reluctant to migrate to Wayland until this is fixed (or until all the apps I use daily have switched to Wayland).
Comment 29 Bug Janitor Service 2021-08-18 12:21:08 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/1272
Comment 30 David Redondo 2021-08-19 06:46:42 UTC
Git commit 6104dc50cfa4cfa6467029dfdad17c9848dc225c by David Redondo.
Committed on 19/08/2021 at 06:46.
Pushed by davidre into branch 'master'.

xwl: Sync primary selection

Syncs the primary selection from wayland to X and from X to wayland.
Instead of doing it through the internal connection like the clipboard,
this sets/reacts to changes in SeatInterface::prrimarySelection directly.
FIXED-IN:5.23

M  +1    -0    src/atoms.cpp
M  +1    -0    src/atoms.h
M  +1    -0    src/xwl/CMakeLists.txt
M  +3    -1    src/xwl/databridge.cpp
M  +2    -0    src/xwl/databridge.h
A  +209  -0    src/xwl/primary.cpp     [License: GPL(v2.0+)]
A  +69   -0    src/xwl/primary.h     [License: GPL(v2.0+)]
M  +1    -1    src/xwl/selection_source.h

https://invent.kde.org/plasma/kwin/commit/6104dc50cfa4cfa6467029dfdad17c9848dc225c
Comment 31 geisserml 2021-08-28 19:27:34 UTC
Please make the middle-click paste feature optional, at least for Wayland (Bug 441668).
Comment 32 Bernie Innocenti 2021-09-01 04:19:47 UTC
Thank you for taking the time to implement this, David.
Will this ship with 5.23?
Comment 33 Bernie Innocenti 2021-09-01 04:27:46 UTC
(In reply to Bernie Innocenti from comment #32)
> Thank you for taking the time to implement this, David.
> Will this ship with 5.23?

Just noticed the tag in the commit msg: FIXED-IN:5.23
Comment 34 Ethan Reesor 2021-10-18 04:55:54 UTC
I would also like middle-click paste to be optional. I use middle click regularly, but the fact that it now pastes is unpleasantly unexpected.