-
Notifications
You must be signed in to change notification settings - Fork 77
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
Clipboard is cleared when the process exits on Linux #61
Comments
This is a known tradeoff/design decision around a limitation of x11. This was documented in a comment back when rust-clipboard/src/x11_clipboard.rs Lines 263 to 279 in 9a13971
|
I realize this might be out of scope, but is there a way of detecting when the contents of the clipboard have been accessed, from rust-clipboard? I want to write a tool to receive input from stdin and copy that to the clipboard. I'd be fine with the process hanging until the contents had been pasted out (in fact, that could be ideal), but I'm not sure how i'd know when that had occurred. I guess this might require something like a variation on |
Thank you for addressing this in detail. As someone who is learning Rust, would you be able to give brief details on the problems involved with using fork? |
This is a real pity as it renders the library essentially useless for my purposes. |
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 did a bit of digging to see how much work it would be to enable the paste detection functionality that I mention in #61 (comment), and it appears pretty nontrivial, since this package uses various lower-level libraries for the actual clipboard bits. |
@brownjohnf I've done exactly this in You'd have to use the |
Following up here with my own match fork() {
Ok(ForkResult::Child) => {
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
ctx.set_contents(password.value.to_owned()).unwrap();
std::thread::sleep(std::time::Duration::from_secs(10));
// optionally clear the clipboard here
}
Err(_) => return Err("clipboard fork failed".into()),
_ => {}
} This only works on platforms that have a Edit: This also shouldn't be done in library code. It's safe-ish in the context I intend to use it in, but not necessarily others. |
This is related to an issue with the clipboard handling in xorg, see aweinstock314/rust-clipboard#61 This now forks a child process and sleeps for 10 seconds, after which it clears the clipboard before exiting. Closes #5
This is related to an issue with the clipboard handling in xorg, see aweinstock314/rust-clipboard#61 This now forks a child process and sleeps for 10 seconds, after which it clears the clipboard before exiting. Closes #5
This is related to an issue with the clipboard handling in xorg, see aweinstock314/rust-clipboard#61 This now forks a child process and sleeps for 10 seconds, after which it clears the clipboard before exiting. Closes #5
This is related to an issue with the clipboard handling in xorg, see aweinstock314/rust-clipboard#61 This now forks a child process and sleeps for 10 seconds, after which it clears the clipboard before exiting. Closes #5
This is related to an issue with the clipboard handling in xorg, see aweinstock314/rust-clipboard#61 This now forks a child process and sleeps for 10 seconds, after which it clears the clipboard before exiting. Closes #5
This is related to an issue with the clipboard handling in xorg, see aweinstock314/rust-clipboard#61 This now forks a child process and sleeps for 10 seconds, after which it clears the clipboard before exiting. Closes #5
Please consider the following code:
The text was updated successfully, but these errors were encountered: