From 0f74d591986c71e0786128827c98f17c0054aadf Mon Sep 17 00:00:00 2001 From: Andra Antariksa Date: Wed, 10 Nov 2021 20:54:49 +0700 Subject: [PATCH 1/6] =?UTF-8?q?Add=20dummy=20platform=20=F0=9F=8C=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 3 +++ dummy/Cargo.toml | 12 ++++++++++++ dummy/LICENSE | 7 +++++++ dummy/src/lib.rs | 22 ++++++++++++++++++++++ src/lib.rs | 18 ++++++++++++++++++ src/platform/dummy.rs | 23 +++++++++++++++++++++++ x11/src/lib.rs | 37 +++++++++++++++++++++---------------- 7 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 dummy/Cargo.toml create mode 100644 dummy/LICENSE create mode 100644 dummy/src/lib.rs create mode 100644 src/platform/dummy.rs 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( From 9a5cac87bf9e2b8460045def1d52d43bf1e52813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 27 Jan 2022 16:41:00 +0700 Subject: [PATCH 2/6] Remove `clipboard_dummy` crate --- Cargo.toml | 4 +--- dummy/Cargo.toml | 12 ------------ dummy/LICENSE | 7 ------- dummy/src/lib.rs | 22 ---------------------- src/platform/dummy.rs | 19 ++++++++++++------- 5 files changed, 13 insertions(+), 51 deletions(-) delete mode 100644 dummy/Cargo.toml delete mode 100644 dummy/LICENSE delete mode 100644 dummy/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 15c8b79..e8f11bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ categories = ["gui"] [dependencies] raw-window-handle = "0.3" +thiserror = "1.0" [target.'cfg(windows)'.dependencies] clipboard-win = { version = "4.0", features = ["std"] } @@ -24,9 +25,6 @@ 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 deleted file mode 100644 index d156086..0000000 --- a/dummy/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[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 deleted file mode 100644 index 46d7576..0000000 --- a/dummy/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 8338ae1..0000000 --- a/dummy/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -#[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/platform/dummy.rs b/src/platform/dummy.rs index 27b44a9..9835f97 100644 --- a/src/platform/dummy.rs +++ b/src/platform/dummy.rs @@ -3,21 +3,26 @@ use crate::ClipboardProvider; use raw_window_handle::HasRawWindowHandle; use std::error::Error; -pub use clipboard_dummy as dummy; +struct Dummy; pub fn connect( - window: &W, + _window: &W, ) -> Result, Box> { - let clipboard = Box::new(dummy::Clipboard::connect()?); - Ok(clipboard) + Ok(Dummy) } -impl ClipboardProvider for dummy::Clipboard { +impl ClipboardProvider for Dummy { fn read(&self) -> Result> { - self.read() + Err(Error::Unimplemented) } fn write(&mut self, contents: String) -> Result<(), Box> { - self.write(contents) + Err(Error::Unimplemented) } } + +#[derive(Debug, Clone, Copy, thiserror::Error)] +enum Error { + #[error("unimplemented")] + Unimplemented, +} From 2000137a2dc136c6e7999ab24254e80cb3c9976f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 27 Jan 2022 16:42:07 +0700 Subject: [PATCH 3/6] Build for Wasm in `test` worflow on GitHub CI --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8527f0d..fd7e216 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,3 +14,7 @@ jobs: - uses: actions/checkout@master - name: Run tests run: cargo test --verbose + - name: Add Wasm target + run: rustup target add wasm32-unknown-unknown + - name: Run tests on Wasm + run: cargo build --verbose --target wasm32-unknown-unknown From a5ef1bf81e2dcdb2ea08081623b3b37ff82e0f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 27 Jan 2022 16:46:31 +0700 Subject: [PATCH 4/6] Fix `Error` name collision in `dummy` platform --- src/platform/dummy.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/platform/dummy.rs b/src/platform/dummy.rs index 9835f97..67ba0a1 100644 --- a/src/platform/dummy.rs +++ b/src/platform/dummy.rs @@ -1,22 +1,24 @@ use crate::ClipboardProvider; use raw_window_handle::HasRawWindowHandle; -use std::error::Error; struct Dummy; pub fn connect( _window: &W, -) -> Result, Box> { +) -> Result, Box> { Ok(Dummy) } impl ClipboardProvider for Dummy { - fn read(&self) -> Result> { + fn read(&self) -> Result> { Err(Error::Unimplemented) } - fn write(&mut self, contents: String) -> Result<(), Box> { + fn write( + &mut self, + contents: String, + ) -> Result<(), Box> { Err(Error::Unimplemented) } } From 93c7e170908bc81958844f837086a4398fabd92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 27 Jan 2022 16:49:44 +0700 Subject: [PATCH 5/6] Box all the things in `dummy` platform --- src/platform/dummy.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/dummy.rs b/src/platform/dummy.rs index 67ba0a1..30bbc01 100644 --- a/src/platform/dummy.rs +++ b/src/platform/dummy.rs @@ -7,19 +7,19 @@ struct Dummy; pub fn connect( _window: &W, ) -> Result, Box> { - Ok(Dummy) + Ok(Box::new(Dummy)) } impl ClipboardProvider for Dummy { fn read(&self) -> Result> { - Err(Error::Unimplemented) + Err(Box::new(Error::Unimplemented)) } fn write( &mut self, contents: String, ) -> Result<(), Box> { - Err(Error::Unimplemented) + Err(Box::new(Error::Unimplemented)) } } From ae906dd623f26fafc1d4514b234b2454265ea544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 27 Jan 2022 16:50:52 +0700 Subject: [PATCH 6/6] Fix unused variable warning in `dummy` platform --- src/platform/dummy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/dummy.rs b/src/platform/dummy.rs index 30bbc01..410adc3 100644 --- a/src/platform/dummy.rs +++ b/src/platform/dummy.rs @@ -17,7 +17,7 @@ impl ClipboardProvider for Dummy { fn write( &mut self, - contents: String, + _contents: String, ) -> Result<(), Box> { Err(Box::new(Error::Unimplemented)) }