-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Illustrate how to monitor the primary selection. (#15)
Inspired by https://github.com/farseerfc/ydcv-rs/blob/master/src/main.rs#L143 Fixes #14
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..."); | ||
} | ||
} | ||
} | ||
} |