Skip to content

Commit

Permalink
Illustrate how to monitor the primary selection. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngirard authored and quininer committed Jul 25, 2019
1 parent d142a06 commit 4127796
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/monitor_primary_selection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern crate x11_clipboard;

use x11_clipboard::Clipboard;


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

println!("Waiting for selection...");

loop {
if let Ok(curr) = clipboard.load_wait(
clipboard.getter.atoms.primary,
clipboard.getter.atoms.utf8_string,
clipboard.getter.atoms.property
) {
let curr = String::from_utf8_lossy(&curr);
let curr = curr
.trim_matches('\u{0}')
.trim();
if !curr.is_empty() && last != curr {
last = curr.to_owned();
println!("Contents of primary selection: {}", last);
println!("Waiting for selection...");
}
}
}
}

0 comments on commit 4127796

Please sign in to comment.