Skip to content

(WIP/PoC) Add wayland clipboard support#1583

Closed
trimental wants to merge 5 commits intoalacritty:masterfrom
trimental:wayland-clipboard
Closed

(WIP/PoC) Add wayland clipboard support#1583
trimental wants to merge 5 commits intoalacritty:masterfrom
trimental:wayland-clipboard

Conversation

@trimental
Copy link
Copy Markdown
Contributor

This PR is a work in progress / proof of concept for wayland clipboard integration into alacritty.

The way this PR accesses the wayland clipboard can be seen as kind of a hack (its not explicitly bad but comes with compromises and probably isn't the intended way to access the clipboard), the reason the 'proper' way isn't used is because it would require winit to either expose internal wayland objects that would cause winit breakage and instability or winit would have to provide a clipboard api interface (I'm not too sure what winit's stance on this is).

Currently wayland is used for the clipboard backend if .set_wayland(wayland_display: *mut c_void) is called on the Clipboard object, I'll probably try to make a better way of setting wayland such as using a building pattern or something and split up linux.rs into a linux directory in src like winit and glutin does.

The way the wayland clipboard functions at the moment is that it spawns a new thread that takes the wayland_display and uses it to create various needed wayland objects, the thread then loops every 50ms (this can be any value and is the balance between clipboard access time and cpu usage) and checks every loop for wayland events and/or requests from the main thread to do things like store or load data.

The code quality is pretty bad at the moment because its still a WIP but the code should show the necessary changes required for wayland clipboard support.

@trimental trimental changed the title (WIP/Poc) Add wayland clipboard support (WIP/PoC) Add wayland clipboard support Sep 23, 2018
@trimental trimental force-pushed the wayland-clipboard branch 2 times, most recently from 303f80d to 9dfc0d0 Compare September 23, 2018 09:40
@trimental
Copy link
Copy Markdown
Contributor Author

@francesca64 Is a clipboard interface API within the scope of winit or should this be the proper way to access the clipboard when using the wayland backend? It does require the creation of a whole separate event queue that must dispatched regularly along with the creation of a lot of wayland objects.

@august64
Copy link
Copy Markdown
Contributor

Clipboard support is in scope for winit, as discussed here: rust-windowing/winit#162

There's no API design decided on, but I'm not too particular about it.

@cetex
Copy link
Copy Markdown

cetex commented Nov 16, 2018

I'm running this and Wayland clipboard integration seems to work well for me with these patches. (whereas the standard xclip-implementation doesn't work at all when copying from a native wayland application to native wayland alacritty)

Thanks!

@trimental
Copy link
Copy Markdown
Contributor Author

According to comments on rust-windowing/winit#695 it seems that clipboard API may be considered out of scope for winit (at least at the present moment)

If rust-windowing/winit#695 gets accepted without clipboard API in its scope then this PR could probably be considered an actual PR instead of a PoC

@ojab
Copy link
Copy Markdown

ojab commented Jan 4, 2019

I've tried the branch and found two issues:

  1. Triple-click to select the whole line selects a single word that is selected by double-click.
  2. Selection is not copied to the PRIMARY selection (i. e. in sway I can paste selection using Ctrl+v, but not using middle mouse button).

@trimental
Copy link
Copy Markdown
Contributor Author

@ojab I cannot replicate the first issue and assume that it would be to do with sway instead of this branch. The second issue I could replicate however I don't believe wayland has the concept of a second clipboard and perhaps sway supports two clipboards purely because of XWayland, @vberger is my understanding correct?

@ojab
Copy link
Copy Markdown

ojab commented Jan 4, 2019

There is a wayland protocol for primary selection, see https://github.com/wayland-project/wayland-protocols/tree/master/unstable/primary-selection.

@elinorbgr
Copy link
Copy Markdown
Contributor

Yes, this protocol is the way forward for primary selection. However, not that sway does not support it yet (see swaywm/wlroots#1367 ).

@chrisduerr
Copy link
Copy Markdown
Member

I've proposed it upstream to make the decision clear that clipboard handling is out of scope for winit. Hopefully this should make it possible to move forward with alternative solutions.

See rust-windowing/winit#162.

@trimental I'd be interested in potentially dropping copypasta completely. I believe it was originally created because the clipboard library from servo (clipboard) was using the GPL library. However it has since been changed to MIT/Apache. Do you think it would be possible to add this code to clipboard, or are you making use of anything that doesn't fit with the library's architecture?

Alternatively it would be possible to make copypasta a thin wrapper around the clipboard library which just adds Wayland support. However I think it would be great if there was one library for doing everything clipboard related in Rust.

It also seems like this is using the smithay-client-toolkit, I haven't actually looked too much at the code, but it doesn't seem to depend on winit. Does this mean that this would also work on alternative window toolkits? That might be a requirement for servo to include it. However afaik servo also makes use of winit, so it might be fine even if it's required (though that would obviously make it less ideal as a Rust ecosystem standard for clipboard handling).

@chrisduerr
Copy link
Copy Markdown
Member

A decision has been made on IRC that @trimental is going to try and offer this functionality as a separate crate. Hopefully we'll be able to include this into the clipboard library and then make use of that for Alacritty.

@chrisduerr chrisduerr closed this Feb 9, 2019
@trimental trimental deleted the wayland-clipboard branch February 9, 2019 11:36
@ojab
Copy link
Copy Markdown

ojab commented Feb 20, 2019

Meanwhile support of primary-selection-unstable-v1 was added to sway: swaywm/sway#3735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants