diff --git a/Cargo.lock b/Cargo.lock index 618b0f5ee7..d601e08d40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -191,6 +191,23 @@ version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859" +[[package]] +name = "arboard" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac57f2b058a76363e357c056e4f74f1945bf734d37b8b3ef49066c4787dde0fc" +dependencies = [ + "clipboard-win 4.5.0", + "log", + "objc", + "objc-foundation", + "objc_id", + "parking_lot 0.12.1", + "thiserror", + "winapi", + "x11rb 0.10.1", +] + [[package]] name = "arc-swap" version = "1.6.0" @@ -778,7 +795,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7" dependencies = [ - "clipboard-win", + "clipboard-win 2.2.0", "objc", "objc-foundation", "objc_id", @@ -794,6 +811,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "clipboard-win" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" +dependencies = [ + "error-code", + "str-buf", + "winapi", +] + [[package]] name = "cocoa" version = "0.25.0" @@ -1487,6 +1515,16 @@ dependencies = [ "libc", ] +[[package]] +name = "error-code" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" +dependencies = [ + "libc", + "str-buf", +] + [[package]] name = "euclid" version = "0.22.9" @@ -1964,6 +2002,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "gethostname" version = "0.3.0" @@ -2812,11 +2860,11 @@ dependencies = [ "Inflector", "alacritty_terminal", "anyhow", + "arboard", "base64", "bytemuck", "chrono", "clap", - "clipboard", "config", "crossbeam-channel", "directories", @@ -4894,7 +4942,7 @@ dependencies = [ "wayland-sys 0.30.1", "web-sys", "windows-sys 0.48.0", - "x11rb", + "x11rb 0.12.0", ] [[package]] @@ -4943,6 +4991,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "str-buf" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" + [[package]] name = "stretto" version = "0.8.1" @@ -7178,7 +7232,7 @@ dependencies = [ "web-time", "windows-sys 0.48.0", "x11-dl", - "x11rb", + "x11rb 0.12.0", "xkbcommon-dl", ] @@ -7260,6 +7314,19 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "x11rb" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" +dependencies = [ + "gethostname 0.2.3", + "nix 0.24.2", + "winapi", + "winapi-wsapoll", + "x11rb-protocol 0.10.0", +] + [[package]] name = "x11rb" version = "0.12.0" @@ -7267,14 +7334,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1641b26d4dec61337c35a1b1aaf9e3cba8f46f0b43636c609ab0291a648040a" dependencies = [ "as-raw-xcb-connection", - "gethostname", + "gethostname 0.3.0", "libc", "libloading 0.7.3", "nix 0.26.4", "once_cell", "winapi", "winapi-wsapoll", - "x11rb-protocol", + "x11rb-protocol 0.12.0", +] + +[[package]] +name = "x11rb-protocol" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" +dependencies = [ + "nix 0.24.2", ] [[package]] diff --git a/lapce-app/Cargo.toml b/lapce-app/Cargo.toml index 1f5d1c18d6..7c7d5169a1 100644 --- a/lapce-app/Cargo.toml +++ b/lapce-app/Cargo.toml @@ -51,7 +51,6 @@ sled = "0.34.7" bytemuck = "1.14.0" tokio = { version = "1.21", features = ["full"] } futures = "0.3.26" -clipboard = "0.5.0" floem = { git = "https://github.com/lapce/floem", rev = "4621c89a5f3d43ec7d8d0f51c0a0b7214eb03a56" } # floem = { path = "../../workspaces/floem" } config = { version = "0.13.2", default-features = false, features = ["toml"] } @@ -59,6 +58,7 @@ structdesc = { git = "https://github.com/lapce/structdesc" } base64 = "0.21.5" sha2 = "0.10.6" zip = { version = "0.6.6", default-features = false, features = ["deflate"] } +arboard = { version = "3.2.1", default-features = false } [target.'cfg(target_os="macos")'.dependencies] fs_extra = "1.2.0" diff --git a/lapce-app/src/doc.rs b/lapce-app/src/doc.rs index f717afe358..f668b02cc1 100644 --- a/lapce-app/src/doc.rs +++ b/lapce-app/src/doc.rs @@ -8,7 +8,6 @@ use std::{ time::Duration, }; -use clipboard::{ClipboardContext, ClipboardProvider}; use floem::{ action::exec_after, cosmic_text::{Attrs, AttrsList, FamilyOwned, TextLayout}, @@ -47,6 +46,7 @@ use lsp_types::{ }; use serde::{Deserialize, Serialize}; use smallvec::SmallVec; +use tracing::error; use self::phantom_text::{PhantomText, PhantomTextKind, PhantomTextLine}; use crate::{ @@ -61,7 +61,7 @@ use crate::{ pub mod phantom_text; pub struct SystemClipboard { - ctx: ClipboardContext, + inner: arboard::Clipboard, } impl Default for SystemClipboard { @@ -73,18 +73,32 @@ impl Default for SystemClipboard { impl SystemClipboard { pub fn new() -> Self { SystemClipboard { - ctx: ClipboardProvider::new().unwrap(), + inner: arboard::Clipboard::new().unwrap(), } } } impl Clipboard for SystemClipboard { fn get_string(&mut self) -> Option { - self.ctx.get_contents().ok() + self.inner + .get_text() + .map_err(|error| { + if !matches!(error, arboard::Error::ContentNotAvailable) { + error!("clipboard error: paste: {error:?}"); + } + error + }) + .ok() } fn put_string(&mut self, s: impl AsRef) { - let _ = self.ctx.set_contents(s.as_ref().to_string()); + let _ = self + .inner + .set_text(s.as_ref().to_string()) + .map_err(|error| { + error!("clipboard error: copy: {error:?}"); + error + }); } }