Bug 502666

Summary: Clipboard not cleared
Product: [Plasma] kwin Reporter: ssmid <ssmid>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED INTENTIONAL    
Severity: normal CC: xaver.hugl
Priority: NOR    
Version First Reported In: 6.3.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description ssmid 2025-04-11 09:51:14 UTC
SUMMARY
kwin does not clear the clipboard when requested through wl_data_device::set_selection(null, serial)

STEPS TO REPRODUCE
Bash instructions for quick reproduction (< 30 seconds):
---
mkdir clip_repro
cd clip_repro
wget https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz
tar xf zig-linux-x86_64-0.14.0.tar.xz
mv zig-linux-x86_64-0.14.0 zig-0.14
git clone https://codeberg.org/ssmid/zeppelin.git
cd zeppelin
git checkout 475a48a9c7
../zig-0.14/zig build run
---

1. Download zig
2. Run zeppelin: https://codeberg.org/ssmid/zeppelin/src/commit/f2005aac414bd322f89c2faf37c9fea6133a62c9
3. Type some text
4. Press Ctrl+C
5. Paste into some text editor like Kate
6. Focus zeppelin
7. Press Ctrl+Z (US layout) to clear the clipboard
8. Paste into Kate
9. (Search zeppelin logs for set_selection)

OBSERVED RESULT
The text still is pasted into Kate even though set_selection has been called with null.
Zeppelin logs say:
--> wl_data_device:10.set_selection(source: 0, serial: 2043102)
The protocol says: "To unset the selection, set the source to NULL."
https://wayland.app/protocols/wayland#wl_data_device:request:set_selection

EXPECTED RESULT
No text is pasted into Kate.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 6.3.4
KDE Frameworks Version: 6.12.0
Qt Version: 6.8.3
Comment 1 Zamundaaa 2025-04-11 11:33:56 UTC
Plasma comes with a built in clipboard manager, which intentionally prevents this.
Comment 2 ssmid 2025-04-11 12:41:42 UTC
Calling EmptyClipboard() on wine works, probably because it sets the clipboard to an empty string.

Why force wayland clients to find workarounds instead of conforming to spec? Letting a user of my library call a function "clearClipboard()" and it just doesn't work is not really an option, so naturally I will use the same workaround.
Comment 3 Zamundaaa 2025-04-11 13:21:45 UTC
This does conform to the spec. Clipboard managers are a thing, whether you like it or not.

> Calling EmptyClipboard() on wine works, probably because it sets the clipboard to an empty string.
That's a bug then, one that should be fixed.