alacritty/copypasta

Clipboard not working on wayland

CristianKerr opened this issue · 5 comments

I have added copypasta to my project and tried to use the example to insert something into the clipboard, but its not working.
No error given, it just doesn't happen.
I am on latest Fedora with wayland, but it seems its picking x11 clipboard for some reason.
I even tried to explicitely tell the wayland feature in toml, but it didn't help.

copypasta = { version = "0.10.0", features = ["wayland"] }

Any ideas?

let mut ctx = ClipboardContext::new().unwrap();
ctx.set_contents(code.to_owned()).unwrap();

Edit:
I have tried the complete code and added also this part:

let content = ctx.get_contents().unwrap();
println!("Clipboard content: {}", content);

And now it works. So I have to read the clipboard after changing it - then it works...

You need a window to make it work. The crate explicitly states that. The goal is to support window based stuff. On GNOME you don't really have options to access clipboard content. If you use something else, look into wlr-data-control.

I have a window. I am creating an app in iced. And As I said above, it does work, but only if I try to read the value from the clipboard after I set it. Which is weird.

post me a full WAYLAND_DEBUG=1 log then where you try to do 'things' and also explain what you did, so I can check whether things match or not.

If you're still stuck with this (and for anyone else coming across this issue, like I did this morning), keep in mind that pub type ClipboardContext = X11ClipboardContext; per the crate docs. This means that you're setting the X11 clipboard when you run the code above. You need to instead call copypasta::wayland_clipboard::create_clipboards_from_external. This is what kchibisov means when he says you need a window.

To be fair, the example docs could be a little clearer in that regard; as we move into a Wayland-by-default world, examples that implicitly assume X11 are going to be more and more problematic.

Hi, thank you for the update. This was probably the issue, somehow I thought that if I add wayland feature it will automatically use wayland. I wil try to use it, thank you. Is there an example somewhere on how to get also the wayland display?