Skip to content

Wayland backend: add host-to-client clipboard sync #1797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nseguin42
Copy link

@nseguin42 nseguin42 commented Apr 5, 2025

This PR adds the other half (host-to-client direction) of clipboard support for the Wayland backend (the client-to-host direction being added in e17aec4). In other words, it allows the gamescope client to paste from the host's clipboard.

--

The implementation is based on Emersion's blogpost from 2020: "Wayland clipboard and drag & drop" . In the post, Emersion writes (emphasis mine):

Note that we’re performing blocking write calls in data_source_handle_send. This could potentially stall the Wayland event loop if we had more data to write (overflowing the kernel buffer). A real client would perform non-blocking writes instead.

I'm not sure how to go about making this change, so I'd appreciate some input here.

--

Only the clipboard is supported (not the primary selection). Since the client-to-host direction supports the primary selection (c.f. ef1e8db), we should probably add this too.

--

Only the "text/plain" MIME type is requested. Should we request different MIME types?

@nseguin42 nseguin42 marked this pull request as draft April 5, 2025 22:45
@MithicSpirit
Copy link

Thanks for doing this, I've been meaning to do it eventually, but never got around to it.

To prevent stalling too much on reads, I just prevented it from reading more than once, and print out a message when it doesn't fit (see line 2516).

I think it would be good for this to support all the same MIME types that the source supports (see lines 1228–1232 and 1240–1244; we should probably refactor these together so we don't triplicate the list of MIME types). However, more importantly, I think it should check the offered MIME types before getting the data. Currently, if I copy an image to the clipboard and try to paste it into gamescope, it just prints out some garbage, while I think it should either empty the internal clipboard or leave it unmodified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants