diff --git a/src/common.rs b/src/common.rs index c90f5e56..6a9bbde4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -30,6 +30,7 @@ pub enum Error { /// This can be caused by a few conditions: /// - Using the Primary clipboard with an older Wayland compositor (that doesn't support version 2) /// - Using the Secondary clipboard on Wayland + /// - Using the clipboard on an unsupported platform #[error("The selected clipboard is not supported with the current system configuration.")] ClipboardNotSupported, diff --git a/src/dummy_clipboard.rs b/src/dummy_clipboard.rs new file mode 100644 index 00000000..b379f1fe --- /dev/null +++ b/src/dummy_clipboard.rs @@ -0,0 +1,44 @@ +use crate::Error; +#[cfg(feature = "image-data")] +use crate::ImageData; + +#[derive(Default, Debug)] +pub struct DummyClipboard {} + +impl DummyClipboard { + pub fn new() -> Result { + Ok(DummyClipboard::default()) + } + + /// Fetches utf-8 text from the clipboard and returns it. + pub fn get_text(&mut self) -> Result { + Err(Error::ContentNotAvailable) + } + + /// Places the text onto the clipboard. Any valid utf-8 string is accepted. + pub fn set_text(&mut self, _text: String) -> Result<(), Error> { + Err(Error::ClipboardNotSupported) + } + + /// Fetches image data from the clipboard, and returns the decoded pixels. + /// + /// Any image data placed on the clipboard with `set_image` will be possible read back, using + /// this function. However it's of not guaranteed that an image placed on the clipboard by any + /// other application will be of a supported format. + #[cfg(feature = "image-data")] + pub fn get_image(&mut self) -> Result, Error> { + Err(Error::ContentNotAvailable) + } + + /// Places an image to the clipboard. + /// + /// The chosen output format, depending on the platform is the following: + /// + /// - On macOS: `NSImage` object + /// - On Linux: PNG, under the atom `image/png` + /// - On Windows: In order of priority `CF_DIB` and `CF_BITMAP` + #[cfg(feature = "image-data")] + pub fn set_image(&mut self, _image: ImageData) -> Result<(), Error> { + Err(Error::ClipboardNotSupported) + } +} diff --git a/src/lib.rs b/src/lib.rs index 6d81f961..1fca62e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,13 @@ pub mod windows_clipboard; #[cfg(target_os = "macos")] pub mod osx_clipboard; +#[cfg(not(any( + all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))), + windows, + target_os = "macos" +)))] +pub mod dummy_clipboard; // Unsupported platforms + #[cfg(all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten")),))] type PlatformClipboard = common_linux::LinuxClipboard; #[cfg(windows)] @@ -42,6 +49,13 @@ type PlatformClipboard = windows_clipboard::WindowsClipboardContext; #[cfg(target_os = "macos")] type PlatformClipboard = osx_clipboard::OSXClipboardContext; +#[cfg(not(any( + all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))), + windows, + target_os = "macos" +)))] +type PlatformClipboard = dummy_clipboard::DummyClipboard; // Unsupported platforms + #[cfg(all( unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten")),