Bug 512075

Summary: Clipboard.SetSelection only works with "text/plain" mime_type
Product: [Plasma] xdg-desktop-portal-kde Reporter: adaha
Component: generalAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: aleixpol, kde
Priority: NOR    
Version First Reported In: 6.5.1   
Target Milestone: ---   
Platform: Other   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=511989
Latest Commit: Version Fixed/Implemented In: 6.20
Sentry Crash Report:

Description adaha 2025-11-14 12:39:55 UTC
SUMMARY
When calling SetSelection, the SelectionTransfer signal will only ever send "text/plain" as the mime_type.


STEPS TO REPRODUCE
1. Call SetSelection with mime_types = [ "text/plain;charset=utf-8", "text/plain" ]
2. Wait for SelectionTransfer signal

OBSERVED RESULT
mime_type will always be "text/plain", limiting usage to ASCII characters only.

EXPECTED RESULT
The protocol is not clear if there is some kind of implied priority with the mime_types, but I would expect utf-8 to be preferred over ASCII.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 43
KDE Plasma Version: 6.5.1
KDE Frameworks Version: 6.19.0
Qt Version: 6.10.0
xdg-desktop-portal-kde-6.5.2-1 (+ patch https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/b7f2107d0eb35d2b4cfccf9ffaa91437b88eff0a)

ADDITIONAL INFORMATION
I have tested calling SetSelection with mime_types set to [ "text/plain;charset=utf-8" ]. But when I do that, the SelectionTransfer signal is never transmitted.
Comment 1 David Redondo 2025-11-14 13:45:53 UTC
Doesn't this depend on the side wanting to read the data? We dont have code special casing mimetypes in the portal for what it's worth, it's either lower in the stack or the process reading the clipboard.
Comment 2 adaha 2025-11-14 13:54:35 UTC
I would assume (In reply to David Redondo from comment #1)
> Doesn't this depend on the side wanting to read the data? 

Yeah that is what I would assume.

Maybe I'm just misunderstanding the protocol and have implemented things incorrectly, but this is how things happen with my current setup:

1. I call SetSelection and set mime_types to ["text/plain;charset=utf-8", "text/plain"].
2. Directly after calling SetSelection, the SelectionTransfer signal is emitted, where the mime_type is always "text/plain".

Is the transfer supposed to be instant? My guess would be that, just as you say, an application makes a request for an available mime type, which then should trigger a transfer.
Comment 3 David Redondo 2025-11-14 14:15:07 UTC
the clipboard manager will instantly request the data.
Comment 4 adaha 2025-11-14 14:46:15 UTC
Alright got it, thanks for clarifying.

Are you able to get a SelectionTransfer signal with mime_type set to "text/plain;charset=utf-8" in SetSelection? It just won't work in my testing :/
Comment 5 David Redondo 2025-11-14 15:04:57 UTC
I can reproduce, it should be fixed already by https://invent.kde.org/frameworks/kguiaddons/-/commit/20b032c87b8d15228d99d162818e51c216054010
Comment 6 adaha 2025-11-14 15:07:12 UTC
Oh, I did not notice that it had already been fixed. I will patch and test again, thanks!
Comment 7 adaha 2025-11-17 07:19:35 UTC
Ok so I just tested with xdg-desktop-portal-kde-d64493551ba28dd0b73dfdddd51d3efa41caa4da

The issue still remains for me:
1. Call SetSelection with mime_types = [ "text/plain;charset=utf-8" ]
2. I never get a SelectionTransfer signal

1. Call SetSelection with mime_types = [ "text/plain;charset=utf-8", "text/plain" ]
2. SelectionTransfer is always called with mime_types = "text/plain".

Do you have a setup where SelectionTransfer works with utf-8?
Comment 8 David Redondo 2025-11-19 08:09:44 UTC
Hi, the fix was only released on friday with frameworks 6.20. I just tested and with that I get SelectionTransfer with utf8. I am gonna close it as fixed.
Comment 9 adaha 2025-11-19 08:49:11 UTC
Just ran an update, work fine now. Thanks!