Bug 449909

Summary: Copied text from XWayland applications is lost after terminating the application
Product: [Plasma] plasmashell Reporter: tgnff242
Component: Clipboard widget & pop-upAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: asturm, bugseforuns, fsundvik, kde, nate
Priority: NOR Keywords: wayland
Version: 5.24.0   
Target Milestone: 1.0   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 6.0
Sentry Crash Report:

Description tgnff242 2022-02-10 03:37:28 UTC
STEPS TO REPRODUCE
1. Open an XWayland application.
2. Copy some text from it.
3. Paste it in kate.
4. Close the XWayland application from which you copied the text at step (1).
5. Try to paste it in kate, again.

OBSERVED RESULT
At step (3) the copied text is pasted, as expected. At step (5) nothing is pasted.

EXPECTED RESULT
Both steps (3) and (5) should have pasted the same text copied at step (1).

SOFTWARE/OS VERSIONS
KDE Plasma Version: 5.24.0
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2 + KDE patches

ADDITIONAL INFORMATION

This is definitely not a regression.
Comment 1 Nate Graham 2022-02-11 23:27:46 UTC
Can you provide an example of an XWayland app where this happens? I cannot reproduce the issue with Discord or Element.
Comment 2 tgnff242 2022-02-12 05:25:35 UTC
You can reproduce it using Firefox. Make sure that it is indeed using XWayland by checking the "Window Protocol" field in "about:support".
Comment 3 David Edmundson 2022-02-12 08:45:21 UTC
Can you confirm what klipper shows?
Comment 4 tgnff242 2022-02-12 18:42:20 UTC
Klipper keeps the copied text after exiting the XWayland application. If you click on its entry in klipper, you can indeed paste the text again.
Comment 5 ytf85869 2022-05-24 19:47:09 UTC
Alternate formulation of this bug: If an XWayland application is closed instead of just losing focus, its clipboard contents are lost and not synced to Klipper.
Comment 6 Patrick Silva 2022-10-29 13:59:14 UTC
Can reproduce with Firefox on Wayland session of Gnome too.

https://gitlab.gnome.org/GNOME/mutter/-/issues/1532

Recent comments say it's a Firefox issue.
Comment 7 Nate Graham 2022-10-31 18:07:12 UTC
Can anyone find or file a bug report for Firefox? And tell them GNOME people too.
Comment 8 tgnff242 2022-10-31 18:37:26 UTC
This affects other applications as well.
Comment 9 Nate Graham 2022-10-31 18:38:04 UTC
Which ones?
Comment 10 tgnff242 2022-10-31 18:42:03 UTC
All of them. Every application that isn't Wayland-native.
Comment 11 Nate Graham 2022-10-31 18:45:40 UTC
I can't reproduce that.
Comment 12 tgnff242 2022-10-31 18:53:02 UTC
Perhaps klipper's settings are important? I don't have enabled the "Keep the selection and clipboard the same" and "Save history across desktop sessions", and both "Text selection" and "Non-text selection " are set to "Only when explicitly copied". 20 Entries and no actions.
Comment 13 Nate Graham 2022-11-02 17:04:58 UTC
Hmm, now I can reproduce this issue 100% with Discord, no matter what Klipper settings I use.
Comment 14 Fred Sundvik 2023-07-07 08:00:54 UTC
This is 100% repeatable for me with and copying from any XWayland application and trying to paste after closing it. I haven't changed any clipboard settings on the system.

And what's worse, is that there's a bug in `wl-clipboard` that causes `wl-paste` to hang when this happens https://github.com/bugaevc/wl-clipboard/issues/185, which in turn causes Neovim to hang, since it uses `wl-paste` under the hood.

I'm using:
KDE Plasma 5.27.6 on Arch Linux
Comment 15 Bug Janitor Service 2023-08-14 16:07:30 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/4326
Comment 16 Vlad Zahorodnii 2023-08-21 08:05:47 UTC
Git commit f7fb9476b37b648298e6d329ff0aad4f5ca550c1 by Vlad Zahorodnii, on behalf of David Edmundson.
Committed on 21/08/2023 at 09:58.
Pushed by vladz into branch 'master'.

xwl: Handle X11 clipboard owners closing more thoroughly

Selection acts as an abstraction around multiple X11Sources, when we get
a new source we asyncronously emit that x11OffersChanged when it
completes.

If the selection is lost, we were just deleting the source, without
notifying other parts.

XwlDataSource is the datasource that SeatInterface knows about. We need
to delete this when the X11 connection is no longer valid. SeatInterface
will update the selection when the XwmlDataSource is deleted if it's the
active selection.

The hook is introduced as updating the selection in Clipboard will cause
Selection to delete m_xSource which gets messy.

M  +5    -0    src/xwayland/clipboard.cpp
M  +1    -0    src/xwayland/clipboard.h
M  +4    -0    src/xwayland/dnd.cpp
M  +1    -0    src/xwayland/dnd.h
M  +5    -0    src/xwayland/primary.cpp
M  +1    -0    src/xwayland/primary.h
M  +4    -2    src/xwayland/selection.cpp
M  +1    -0    src/xwayland/selection.h

https://invent.kde.org/plasma/kwin/-/commit/f7fb9476b37b648298e6d329ff0aad4f5ca550c1