Use copypasta for now
This commit is contained in:
parent
10f1ff7a07
commit
7070c91d26
2 changed files with 13 additions and 64 deletions
|
|
@ -13,10 +13,7 @@ categories = ["gui"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
raw-window-handle = "0.3"
|
raw-window-handle = "0.3"
|
||||||
clipboard = "0.5"
|
copypasta = "0.6"
|
||||||
|
|
||||||
[target.'cfg(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten"))))'.dependencies]
|
|
||||||
smithay-clipboard = "0.3"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
winit = "=0.20.0-alpha5"
|
winit = "=0.20.0-alpha5"
|
||||||
|
|
|
||||||
72
src/lib.rs
72
src/lib.rs
|
|
@ -3,21 +3,7 @@ use std::cell::RefCell;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
pub struct Clipboard {
|
pub struct Clipboard {
|
||||||
raw: Raw,
|
raw: RefCell<Box<dyn copypasta::ClipboardProvider>>,
|
||||||
}
|
|
||||||
|
|
||||||
enum Raw {
|
|
||||||
#[cfg(all(
|
|
||||||
unix,
|
|
||||||
not(any(
|
|
||||||
target_os = "macos",
|
|
||||||
target_os = "android",
|
|
||||||
target_os = "emscripten"
|
|
||||||
))
|
|
||||||
))]
|
|
||||||
Wayland(RefCell<smithay_clipboard::WaylandClipboard>),
|
|
||||||
|
|
||||||
NotWayland(RefCell<clipboard::ClipboardContext>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clipboard {
|
impl Clipboard {
|
||||||
|
|
@ -36,66 +22,32 @@ impl Clipboard {
|
||||||
RawWindowHandle::Wayland(handle) => {
|
RawWindowHandle::Wayland(handle) => {
|
||||||
assert!(!handle.display.is_null());
|
assert!(!handle.display.is_null());
|
||||||
|
|
||||||
Raw::Wayland(RefCell::new(unsafe {
|
Box::new(unsafe {
|
||||||
smithay_clipboard::WaylandClipboard::new_from_external(
|
let (_, raw) = copypasta::wayland_clipboard::create_clipboards_from_external(
|
||||||
handle.display as *mut _,
|
handle.display as *mut _,
|
||||||
)
|
);
|
||||||
}))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
use clipboard::ClipboardProvider as _;
|
|
||||||
|
|
||||||
Raw::NotWayland(RefCell::new(
|
raw
|
||||||
clipboard::ClipboardContext::new()?
|
}) as _
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
_ => Box::new(copypasta::ClipboardContext::new()?) as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Clipboard { raw })
|
Ok(Clipboard {
|
||||||
|
raw: RefCell::new(raw),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&self) -> Result<String, Box<dyn Error>> {
|
pub fn read(&self) -> Result<String, Box<dyn Error>> {
|
||||||
// TODO: Think about use of `RefCell`
|
// TODO: Think about use of `RefCell`
|
||||||
// Maybe we should make `read` mutable (?)
|
// Maybe we should make `read` mutable (?)
|
||||||
use clipboard::ClipboardProvider as _;
|
self.raw.borrow_mut().get_contents()
|
||||||
|
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(
|
pub fn write(
|
||||||
&mut self,
|
&mut self,
|
||||||
contents: impl Into<String>,
|
contents: impl Into<String>,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
use clipboard::ClipboardProvider as _;
|
self.raw.borrow_mut().set_contents(contents.into())
|
||||||
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue