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)
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
Hide additional 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...");
            }
        }
    }
}
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)
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);
}
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)
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
Hide additional 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...");
            }
        }
    }
}
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>,

§

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>,

§

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.