diff --git a/Cargo.toml b/Cargo.toml index 9b69535..15c8b79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,9 @@ clipboard_macos = { version = "0.1", path = "./macos" } clipboard_x11 = { version = "0.3", path = "./x11" } clipboard_wayland = { version = "0.2", path = "./wayland" } +[target.'cfg(not(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "android", target_os = "emscripten"))), target_os = "windows", target_os = "macos", target_os = "ios", target_os = "android")))'.dependencies] +clipboard_dummy = { version = "0.3", path = "./dummy" } + [dev-dependencies] rand = "0.8" winit = "0.23" diff --git a/dummy/Cargo.toml b/dummy/Cargo.toml new file mode 100644 index 0000000..d156086 --- /dev/null +++ b/dummy/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "clipboard_dummy" +version = "0.3.1" +authors = ["Héctor Ramón Jiménez "] +edition = "2018" +description = "A library to obtain access to the dummy clipboard" +license = "MIT" +repository = "https://github.com/hecrj/window_clipboard" +documentation = "https://docs.rs/clipboard_x11" +keywords = ["clipboard", "dummy"] + +[dependencies] diff --git a/dummy/LICENSE b/dummy/LICENSE new file mode 100644 index 0000000..46d7576 --- /dev/null +++ b/dummy/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2019 quininer@live.com, Héctor Ramón, window_clipboard_x11 contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/dummy/src/lib.rs b/dummy/src/lib.rs new file mode 100644 index 0000000..8338ae1 --- /dev/null +++ b/dummy/src/lib.rs @@ -0,0 +1,22 @@ +#[forbid(unsafe_code)] +use std::error::Error; + +/// A connection to an Dummy [`Clipboard`]. +pub struct Clipboard; + +impl Clipboard { + /// Connect to the Dummy and obtain a [`Clipboard`]. + pub fn connect() -> Result> { + Ok(Clipboard) + } + + /// Read the current [`Clipboard`] value. + pub fn read(&self) -> Result> { + Ok(String::new()) + } + + /// Write a new value to the [`Clipboard`]. + pub fn write(&mut self, contents: String) -> Result<(), Box> { + Ok(()) + } +} diff --git a/src/lib.rs b/src/lib.rs index c396478..6a940a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,24 @@ mod platform; #[path = "platform/android.rs"] mod platform; +#[cfg(not(any( + all( + unix, + not(any( + target_os = "macos", + target_os = "ios", + target_os = "android", + target_os = "emscripten" + )) + ), + target_os = "windows", + target_os = "macos", + target_os = "ios", + target_os = "android" +)))] +#[path = "platform/dummy.rs"] +mod platform; + use raw_window_handle::HasRawWindowHandle; use std::error::Error; diff --git a/src/platform/dummy.rs b/src/platform/dummy.rs new file mode 100644 index 0000000..27b44a9 --- /dev/null +++ b/src/platform/dummy.rs @@ -0,0 +1,23 @@ +use crate::ClipboardProvider; + +use raw_window_handle::HasRawWindowHandle; +use std::error::Error; + +pub use clipboard_dummy as dummy; + +pub fn connect( + window: &W, +) -> Result, Box> { + let clipboard = Box::new(dummy::Clipboard::connect()?); + Ok(clipboard) +} + +impl ClipboardProvider for dummy::Clipboard { + fn read(&self) -> Result> { + self.read() + } + + fn write(&mut self, contents: String) -> Result<(), Box> { + self.write(contents) + } +} diff --git a/x11/src/lib.rs b/x11/src/lib.rs index 0e2b54e..346bf51 100644 --- a/x11/src/lib.rs +++ b/x11/src/lib.rs @@ -360,23 +360,28 @@ impl Worker { if event.target == self.context.atoms.targets { let data = [self.context.atoms.targets, target]; - self.context.connection.change_property32( - xproto::PropMode::REPLACE, - event.requestor, - event.property, - xproto::AtomEnum::ATOM, - &data, - ) - .expect("Change property"); + self.context + .connection + .change_property32( + xproto::PropMode::REPLACE, + event.requestor, + event.property, + xproto::AtomEnum::ATOM, + &data, + ) + .expect("Change property"); } else { - let _ = self.context.connection.change_property8( - xproto::PropMode::REPLACE, - event.requestor, - event.property, - target, - value, - ) - .expect("Change property"); + let _ = self + .context + .connection + .change_property8( + xproto::PropMode::REPLACE, + event.requestor, + event.property, + target, + value, + ) + .expect("Change property"); } let _ = xproto::send_event(