Bug 511989 - Can't use Clipboard portal with RemoteDesktop portal
Summary: Can't use Clipboard portal with RemoteDesktop portal
Status: RESOLVED FIXED
Alias: None
Product: xdg-desktop-portal-kde
Classification: Plasma
Component: general (other bugs)
Version First Reported In: 6.4.4
Platform: Other Linux
: HI normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-11-12 10:24 UTC by adaha
Modified: 2025-11-14 20:47 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.5.3
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description adaha 2025-11-12 10:24:20 UTC
SUMMARY
I'm trying to use the Clipboard portal together with the RemoteDesktop+Screencast portal. No matter what I do, RemoteDesktop.start will always respond with clipboard_enabled set to 0.

My call to Clipboard.RequestClipboard does not fail or give any errors.

STEPS TO REPRODUCE
1. Create RemoteDesktop session
2. Use RemoteDesktop session with Clipboard.RequestClipboard
3. Start session

OBSERVED RESULT
enable_clipboard is set to 0 in response to RemoteDesktop.start.

EXPECTED RESULT
I expect enable_clipboard toe return 1, or at least see a message/error about why it is not enabled.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 42
KDE Plasma Version: 6.4.4 
KDE Frameworks Version: 6.17.0
Qt Version: 6.9.2
xdg-desktop-portal-kde Version: 6.4.4

ADDITIONAL INFORMATION
I'm trying to get clipboard to work with TigerVNC's w0vncserver. Here is the relevant PR where I'm seeing this issue for anyone interested [1]. I don't see any issues on GNOME, and I can't see anything logged in the journal on KDE.

Does this have anything to with mega-authorization perhaps? Or am I maybe supposed to use ext-data-control-v1 for this?

[1] https://github.com/TigerVNC/tigervnc/pull/2012
   * Relevant changes in RemoteDesktop.cxx and Clipboard.cxx
Comment 1 Harald Sitter 2025-11-13 05:55:17 UTC
To clarify: enable_clipboard is false but the clipboard does work, right?
Comment 2 adaha 2025-11-13 07:00:46 UTC
Sorry, I forgot to add that clipboard does not work and calling for example Clipboard.SetSelection will result in an error:
> GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Clipboard not enabled
Comment 3 Bug Janitor Service 2025-11-13 08:19:03 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/472
Comment 4 adaha 2025-11-13 10:17:36 UTC
I applied the patch in https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/472.

Now, enable_clipboard returns true as expected, and I don't get any AccessDenied errors when calling SetSelection. Thanks for the quick fix :)

I am now able to successfully read from the clipboard. 

Writing to the clipboard does not seem to work, not sure if it might be something incorrect with my implementation. After calling SetSelection, I never get the SelectionTransfer signal. Will have to do some further digging here.
Comment 5 Harald Sitter 2025-11-13 10:33:11 UTC
Git commit 48ee6022aa4f34c88ad940d95235b679f355a921 by Harald Sitter.
Committed on 13/11/2025 at 08:18.
Pushed by sitter into branch 'master'.

remotedesktop: correctly set clipboard_enabled

unclear if this will fix the bug but it definitely isn't correct to just
always return false

M  +1    -1    src/remotedesktop.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/48ee6022aa4f34c88ad940d95235b679f355a921
Comment 6 Bug Janitor Service 2025-11-13 10:33:43 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/473
Comment 7 Harald Sitter 2025-11-13 10:47:51 UTC
Git commit b7f2107d0eb35d2b4cfccf9ffaa91437b88eff0a by Harald Sitter.
Committed on 13/11/2025 at 10:33.
Pushed by sitter into branch 'Plasma/6.5'.

remotedesktop: correctly set clipboard_enabled

unclear if this will fix the bug but it definitely isn't correct to just
always return false


(cherry picked from commit 48ee6022aa4f34c88ad940d95235b679f355a921)

Co-authored-by: Harald Sitter <sitter@kde.org>

M  +1    -1    src/remotedesktop.cpp

https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/b7f2107d0eb35d2b4cfccf9ffaa91437b88eff0a
Comment 8 adaha 2025-11-13 16:14:40 UTC
Ok so I've noticed two things after further digging:

1. Whenever I set mime_types in SetSelection, I will only ever get requests for "text/plain" in SelectionTransfer. This limits writing to the clipboard to only ASCII characters. Reading from the clipboard on the other hand seems to work as expected, I have no issues reading utf-8 strings with "text/plain;charset=utf-8".

2. In my SelectionWrite reponse-handler, whatever I am writing into the FD will get repeated (seemingly arbitrarily) many times. I thought this might have something to do with missing a null-terminator, but including one does not really fix the issue.

So for example, here is some sample code of trying to write "ab" to the clipboard:
> int written;
> int remaining;
> const char* data;
> 
> char s[] = { 97, 98, '\0' };
> remaining = 3;
> data = s;
> 
> while (remaining > 0) {
>   written = write(fd, data, remaining);
> 
>   if (written < 0) {
>     vlog.error("Error writing to fd: %s", strerror(errno));
>     selectionWriteDone(serial, false);
>     g_object_unref(fdList);
>     close(fd);
>     return;
>   }
> 
>   remaining -= written;
>   data += written;
> }
> 
> if (close(fd) != 0) {
>   vlog.error("Failed to close fd: %s", strerror(errno));
>   selectionWriteDone(serial, false);
> } else {
>   selectionWriteDone(serial, true);
> }
If I include the null-terminator (remaining = 3) and try to paste into Konsole, I get a Confirm Paste warning with between ~3k and 100k characters of repeated "ab", and a warning about pasting hidden control characters U+0000. Pasting with the null character will simply paste "ab" to the terminal.

If I don't include the null-terminator (remaining = 2), I still get the Confirm Paste warning with ~3-100k characters.

Note that the number of characters printed (~3-100k) will differ between each paste, and not between every time I write to the clipboard.

Maybe this bug should be closed, and a new one opened for this issue? Or would you prefer to keep it here?
Comment 9 adaha 2025-11-14 12:50:40 UTC
> Maybe this bug should be closed, and a new one opened for this issue? Or
> would you prefer to keep it here?

I've created two new bugs: bug 512075, bug 512076.