arboard icon indicating copy to clipboard operation
arboard copied to clipboard

set_text is not working properly

Open alkarkhi opened this issue 3 years ago • 3 comments

When I use the set_text method, the text isn't set to the clipboard. But when I add a little delay before the program exists it works. Here is the code

let clipboard = Clipboard::new();

match clipboard {
    Ok(mut clipboard) => {
        let text = clipboard.set_text("hello world 2".to_string());
        match text {
            Ok(_) => {
                println!("OK");
                //std::thread::sleep(std::time::Duration::from_millis(10));
            }
            Err(_) => {
                println!("Error");
            }
        }
    },
    Err(_) => {

    }
}

When I uncomment the std::thread::sleep(std::time::Duration::from_millis(10)); it works. But I guess this isn't the intended behaviour

alkarkhi avatar Apr 07 '22 11:04 alkarkhi

Hi there @DodyAlkarkhi. What operating system and desktop environment are you seeing this behavior on?

complexspaces avatar Apr 07 '22 13:04 complexspaces

Hi there @DodyAlkarkhi. What operating system and desktop environment are you seeing this behavior on?

Hi.

OS is Debian sid and desktop environment is KDE Plasma

alkarkhi avatar Apr 07 '22 13:04 alkarkhi

It sounds like you may be running into the same problem that #39 with how the dropping Clipboard interacts with the X11 window server.

If you move the mut clipboard binding outside of the match i.e using .unwrap() for example, then the text should be available outside of that first Ok block.

complexspaces avatar Apr 07 '22 20:04 complexspaces

Hey there again. I'm going to go ahead and close this one now that 3.0 is out with the wait function. If you need to access clipboard contents longer, I would recommend using this function or keeping the Clipboard struct around longer.

complexspaces avatar Sep 19 '22 22:09 complexspaces