feat: add wayland impl for custom mime types

This commit is contained in:
Ashley Wulber 2024-02-29 17:15:30 -05:00
parent 8e7827ebbe
commit 6c41143f5c
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
5 changed files with 225 additions and 1 deletions

View file

@ -18,6 +18,8 @@ use std::{
sync::{Arc, Mutex},
};
pub use smithay_clipboard::mime::{AllowedMimeTypes, AsMimeTypes, MimeType};
pub struct Clipboard {
context: Arc<Mutex<smithay_clipboard::Clipboard>>,
}
@ -53,4 +55,34 @@ impl Clipboard {
Ok(())
}
pub fn write<T: AsMimeTypes + Send + Sync + 'static>(
&mut self,
data: T,
) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store(data);
Ok(())
}
pub fn write_primary<T: AsMimeTypes + Send + Sync + 'static>(
&mut self,
data: T,
) -> Result<(), Box<dyn Error>> {
self.context.lock().unwrap().store_primary(data);
Ok(())
}
pub fn read<T: AllowedMimeTypes + 'static>(
&self,
) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load()?)
}
pub fn read_primary<T: AllowedMimeTypes + 'static>(
&self,
) -> Result<T, Box<dyn Error>> {
Ok(self.context.lock().unwrap().load_primary()?)
}
}