Struct x11_clipboard::Clipboard
source · pub struct Clipboard {
pub getter: Context,
pub setter: Arc<Context>,
/* private fields */
}
Expand description
X11 Clipboard
Fields§
§getter: Context
§setter: Arc<Context>
Implementations§
source§impl Clipboard
impl Clipboard
sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Create Clipboard.
Examples found in repository?
examples/paste.rs (line 8)
7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
let clipboard = Clipboard::new().unwrap();
let val =
clipboard.load(
clipboard.setter.atoms.clipboard,
clipboard.setter.atoms.utf8_string,
clipboard.setter.atoms.property,
Duration::from_secs(3)
)
.unwrap();
let val = String::from_utf8(val).unwrap();
print!("{}", val);
}
More examples
examples/wait_copy_event.rs (line 6)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let clipboard = Clipboard::new().unwrap();
loop {
let val = clipboard
.load_wait(
clipboard.setter.atoms.clipboard,
clipboard.setter.atoms.string,
clipboard.setter.atoms.property,
)
.unwrap();
let val = String::from_utf8(val).unwrap();
println!("{}", val);
}
}
examples/monitor_primary_selection.rs (line 7)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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...");
}
}
}
}
sourcepub fn load<T>(
&self,
selection: Atom,
target: Atom,
property: Atom,
timeout: T
) -> Result<Vec<u8>, Error>where
T: Into<Option<Duration>>,
pub fn load<T>( &self, selection: Atom, target: Atom, property: Atom, timeout: T ) -> Result<Vec<u8>, Error>where T: Into<Option<Duration>>,
load value.
Examples found in repository?
examples/paste.rs (lines 10-15)
7 8 9 10 11 12 13 14 15 16 17 18 19 20
fn main() {
let clipboard = Clipboard::new().unwrap();
let val =
clipboard.load(
clipboard.setter.atoms.clipboard,
clipboard.setter.atoms.utf8_string,
clipboard.setter.atoms.property,
Duration::from_secs(3)
)
.unwrap();
let val = String::from_utf8(val).unwrap();
print!("{}", val);
}
sourcepub fn load_wait(
&self,
selection: Atom,
target: Atom,
property: Atom
) -> Result<Vec<u8>, Error>
pub fn load_wait( &self, selection: Atom, target: Atom, property: Atom ) -> Result<Vec<u8>, Error>
wait for a new value and load it
Examples found in repository?
examples/wait_copy_event.rs (lines 10-14)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let clipboard = Clipboard::new().unwrap();
loop {
let val = clipboard
.load_wait(
clipboard.setter.atoms.clipboard,
clipboard.setter.atoms.string,
clipboard.setter.atoms.property,
)
.unwrap();
let val = String::from_utf8(val).unwrap();
println!("{}", val);
}
}
More examples
examples/monitor_primary_selection.rs (lines 13-17)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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...");
}
}
}
}