Bug 424754 - Plasma fails to paste text copied from apps running on Xwayland (tested Firefox and Chromium) when "Prevent Empty Clipboard" is enabled
Summary: Plasma fails to paste text copied from apps running on Xwayland (tested Firef...
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Clipboard (show other bugs)
Version: master
Platform: Neon Linux
: VHI major
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords: wayland
: 424731 426713 427832 439513 439765 441783 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-07-28 13:52 UTC by Patrick Silva
Modified: 2021-12-23 11:47 UTC (History)
39 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Silva 2020-07-28 13:52:19 UTC
STEPS TO REPRODUCE
1. load this bug report with Firefox or Chromium running on Xwayland
2. select and copy any word written here
3. try to paste it into the "Comment" text box
4. if the copied word is pasted as expected, repeat the steps 2 and 3.
At some point the copied word will not be pasted in the "Comment" text box
as it should. Nothing will be pasted or a previously copied text will
be pasted instead.

EXPECTED RESULT
word copied in the step 2 should always be pasted in the step 3

SOFTWARE/OS VERSIONS
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.19.80
KDE Frameworks Version: 5.73.0
Qt Version: 5.14.2
Comment 1 David Edmundson 2020-08-13 16:31:03 UTC
*** Bug 424731 has been marked as a duplicate of this bug. ***
Comment 2 David Edmundson 2020-08-13 16:31:27 UTC
Is this fixed with p-w as of today? It should be
Comment 3 Leszek Lesner 2020-08-14 02:37:41 UTC
No not fixed yet. I still have empty entries in klipper and still stuff not copied on Ctrl+C in XWayland apps.
Comment 4 Leszek Lesner 2020-08-14 12:45:01 UTC
(In reply to Leszek Lesner from comment #3)
> No not fixed yet. I still have empty entries in klipper and still stuff not
> copied on Ctrl+C in XWayland apps.

Figured out if you disable "Prevent empty keyboard" it seems to work!? Ctrl+C works directly in XWayland apps like Chromium/Firefox and co
Comment 5 Patrick Silva 2020-08-14 15:19:48 UTC
it's still reproducible.

Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.19.80
KDE Frameworks Version: 5.74.0
Qt Version: 5.14.2
Comment 6 Patrick Silva 2020-08-14 15:26:12 UTC
(In reply to Leszek Lesner from comment #4)
> (In reply to Leszek Lesner from comment #3)
> > No not fixed yet. I still have empty entries in klipper and still stuff not
> > copied on Ctrl+C in XWayland apps.
> 
> Figured out if you disable "Prevent empty keyboard" it seems to work!?
> Ctrl+C works directly in XWayland apps like Chromium/Firefox and co

yes, I can't reproduce if "Prevent empty clipboard" is uncheched in clipboard applet settings.
Comment 7 David Edmundson 2020-08-14 15:32:59 UTC
Turns out I hadn't merged my workarounds...so potentially my fix is still fine.

Also upstream protocols approved my idea for a proper fix so I'll work on that soon.
Comment 8 Andrey 2020-08-14 19:19:28 UTC
(In reply to David Edmundson from comment #7)
> Also upstream protocols approved my idea for a proper fix so I'll work on
> that soon.

Was it public discussion? I would love to follow.
Comment 9 David Edmundson 2020-08-14 22:50:21 UTC
https://github.com/swaywm/wlr-protocols/issues/92
Comment 10 Patrick Silva 2020-09-19 23:13:16 UTC
*** Bug 426713 has been marked as a duplicate of this bug. ***
Comment 11 Claudius Ellsel 2020-10-17 13:42:33 UTC
*** Bug 427832 has been marked as a duplicate of this bug. ***
Comment 12 Claudius Ellsel 2020-10-17 13:46:51 UTC
I experience this since the update to Plasma 5.20. The behavior is rather frustrating and might lead to data loss if you think you have copied (or cut out) something, close it and then when trying to paste it nothing is pasted.

Also at least from a user perspective it appears as a regression (although technically it might not be true).

Added the regression keyword and moved importance to HI and major due to the possibility of data loss and the user frustration to be expected.
Comment 13 Bug Janitor Service 2020-10-20 00:30:16 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/365
Comment 14 Nate Graham 2020-10-27 01:10:46 UTC
*** Bug 428075 has been marked as a duplicate of this bug. ***
Comment 15 Aleix Pol 2020-10-29 14:56:43 UTC
Git commit d335070b80c2f3bc5674355e3edba61bc010bc36 by Aleix Pol.
Committed on 29/10/2020 at 14:56.
Pushed by apol into branch 'master'.

xwl: Do not refresh the x11 Clipboard while fetching

At the moment there was a race condition when putting something into the
keyboard from XWayland apps. The clipboard manager would announce a new
thing before we'd submitted it all resulting in a broken state.

This change detects when it's fetching and will only refresh the source
after everything has been sent.
Related: bug 412350

M  +10   -0    xwl/clipboard.cpp
M  +1    -0    xwl/clipboard.h

https://invent.kde.org/plasma/kwin/commit/d335070b80c2f3bc5674355e3edba61bc010bc36
Comment 16 Claudius Ellsel 2020-10-29 15:57:13 UTC
Won't this get backported to 5.20? I personally consider the experience rather frustrating and would be pretty disappointed if I had to wait about three months in this state until it is fixed.
Comment 17 Claudius Ellsel 2020-10-29 15:59:45 UTC
Ignore that, it seems to be planned to backport this, probably just have to wait a short time.
Comment 18 Nate Graham 2020-11-04 19:41:35 UTC
*** Bug 428521 has been marked as a duplicate of this bug. ***
Comment 19 Brian 2020-11-28 02:47:17 UTC
Built from git master, i am still encountering this issue, and infact i think it's worse than before. I am completely unable to copy or paste between a Wayland and XWayland application now. Before this i used to be able to paste sometimes by using the middle mouse button, but even that doesn't work at all now.
Comment 20 Nate Graham 2020-11-28 22:34:42 UTC
Git commit 99b29195b45ecc0de97761f13e7df81dd92b53e7 by Nate Graham, on behalf of Aleix Pol.
Committed on 28/11/2020 at 22:33.
Pushed by ngraham into branch 'Plasma/5.20'.

xwl: Do not refresh the x11 Clipboard while fetching

At the moment there was a race condition when putting something into the
keyboard from XWayland apps. The clipboard manager would announce a new
thing before we'd submitted it all resulting in a broken state.

This change detects when it's fetching and will only refresh the source
after everything has been sent.
Related: bug 412350
(cherry picked from commit d335070b80c2f3bc5674355e3edba61bc010bc36)

M  +10   -0    xwl/clipboard.cpp
M  +1    -0    xwl/clipboard.h

https://invent.kde.org/plasma/kwin/commit/99b29195b45ecc0de97761f13e7df81dd92b53e7
Comment 21 Brian 2020-11-28 23:06:25 UTC
I think there's more to this bug than just the race condition, especially since i still encounter this. I think a partial cause is that window focus issues make it so that the clipboard cannot be accessed.

At line 141 in https://invent.kde.org/plasma/kwin/-/blob/0549c14588e0ccdbd4d78bb710e1c7569b409247/xwl/clipboard.cpp it seems it's checking for XWayland application focus before allowing the use of the clipboard. However, if the window focus is broken, then this would not work obviously, hence why it is still breaking despite this patch?
Comment 22 Nate Graham 2020-11-28 23:09:34 UTC
Would you be interested in hacking on it a bit and submitting a merge request?
Comment 23 Brian 2020-11-28 23:43:22 UTC
(In reply to Nate Graham from comment #22)
> Would you be interested in hacking on it a bit and submitting a merge
> request?

I wish i could, but i have no idea how Kwin works, and it isn't an issue with the clipboard code i shared but rather window handling.
Comment 24 Claudius Ellsel 2020-11-29 15:34:36 UTC
Since you seem to be familiar with compiling with kdesrc-build, what you could try to do is to modify the code at the line you found to be possibly suspicious and add debug output to see how the code behaves for you. That could at least confirm your theory that this has something to do with window focus and https://bugs.kde.org/show_bug.cgi?id=400987.

However that might take time while not delivering helpful information. But it would be something you probably can do.

Further information on how to get console output for example can be found here: https://www.proli.net/2020/04/03/developing-kwin-wayland/.
Comment 25 Patrick Silva 2020-12-21 10:32:55 UTC
I can reproduce this problem with the steps already provided using Firefox
or Opera browsers.

Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.20.80
KDE Frameworks Version: 5.78.0
Qt Version: 5.15.2
Comment 26 Leyenda 2021-01-26 13:01:40 UTC
I can reproduce this problem with the steps already provided using Firefox flatpak version.


Operating System: KDE neon 20.04 Testing Edition
KDE Plasma Version: 5.20.90
KDE Frameworks Version: 5.79.0
Qt Version: 5.15.2
Comment 27 Brian 2021-02-02 23:29:28 UTC
https://bugzilla.mozilla.org/show_bug.cgi?id=1631061

Seems to have been fixed now?
Comment 28 Patrick Silva 2021-02-02 23:43:03 UTC
No. Firefox is not the only affected app.
Comment 29 Nate Graham 2021-03-24 21:50:46 UTC
Patrick, is this still reproducible for you with current Neon unstable?
Comment 30 Patrick Silva 2021-03-24 23:58:31 UTC
Currently this bug is harder to reproduce, but it persists.
Sometimes Clipboard applet shows an empty entry after copying a word,
then pasting fails.

Firefox 86.0.1
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.21.80
KDE Frameworks Version: 5.81.0
Qt Version: 5.15.2
Graphics Platform: Wayland
Comment 31 Bernie Innocenti 2021-03-25 11:17:55 UTC
Perhaps related to this bug: https://bugs.kde.org/show_bug.cgi?id=422426#c14
Comment 32 Bernie Innocenti 2021-03-25 11:20:03 UTC
I can reproduce this in Chrome as well, on Fedora 34 beta.
Comment 33 David Edmundson 2021-04-18 14:32:09 UTC
This early return looks horribly wrong.

```
void Clipboard::wlSelectionChanged(KWaylandServer::AbstractDataSource *dsi)
{
    if (m_waitingForTargets) {
        return;
    }
```

It needs to discard the old async operation, not discard the new one.
Comment 34 Bernie Innocenti 2021-04-24 14:26:02 UTC
gtk 3.24.29 was released today and is already packaged in Arch Linux, so I tested there.

Primary selection now works fine between a Qt app (konsole) and most GTK3 apps (gnome-disks, seahorse, tilix).

However, it still fails between Qt apps and GTK3 apps which are still using X11 (Chrome, Firefox, Thunderbird, Signal Desktop).

I checked, and these binaries are using the new libgtk-3.so:

  % cat /proc/$(pidof -s chrome)/maps | grep -m1 gtk 
  7fab70d09000-7fab70d8c000 r--p 00000000 103:03 17587682                  /usr/lib/libgtk-3.so.0.2404.25
  % cat /proc/$(pidof -s thunderbird-bin)/maps | grep -m1 gtk 
  7f87486d7000-7f874875a000 r--p 00000000 103:03 17587682                  /usr/lib/libgtk-3.so.0.2404.25

Not sure if this is a kwin bug, or the gtk bug is not fully fixed yet.
Comment 35 Bernie Innocenti 2021-04-24 14:31:42 UTC
Ah, this is a known issue:
https://bugs.kde.org/show_bug.cgi?id=422426#c24

"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."

Looks like we could close one of these bugs as duplicate of the other.

And this, imho, should be a Wayland showstopper because it breaks all a very basic workflow (copying text between KDE apps and browsers plus all electron UI apps).
Comment 36 Armin 2021-04-29 06:30:21 UTC
I can still reproduce this bug on my Fedora 34 (KDE spin) system.

SOFTWARE/OS VERSIONS
OS: Fedora 
Kernel: x86_64 Linux 5.11.15-300.fc34.x86_64
DE: KDE 5.80.0 / Plasma 5.21.4
Comment 37 Bernie Innocenti 2021-04-30 04:31:14 UTC
(In reply to Armin from comment #36)
> I can still reproduce this bug on my Fedora 34 (KDE spin) system.
> 
> SOFTWARE/OS VERSIONS
> OS: Fedora 
> Kernel: x86_64 Linux 5.11.15-300.fc34.x86_64
> DE: KDE 5.80.0 / Plasma 5.21.4

This is already being tracked in the RH bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=1954147
Comment 38 Shmerl 2021-07-11 20:12:30 UTC
I have another use case that doesn't involve GTK or XWayland.

1. Open Kate, open Konsole.
2. Copy test from Kate, paste in Konsole - works.
3. Copy another text from Kate and paste in console - nothing is getting pasted. Klipper shows empty text for the current buffer.

Both Konsole and Kate are Wayland windows, no XWayland windows are active during this test.

Plasma: 5.22.3.

Should I open another bug about it or it falls into the same one?
Comment 39 Nate Graham 2021-07-12 01:15:29 UTC
If XWayland is not involved, that sounds like a different bug. :)
Comment 40 Shmerl 2021-07-12 01:16:35 UTC
(In reply to Nate Graham from comment #39)
> If XWayland is not involved, that sounds like a different bug. :)

OK, I'll open another one. But the symptom looks very similar.
Comment 41 Shmerl 2021-07-12 02:36:42 UTC
Opened bug 439765.
Comment 42 Nate Graham 2021-08-03 23:15:02 UTC
Actually I think you're right; they are the same after all. Sorry for sending you on a wild goose chase.
Comment 43 Nate Graham 2021-08-03 23:15:26 UTC
*** Bug 439765 has been marked as a duplicate of this bug. ***
Comment 44 Nate Graham 2021-08-04 15:35:18 UTC
*** Bug 439513 has been marked as a duplicate of this bug. ***
Comment 45 Patrick Silva 2021-09-07 12:24:56 UTC
*** Bug 441783 has been marked as a duplicate of this bug. ***
Comment 46 David Edmundson 2021-09-17 22:55:37 UTC
This has been cleaned up for 5.23. Please create a new bug if there are still issues, with some newer logs.