Skip to content

Commit

Permalink
Switch from crate clipboard to arboard
Browse files Browse the repository at this point in the history
This avoids a dependency via x11-clipboard to an old version of xcb,
v0.3. Problems and annoyances with xcb v0.3 include

- safety: aweinstock314/rust-clipboard#90
- build script depends on python
- won't build in a sandbox, as it writes to the source directory

See also aweinstock314/rust-clipboard#91
  • Loading branch information
tv42 committed Nov 18, 2023
1 parent c0b4a07 commit e1003d3
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 12 deletions.
88 changes: 82 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lapce-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ 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"] }
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"
Expand Down
24 changes: 19 additions & 5 deletions lapce-app/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{
time::Duration,
};

use clipboard::{ClipboardContext, ClipboardProvider};
use floem::{
action::exec_after,
cosmic_text::{Attrs, AttrsList, FamilyOwned, TextLayout},
Expand Down Expand Up @@ -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::{
Expand All @@ -61,7 +61,7 @@ use crate::{
pub mod phantom_text;

pub struct SystemClipboard {
ctx: ClipboardContext,
inner: arboard::Clipboard,
}

impl Default for SystemClipboard {
Expand All @@ -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<String> {
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<str>) {
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
});
}
}

Expand Down

0 comments on commit e1003d3

Please sign in to comment.