From 5c638bc295d1305f4c0dde10e24f5f401b7dc943 Mon Sep 17 00:00:00 2001 From: Yeicor <4929005+Yeicor@users.noreply.github.com> Date: Thu, 26 May 2022 21:03:12 +0200 Subject: [PATCH 1/2] Adds a dummy clipboard to fix building for unsupported platforms. --- src/common.rs | 1 + src/dummy_clipboard.rs | 44 ++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 14 ++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/dummy_clipboard.rs 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..727972f0 --- /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..1f6977a0 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( +target_os = "macos", +windows, +all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))) +)))] +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( +target_os = "macos", +windows, +all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))) +)))] +type PlatformClipboard = dummy_clipboard::DummyClipboard; // Unsupported platforms + #[cfg(all( unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten")), From 574e30e32a2c122c14e29bbc963997cded582c63 Mon Sep 17 00:00:00 2001 From: Yeicor <4929005+Yeicor@users.noreply.github.com> Date: Thu, 26 May 2022 22:59:56 +0200 Subject: [PATCH 2/2] cargo fmt --all --- src/dummy_clipboard.rs | 62 +++++++++++++++++++++--------------------- src/lib.rs | 12 ++++---- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/dummy_clipboard.rs b/src/dummy_clipboard.rs index 727972f0..b379f1fe 100644 --- a/src/dummy_clipboard.rs +++ b/src/dummy_clipboard.rs @@ -6,39 +6,39 @@ use crate::ImageData; pub struct DummyClipboard {} impl DummyClipboard { - pub fn new() -> Result { - Ok(DummyClipboard::default()) - } + 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) - } + /// 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) - } + /// 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) - } + /// 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) - } + /// 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 1f6977a0..1fca62e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,9 +36,9 @@ pub mod windows_clipboard; pub mod osx_clipboard; #[cfg(not(any( -target_os = "macos", -windows, -all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))) + all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))), + windows, + target_os = "macos" )))] pub mod dummy_clipboard; // Unsupported platforms @@ -50,9 +50,9 @@ type PlatformClipboard = windows_clipboard::WindowsClipboardContext; type PlatformClipboard = osx_clipboard::OSXClipboardContext; #[cfg(not(any( -target_os = "macos", -windows, -all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))) + all(unix, not(any(target_os = "macos", target_os = "android", target_os = "emscripten"))), + windows, + target_os = "macos" )))] type PlatformClipboard = dummy_clipboard::DummyClipboard; // Unsupported platforms