alacritty/copypasta

`set_contents` not working on Ubuntu 22.04?

AustinScola opened this issue ยท 9 comments

Hi,

I have a machine running Ubuntu 22.04 and set_contents does not seem to be working? It doesn't return an error and it seems to set the clipboard to an empty string. I have however found that if I call get_contents right afterwards it does work properly?

Does the application keep running or are you terminating? On Linux the application delivers the clipboard content when the paste request is made, so if you quit before then there will be nothing to answer that request.

You might also want to look into clipboard managers, which act as an intermediate.

The application keeps running, but the clipboard context does go out of scope right after I call set_contents. Does that matter?

Yeah, the clipboard needs to stay alive. Should be pretty simple to test though.

Is this documented anywhere in copypasta that the clipboard context must remain in scope in order to guarantee that the contents will actually be set?

That's just how clipboards work and have always worked on Linux. It shouldn't come as a surprise?

Well I do find it surprising because I didn't know that.

And what you are saying is that the example in the README might not actually set the contents of the clipboard b/c the context goes out of scope right afterwards??

extern crate copypasta;

use copypasta::{ClipboardContext, ClipboardProvider};

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

I've opened #50 to make our examples more consistent. That should make it less likely for people to get confused.

Okay, I still think there should be an explanation of why calling get_contents after set_contents is necessary because as an API that is not intuitive.

It's not necessary. The only thing that is necessary is that the clipboard context needs to still be alive when it is retrieved. Which should be intuitive for Linux users imo.