Struct 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

Source

pub fn new() -> Result<Self, Error>

Create Clipboard.

Examples found in repository?
examples/paste.rs (line 8)
7fn main() {
8    let clipboard = Clipboard::new().unwrap();
9    let val =
10        clipboard.load(
11            clipboard.setter.atoms.clipboard,
12            clipboard.setter.atoms.utf8_string,
13            clipboard.setter.atoms.property,
14            Duration::from_secs(3)
15        )
16        .unwrap();
17    let val = String::from_utf8(val).unwrap();
18
19    print!("{}", val);
20}
More examples
Hide additional examples
examples/wait_copy_event.rs (line 6)
5fn main() {
6    let clipboard = Clipboard::new().unwrap();
7
8    loop {
9        let val = clipboard
10            .load_wait(
11                clipboard.setter.atoms.clipboard,
12                clipboard.setter.atoms.string,
13                clipboard.setter.atoms.property,
14            )
15            .unwrap();
16
17        let val = String::from_utf8(val).unwrap();
18
19        println!("{}", val);
20    }
21}
examples/monitor_primary_selection.rs (line 7)
6fn main() {
7    let clipboard = Clipboard::new().unwrap();
8    let mut last = String::new();
9
10    println!("Waiting for selection...");
11
12    loop {
13        if let Ok(curr) = clipboard.load_wait(
14            clipboard.getter.atoms.primary,
15            clipboard.getter.atoms.utf8_string,
16            clipboard.getter.atoms.property
17        ) {
18            let curr = String::from_utf8_lossy(&curr);
19            let curr = curr
20                .trim_matches('\u{0}')
21                .trim();
22            if !curr.is_empty() && last != curr {
23                last = curr.to_owned();
24                println!("Contents of primary selection: {}", last);
25                println!("Waiting for selection...");
26            }
27        }
28    }
29}
Source

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)
7fn main() {
8    let clipboard = Clipboard::new().unwrap();
9    let val =
10        clipboard.load(
11            clipboard.setter.atoms.clipboard,
12            clipboard.setter.atoms.utf8_string,
13            clipboard.setter.atoms.property,
14            Duration::from_secs(3)
15        )
16        .unwrap();
17    let val = String::from_utf8(val).unwrap();
18
19    print!("{}", val);
20}
Source

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)
5fn main() {
6    let clipboard = Clipboard::new().unwrap();
7
8    loop {
9        let val = clipboard
10            .load_wait(
11                clipboard.setter.atoms.clipboard,
12                clipboard.setter.atoms.string,
13                clipboard.setter.atoms.property,
14            )
15            .unwrap();
16
17        let val = String::from_utf8(val).unwrap();
18
19        println!("{}", val);
20    }
21}
More examples
Hide additional examples
examples/monitor_primary_selection.rs (lines 13-17)
6fn main() {
7    let clipboard = Clipboard::new().unwrap();
8    let mut last = String::new();
9
10    println!("Waiting for selection...");
11
12    loop {
13        if let Ok(curr) = clipboard.load_wait(
14            clipboard.getter.atoms.primary,
15            clipboard.getter.atoms.utf8_string,
16            clipboard.getter.atoms.property
17        ) {
18            let curr = String::from_utf8_lossy(&curr);
19            let curr = curr
20                .trim_matches('\u{0}')
21                .trim();
22            if !curr.is_empty() && last != curr {
23                last = curr.to_owned();
24                println!("Contents of primary selection: {}", last);
25                println!("Waiting for selection...");
26            }
27        }
28    }
29}
Source

pub fn store<T: Into<Vec<u8>>>( &self, selection: Atom, target: Atom, value: T, ) -> Result<(), Error>

store value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.