1Password / arboard

A clipboard for Rust
Apache License 2.0
602 stars 63 forks source link

`set_text` not copying to X11 clipboard #143

Open yoyobara opened 3 months ago

yoyobara commented 3 months ago

running the following:

use arboard::Clipboard;

fn main() {
    let mut clipboard = Clipboard::new().unwrap();

    let the_string = "Hello, world!";
    clipboard.set_text(the_string).unwrap();
    println!("But now the clipboard text should be: \"{}\"", the_string);
}

nothing new seems to be copied to the clipboard. the previous thing in the clipboard is still there.

output of cargo run:

    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/exers`
But now the clipboard text should be: "Hello, world!"

my neofetch:

OS: Arch Linux x86_64 
Host: Inspiron 14 5420 
Kernel: 6.8.2-arch2-1 
Uptime: 16 hours, 11 mins 
Packages: 1131 (pacman) 
Shell: bash 5.2.26 
Resolution: 2240x1400 
DE: Plasma 6.0.3 
WM: KWin 
Theme: Breeze-Dark [GTK2], Breeze [GTK3] 
Icons: breeze-dark [GTK2/3] 
Terminal: tmux 
CPU: 12th Gen Intel i7-1255U (12) @ 4.700GHz 
GPU: Intel Alder Lake-UP3 GT2 [Iris Xe Graphics] 
GPU: NVIDIA GeForce MX570 
Memory: 4411MiB / 15682MiB 
yoyobara commented 3 months ago

however, waiting a second before program exists fixes the problem (https://github.com/sigoden/aichat/issues/160)

yoyobara commented 3 months ago

I just figured out that the case is a little different in linux, since the process is responsible for providing the clipboard until something new is copied. so I managed to get it to work by spawning a thread that does just that.

but something doesn't add up; why waiting a second before exiting in the original problem worked??

ktwrd commented 2 months ago

Same thing happens even if you call something else after calling set_text, wait 1s, then exit.

Currently trying to show a notification directly after calling set_text, waiting 1s, then exiting, but I still encounter the same issue.

Note: I am calling the set_text function inside of an async block while using tokio for async support.

Edit

Made an issue that shows an example of it not working #154