-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
current status of ClipboardContext::set_contents on linux #28
Comments
That the clipboard provided by this crate doesn't outlast the process is due to several considerations:
I havn't personally tested this crate with a clipboard manager, but have received reports via IRC that it does work with them (possibly together with a call to sleep for a few hundred milliseconds if the client would otherwise exit immediately after setting the contents). I'll try to document this better. |
Cool. Thanks! |
I'll add that this behavior recently really tripped me up. I'm writing a CLI app so it immediately exits after "setting" the clipboard. It's highly unintuitive to have it all work this way on linux. Some documentation here would be good. |
I agree. I invoke |
Ditto. This is exactly the same as my current solution. use std::io::Write;
use std::process::{Command, Stdio};
pub fn write(s: &str) -> Option<()> {
#[cfg(target_os = "macos")]
let mut command = Command::new("pbcopy");
#[cfg(target_os = "linux")]
let mut command = {
// See https://linux.die.net/man/1/xclip.
let mut c = Command::new("xclip");
c.arg("-in");
c.arg("-selection");
c.arg("clipboard");
c
};
let mut child = command.stdin(Stdio::piped()).spawn().ok()?;
// When stdin is dropped the fd is automatically closed. See
// https://doc.rust-lang.org/std/process/struct.ChildStdin.html.
{
let stdin = child.stdin.as_mut()?;
stdin.write_all(s.as_bytes()).ok()?;
}
// Wait on pbcopy/xclip to finish.
child.wait().ok()?;
Some(())
} |
Assuming this is a For example, these will keep clipboard contents after exit: use clipboard_ext::prelude::*;
// Fork and keep contents
clipboard_ext::x11_fork::ClipboardContext::new().unwrap()
.set_contents("some string".into()).unwrap();
// Invoke xclip/xsel and keep contents
clipboard_ext::x11_bin::ClipboardContext::new().unwrap()
.set_contents("some string".into()).unwrap(); See the README for more information. |
I got around this issue by delaying the function end which allows me time enough to paste the resulting cliboard using:
|
What do you think about solution made clip c++ library? |
Is it possible to make the set_content effect outlive the process now? Thanks!
The text was updated successfully, but these errors were encountered: