Skip to content
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

Add clipboard support #906

Merged
merged 7 commits into from
Aug 23, 2023
Merged

Conversation

ForTheReallys
Copy link

Tested with gamescope gvim. This PR adds support for copying/pasting utf-8 text for both the clipboard and the primary selection. In the event that SDL_CLIPBOARDUPDATE doesn't get triggered (for example, when running gamescope as XWayland under sway), I've implemented the keybinding Super + C to sync both the clipboard and primary selection with gamescope. As of now, this PR only supports Xwayland application windows under gamescope. I don't have much experience with Xlib, so any feedback is appreciated.

Closes #303

README.md Outdated Show resolved Hide resolved
@emersion
Copy link
Collaborator

emersion commented Jul 6, 2023

In the event that SDL_CLIPBOARDUPDATE doesn't get triggered (for example, when running gamescope as XWayland under sway), I've implemented the keybinding Super + C to sync both the clipboard and primary selection with gamescope.

That sounds like a bug somewhere. Sway should update the X11 clipboard when an X11 window is focused.

@ForTheReallys
Copy link
Author

ForTheReallys commented Jul 6, 2023

@emersion Just found out it's a bug in SDL. Looks SDL doesn't send CLIPBOARDUPDATE if the videodriver is x11. I can move set_gamescope_selections() under SDL_WINDOWEVENT_FOCUSED_GAINED if that makes more sense. Thoughts?

@misyltoad
Copy link
Collaborator

We can just fix it in SDL maybe?

@ForTheReallys
Copy link
Author

Works for me. I'll look into that. In the meantime, is there anything stopping us from merging this PR?

Fixes the following error:
error: control reaches end of non-void function [-Werror=return-type]
@ForTheReallys
Copy link
Author

SDL PR: libsdl-org/SDL#7951

@ForTheReallys
Copy link
Author

The fix has been merged into SDL2. Let me know if there's anything else you need from me

@ForTheReallys
Copy link
Author

@emersion @Joshua-Ashton Bump

@misyltoad
Copy link
Collaborator

On Holiday until Wednesday

@ForTheReallys
Copy link
Author

Any updates on this @Joshua-Ashton?

@emersion
Copy link
Collaborator

With the SDL bug fixed, do we really need the keyboard shortcut to synchronize?

@ForTheReallys
Copy link
Author

With the SDL bug fixed, do we really need the keyboard shortcut to synchronize?

Really your call. I don't mind either way. I'm not super familiar with distro release schedules, but the only reason I can think of to keep it around is if this change gets picked up by distros before the SDL fix. Again, your call. Let me know and I'll do what I need to do

This change properly syncs the primary selection and clipboard across
all xwayland instances, even in embedded mode
@ForTheReallys
Copy link
Author

ForTheReallys commented Jul 30, 2023

@emersion I went ahead and removed the keybind now that SDL has been fixed to properly report clipboard updates. I also added support for clipboard synchronization across xwayland instances, including in embedded mode. I was going to wait until this PR got merged before introducing the change, but it was a pretty simple so I just included it in this PR. That commit should also fix #916.

src/steamcompmgr.cpp Outdated Show resolved Hide resolved
When a client becomes the selection owner, and sets the selection, an
XFixes event is raised, and gamescope responds by retrieving the contents
of the selection, and re-setting ourWindow as the owner of the selection.
We don't need to call XChangeProperty when syncing across Xwayland
instances, as that gets called when a client makes a SelectionRequest.
@ForTheReallys
Copy link
Author

Bump @Joshua-Ashton

@ForTheReallys
Copy link
Author

Bump @Joshua-Ashton

@misyltoad
Copy link
Collaborator

Thought I merged this already, oops!

@misyltoad misyltoad merged commit a64a5a8 into ValveSoftware:master Aug 23, 2023
1 check passed
@ForTheReallys
Copy link
Author

No worries. Thank you!

@ForTheReallys ForTheReallys deleted the clipboard branch August 24, 2023 01:31
@isnikulin
Copy link

This PR has been merged, however, I don't see this functionality neither in readme of current codebase, nor in help message of a built-from source executable.

Has this been reverted for some reason? If not, what are the steps to enable basic clipboard functionality?

@ForTheReallys @Joshua-Ashton

@ForTheReallys
Copy link
Author

@Preposterone the easiest way to get this working is to set SDL_VIDEODRIVER=wayland (assuming you're on Wayland). For it to work with X11 or XWayland, you'll need to have SDL 2.30.0.

@MisterrrX
Copy link

@Preposterone the easiest way to get this working is to set SDL_VIDEODRIVER=wayland (assuming you're on Wayland). For it to work with X11 or XWayland, you'll need to have SDL 2.30.0.

Unfortunately, this doesn't work for me on Arch and Hyprland. Has anyone got this to work?

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.

Possible to copy paste into gamescope windows?
5 participants