copypasta: Setting clipboard on Fedora 33 / GNOME / Wayland does not work

I have this simple code from example:

use copypasta::{ClipboardContext, ClipboardProvider};

fn main() {
    let mut ctx = ClipboardContext::new().unwrap();
    println!("{:?}", ctx.get_contents());
    ctx.set_contents("some string".to_owned()).unwrap();
}

Running it twice shows:

❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/foo`
Ok("master")

foo on  master [?] is 📦 v0.1.0 via 🦀 v1.43.1 
❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/foo`
Ok("")

foo on  master [?] is 📦 v0.1.0 via 🦀 v1.43.1 

so it seems it sets buffer to empty instead of some string. I am not sure how to debug this, so let me know and I will happily provide as much details as needed.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (15 by maintainers)

Most upvoted comments

@ignatenkobrain it’s a bug that it works IIRC, it shouldn’t work, unless GNOME added a magic protocol. The keyboard focus is a requirement in protocol, wl-clipboard is using hack with invisible window IIRC on GNOME.

This is the https://github.com/alacritty/copypasta/blob/ae35fada33a348e4edb141390f6c30b5c1d68d86/src/wayland_clipboard.rs#L37 which creates a wayland clipboard, but it’ll still require a window for you. But on GNOME you have clipboard manager by default for at least all Wayland clients.

I definitely would never recommend anyone to use this approach. It’s completely backwards from how this should be solved and creates an absolute mess.

If you want your clipboard to be managed, just install a clipboard manager. If such a clipboard manager is present, copypasta will work just fine even after the application is closed. That’s the entire goal of clipboard managers after all and that’s the solution to the problem.

However this issue is obviously about the incorrect usage of our library due to improper API documentation.

@chrisduerr oh, that’s unfortunate. I was thinking about porting ffsend to this crate. and its purpose is to copy link to the clipboard and close itself.