From 7070c91d26266566885a24b2b8d1077691ff44f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 18 Dec 2019 06:38:55 +0100 Subject: [PATCH] Use `copypasta` for now --- Cargo.toml | 5 +--- src/lib.rs | 72 +++++++++--------------------------------------------- 2 files changed, 13 insertions(+), 64 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 33eec1c..c1ee5ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,7 @@ categories = ["gui"] [dependencies] raw-window-handle = "0.3" -clipboard = "0.5" - -[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dependencies] -smithay-clipboard = "0.3" +copypasta = "0.6" [dev-dependencies] winit = "=0.20.0-alpha5" diff --git a/src/lib.rs b/src/lib.rs index e48e4c3..6cf53bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,21 +3,7 @@ use std::cell::RefCell; use std::error::Error; pub struct Clipboard { - raw: Raw, -} - -enum Raw { - #[cfg(all( - unix, - not(any( - target_os = "macos", - target_os = "android", - target_os = "emscripten" - )) - ))] - Wayland(RefCell), - - NotWayland(RefCell), + raw: RefCell>, } impl Clipboard { @@ -36,66 +22,32 @@ impl Clipboard { RawWindowHandle::Wayland(handle) => { assert!(!handle.display.is_null()); - Raw::Wayland(RefCell::new(unsafe { - smithay_clipboard::WaylandClipboard::new_from_external( + Box::new(unsafe { + let (_, raw) = copypasta::wayland_clipboard::create_clipboards_from_external( handle.display as *mut _, - ) - })) - } - _ => { - use clipboard::ClipboardProvider as _; + ); - Raw::NotWayland(RefCell::new( - clipboard::ClipboardContext::new()? - )) + raw + }) as _ } + _ => Box::new(copypasta::ClipboardContext::new()?) as _, }; - Ok(Clipboard { raw }) + Ok(Clipboard { + raw: RefCell::new(raw), + }) } pub fn read(&self) -> Result> { // TODO: Think about use of `RefCell` // Maybe we should make `read` mutable (?) - use clipboard::ClipboardProvider as _; - - match &self.raw { - #[cfg(all( - unix, - not(any( - target_os = "macos", - target_os = "android", - target_os = "emscripten" - )) - ))] - Raw::Wayland(clipboard) => Ok(clipboard.borrow_mut().load(None)), - Raw::NotWayland(clipboard) => clipboard.borrow_mut().get_contents(), - } + self.raw.borrow_mut().get_contents() } pub fn write( &mut self, contents: impl Into, ) -> Result<(), Box> { - use clipboard::ClipboardProvider as _; - - match &self.raw { - #[cfg(all( - unix, - not(any( - target_os = "macos", - target_os = "android", - target_os = "emscripten" - )) - ))] - Raw::Wayland(clipboard) => { - clipboard.borrow_mut().store(None, contents); - - Ok(()) - } - Raw::NotWayland(clipboard) => { - clipboard.borrow_mut().set_contents(contents.into()) - } - } + self.raw.borrow_mut().set_contents(contents.into()) } }