pub struct DataControl { /* private fields */ }Expand description
A connection to the Wayland compositor’s clipboard.
Connecting spawns one thread that owns the Wayland connection. Dropping the handle stops and joins it.
use lamco_data_control::{Content, DataControl};
let clipboard = DataControl::connect()?;
clipboard.set_selection(Content::new().data("text/plain;charset=utf-8", "hello"))?;Implementations§
Source§impl DataControl
impl DataControl
Sourcepub fn connect() -> Result<Self>
pub fn connect() -> Result<Self>
Connect with the default Options.
§Errors
See Error: no compositor, no data-control protocol, or no seat.
Examples found in repository?
More examples
5fn main() -> lamco_data_control::Result<()> {
6 let text = std::env::args()
7 .nth(1)
8 .unwrap_or_else(|| "hello".to_owned());
9 let clipboard = DataControl::connect()?;
10 clipboard.set_selection(
11 Content::new()
12 .data("text/plain;charset=utf-8", text.clone())
13 .data("text/plain", text),
14 )?;
15 println!("clipboard set; press Ctrl-C to release it");
16 std::thread::park();
17 Ok(())
18}Sourcepub fn connect_with(options: &Options) -> Result<Self>
pub fn connect_with(options: &Options) -> Result<Self>
Sourcepub fn selection_mime_types(&self) -> Vec<String>
pub fn selection_mime_types(&self) -> Vec<String>
MIME types the current selection offers; empty if there is none.
Sourcepub fn on_change(&self, callback: impl Fn(Vec<String>) + Send + Sync + 'static)
pub fn on_change(&self, callback: impl Fn(Vec<String>) + Send + Sync + 'static)
Call callback with the offered MIME types whenever another client
changes the selection.
A selection this handle set itself is not reported; it still advances
serial and updates
selection_mime_types.
The callback runs on the worker thread and must not block.
Sourcepub fn on_transfer(
&self,
callback: impl Fn(TransferRequest) + Send + Sync + 'static,
)
pub fn on_transfer( &self, callback: impl Fn(TransferRequest) + Send + Sync + 'static, )
Call callback when something pastes a type that was advertised
without data.
The callback runs on the worker thread and must not block; hand the request to another thread and answer it there.
Sourcepub fn set_selection(&self, content: Content) -> Result<()>
pub fn set_selection(&self, content: Content) -> Result<()>
Examples found in repository?
5fn main() -> lamco_data_control::Result<()> {
6 let text = std::env::args()
7 .nth(1)
8 .unwrap_or_else(|| "hello".to_owned());
9 let clipboard = DataControl::connect()?;
10 clipboard.set_selection(
11 Content::new()
12 .data("text/plain;charset=utf-8", text.clone())
13 .data("text/plain", text),
14 )?;
15 println!("clipboard set; press Ctrl-C to release it");
16 std::thread::park();
17 Ok(())
18}Sourcepub fn update_data(
&self,
mime_type: impl Into<String>,
data: impl Into<Vec<u8>>,
) -> Result<()>
pub fn update_data( &self, mime_type: impl Into<String>, data: impl Into<Vec<u8>>, ) -> Result<()>
Add data for a type after set_selection,
without replacing the selection.
§Errors
Error::Stopped if the worker has shut down.
Sourcepub fn clear_selection(&self) -> Result<()>
pub fn clear_selection(&self) -> Result<()>
Give up the selection if this handle still owns it.
§Errors
Error::Stopped if the worker has shut down.
Sourcepub fn read(&self, mime_type: &str) -> Result<Option<Vec<u8>>>
pub fn read(&self, mime_type: &str) -> Result<Option<Vec<u8>>>
Read the current selection as mime_type.
Charset differences are tolerated, see find_mime_match. Returns
Ok(None) when there is no selection or it does not offer the type.
§Errors
Error::TooLarge past the size limit, Error::Timeout if the
source stalls for five seconds, Error::Stopped if the worker has
shut down, Error::Io for pipe failures.
Trait Implementations§
Source§impl Debug for DataControl
impl Debug for DataControl
Source§impl Drop for DataControl
impl Drop for DataControl
Auto Trait Implementations§
impl !RefUnwindSafe for DataControl
impl !UnwindSafe for DataControl
impl Freeze for DataControl
impl Send for DataControl
impl Sync for DataControl
impl Unpin for DataControl
impl UnsafeUnpin for DataControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.