diff --git a/src/lib.rs b/src/lib.rs index 090505a..075e1fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ //! should have surface around. #![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use)] +use std::borrow::Cow; use std::ffi::c_void; use std::io::Result; use std::sync::mpsc::{self, Receiver}; @@ -55,7 +56,7 @@ impl Clipboard { /// /// Load the requested type from a clipboard on the last observed seat. pub fn load(&self) -> Result { - self.load_inner(SelectionTarget::Clipboard) + self.load_inner(SelectionTarget::Clipboard, T::allowed()) } /// Load clipboard data. @@ -70,7 +71,7 @@ impl Clipboard { /// Load the requested type from a primary clipboard on the last observed /// seat. pub fn load_primary(&self) -> Result { - self.load_inner(SelectionTarget::Primary) + self.load_inner(SelectionTarget::Primary, T::allowed()) } /// Load primary clipboard data. @@ -80,6 +81,26 @@ impl Clipboard { self.load_primary::().map(|t| t.0) } + /// Load raw clipboard data. + /// + /// Loads content from a primary clipboard on a last observed seat. + pub fn load_raw( + &self, + allowed: impl Into>, + ) -> Result<(Vec, MimeType)> { + self.load_inner(SelectionTarget::Clipboard, allowed) + } + + /// Load raw primary clipboard data. + /// + /// Loads content from a primary clipboard on a last observed seat. + pub fn load_primary_raw( + &self, + allowed: impl Into>, + ) -> Result<(Vec, MimeType)> { + self.load_inner(SelectionTarget::Primary, allowed) + } + /// Store custom data to a clipboard. /// /// Stores data of the provided type to a clipboard on a last observed seat. @@ -109,8 +130,12 @@ impl Clipboard { self.store_primary(Text(text.into())); } - fn load_inner(&self, target: SelectionTarget) -> Result { - let _ = self.request_sender.send(worker::Command::Load(T::allowed().to_vec(), target)); + fn load_inner, MimeType)> + 'static>( + &self, + target: SelectionTarget, + allowed: impl Into>, + ) -> Result { + let _ = self.request_sender.send(worker::Command::Load(allowed.into(), target)); match self.request_receiver.recv() { Ok(res) => res.and_then(|(data, mime)| { diff --git a/src/worker.rs b/src/worker.rs index 77fbe8c..1ddc90f 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::io::{Error, ErrorKind, Result}; use std::sync::mpsc::Sender; @@ -29,7 +30,7 @@ pub fn spawn( /// Clipboard worker thread command. pub enum Command { /// Loads data for the first available mime type in the provided list. - Load(Vec, SelectionTarget), + Load(Cow<'static, [MimeType]>, SelectionTarget), /// Store Data with the given mime types. Store(Box, SelectionTarget), /// Shutdown the worker.