Browse Source

Replace copypasta with arboard (#1475)

* Replace copypasta with arboard

Closes https://github.com/emilk/egui/issues/1474

* Clean up deny.toml
pull/1482/head
Emil Ernerfeldt 3 years ago
committed by GitHub
parent
commit
65d16695ae
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 123
      Cargo.lock
  2. 47
      deny.toml
  3. 6
      egui-winit/Cargo.toml
  4. 38
      egui-winit/src/clipboard.rs

123
Cargo.lock

@ -90,6 +90,24 @@ dependencies = [
"num-traits",
]
[[package]]
name = "arboard"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6045ca509e4abacde2b884ac4618a51d0c017b5d85a3ee84a7226eb33b3154a9"
dependencies = [
"clipboard-win",
"log",
"objc",
"objc-foundation",
"objc_id",
"once_cell",
"parking_lot 0.12.0",
"thiserror",
"winapi",
"x11rb",
]
[[package]]
name = "arrayref"
version = "0.3.6"
@ -516,11 +534,12 @@ dependencies = [
[[package]]
name = "clipboard-win"
version = "3.1.1"
version = "4.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342"
checksum = "2f3e1238132dc01f081e1cbb9dace14e5ef4c3a51ee244bd982275fb514605db"
dependencies = [
"lazy-bytes-cast",
"error-code",
"str-buf",
"winapi",
]
@ -590,20 +609,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "copypasta"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4423d79fed83ebd9ab81ec21fa97144300a961782158287dc9bf7eddac37ff0b"
dependencies = [
"clipboard-win",
"objc",
"objc-foundation",
"objc_id",
"smithay-clipboard",
"x11-clipboard",
]
[[package]]
name = "core-foundation"
version = "0.7.0"
@ -1033,7 +1038,7 @@ dependencies = [
name = "egui-winit"
version = "0.17.0"
dependencies = [
"copypasta",
"arboard",
"dark-light",
"egui",
"epi",
@ -1247,6 +1252,16 @@ dependencies = [
"tracing",
]
[[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 = "event-listener"
version = "2.5.2"
@ -1425,6 +1440,16 @@ dependencies = [
"system-deps",
]
[[package]]
name = "gethostname"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "getrandom"
version = "0.2.5"
@ -1810,12 +1835,6 @@ dependencies = [
"arrayvec 0.7.2",
]
[[package]]
name = "lazy-bytes-cast"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10257499f089cd156ad82d0a9cd57d9501fa2c989068992a97eb3c27836f206b"
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -2509,15 +2528,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "quick-xml"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b"
dependencies = [
"memchr",
]
[[package]]
name = "quote"
version = "1.0.15"
@ -2989,16 +2999,6 @@ dependencies = [
"wayland-protocols",
]
[[package]]
name = "smithay-clipboard"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "610b551bd25378bfd2b8e7a0fcbd83d427e8f2f6a40c47ae0f70688e9949dd55"
dependencies = [
"smithay-client-toolkit",
"wayland-client",
]
[[package]]
name = "socket2"
version = "0.4.4"
@ -3040,6 +3040,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "str-buf"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a"
[[package]]
name = "strsim"
version = "0.8.0"
@ -3790,6 +3796,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "winapi-wsapoll"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
@ -3894,15 +3909,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "x11-clipboard"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473068b7b80ac86a18328824f1054e5e007898c47b5bbc281bd7abe32bc3653c"
dependencies = [
"xcb",
]
[[package]]
name = "x11-dl"
version = "2.19.1"
@ -3915,14 +3921,15 @@ dependencies = [
]
[[package]]
name = "xcb"
version = "0.10.1"
name = "x11rb"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c"
checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a"
dependencies = [
"libc",
"log",
"quick-xml",
"gethostname",
"nix 0.22.3",
"winapi",
"winapi-wsapoll",
]
[[package]]

47
deny.toml

@ -16,28 +16,27 @@ yanked = "deny"
ignore = [
"RUSTSEC-2020-0071", # https://rustsec.org/advisories/RUSTSEC-2020-0071 - chrono/time: Potential segfault in the time crate
"RUSTSEC-2020-0159", # https://rustsec.org/advisories/RUSTSEC-2020-0159 - chrono/time: Potential segfault in localtime_r invocations
"RUSTSEC-2021-0019", # https://rustsec.org/advisories/RUSTSEC-2021-0019 - xcb - is being worked on: https://github.com/rust-x-bindings/rust-xcb/issues/107
"RUSTSEC-2021-0127", # https://rustsec.org/advisories/RUSTSEC-2021-0127 - https://github.com/bheisler/criterion.rs/issues/534
]
[bans]
multiple-versions = "deny"
wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed
deny = [
{ name = "openssl" }, # prefer rustls
{ name = "openssl-sys" }, # prefer rustls
{ name = "openssl" }, # prefer rustls
{ name = "openssl-sys" }, # prefer rustls
]
skip = [
{ name = "ahash" }, # old version via dark-light
{ name = "arrayvec" }, # old version via tiny-skia
{ name = "hashbrown" }, # old version via dark-light
{ name = "time" }, # old version pulled in by unmaintianed crate 'chrono'
{ name = "ahash" }, # old version via dark-light
{ name = "arrayvec" }, # old version via tiny-skiaz
{ name = "hashbrown" }, # old version via dark-light
{ name = "time" }, # old version pulled in by unmaintianed crate 'chrono'
{ name = "ttf-parser" }, # different versions pulled in by ab_glyph and usvg
]
skip-tree = [
{ name = "criterion" }, # dev-dependnecy
{ name = "glium" }, # legacy crate, lots of old dependencies
{ name = "glutin" }, # legacy crate, lots of old dependencies
{ name = "glium" }, # legacy crate, lots of old dependencies
]
@ -47,29 +46,25 @@ allow-osi-fsf-free = "neither"
confidence-threshold = 0.92 # We want really high confidence when inferring licenses from text
copyleft = "deny"
allow = [
"Apache-2.0 WITH LLVM-exception", # https://spdx.org/licenses/LLVM-exception.html
"Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)
"BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)
"BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised)
"BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained
"CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/
"ISC", # https://tldrlegal.com/license/-isc-license
"MIT", # https://tldrlegal.com/license/mit-license
"MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11
"OpenSSL", # https://www.openssl.org/source/license.html
"Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib)
# "Apache-2.0 WITH LLVM-exception", # https://spdx.org/licenses/LLVM-exception.html
"Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)
"BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)
"BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised)
"BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained
"CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/
"ISC", # https://tldrlegal.com/license/-isc-license
"MIT", # https://tldrlegal.com/license/mit-license
"MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11
"OpenSSL", # https://www.openssl.org/source/license.html
"Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib)
]
[[licenses.clarify]]
name = "webpki"
expression = "ISC"
license-files = [
{ path = "LICENSE", hash = 0x001c7e6c }
]
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
[[licenses.clarify]]
name = "ring"
expression = "MIT AND ISC AND OpenSSL"
license-files = [
{ path = "LICENSE", hash = 0xbd0eed23 }
]
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]

6
egui-winit/Cargo.toml

@ -22,7 +22,7 @@ default = ["clipboard", "dark-light", "links"]
# enable cut/copy/paste to OS clipboard.
# if disabled a clipboard will be simulated so you can still copy/paste within the egui app.
clipboard = ["copypasta"]
clipboard = ["arboard"]
# implement bytemuck on most types.
bytemuck = ["egui/bytemuck"]
@ -51,8 +51,8 @@ winit = "0.26.1"
# Optional:
epi = { version = "0.17.0", path = "../epi", optional = true }
copypasta = { version = "0.7", optional = true }
dark-light = { version = "0.2.1", optional = true } # detect dark mode system preference
arboard = { version = "2.1", optional = true, default-features = false }
dark-light = { version = "0.2.1", optional = true } # detect dark mode system preference
glow = { version = "0.11", optional = true }
serde = { version = "1.0", optional = true, features = ["derive"] }
webbrowser = { version = "0.6", optional = true }

38
egui-winit/src/clipboard.rs

@ -1,21 +1,21 @@
/// Handles interfacing either with the OS clipboard.
/// If the "clipboard" feature is off it will instead simulate the clipboard locally.
pub struct Clipboard {
#[cfg(feature = "copypasta")]
copypasta: Option<copypasta::ClipboardContext>,
#[cfg(feature = "arboard")]
arboard: Option<arboard::Clipboard>,
/// Fallback manual clipboard.
#[cfg(not(feature = "copypasta"))]
#[cfg(not(feature = "arboard"))]
clipboard: String,
}
impl Default for Clipboard {
fn default() -> Self {
Self {
#[cfg(feature = "copypasta")]
copypasta: init_copypasta(),
#[cfg(feature = "arboard")]
arboard: init_arboard(),
#[cfg(not(feature = "copypasta"))]
#[cfg(not(feature = "arboard"))]
clipboard: String::default(),
}
}
@ -23,11 +23,10 @@ impl Default for Clipboard {
impl Clipboard {
pub fn get(&mut self) -> Option<String> {
#[cfg(feature = "copypasta")]
if let Some(clipboard) = &mut self.copypasta {
use copypasta::ClipboardProvider as _;
match clipboard.get_contents() {
Ok(contents) => Some(contents),
#[cfg(feature = "arboard")]
if let Some(clipboard) = &mut self.arboard {
match clipboard.get_text() {
Ok(text) => Some(text),
Err(err) => {
tracing::error!("Paste error: {}", err);
None
@ -37,29 +36,28 @@ impl Clipboard {
None
}
#[cfg(not(feature = "copypasta"))]
#[cfg(not(feature = "arboard"))]
Some(self.clipboard.clone())
}
pub fn set(&mut self, text: String) {
#[cfg(feature = "copypasta")]
if let Some(clipboard) = &mut self.copypasta {
use copypasta::ClipboardProvider as _;
if let Err(err) = clipboard.set_contents(text) {
#[cfg(feature = "arboard")]
if let Some(clipboard) = &mut self.arboard {
if let Err(err) = clipboard.set_text(text) {
tracing::error!("Copy/Cut error: {}", err);
}
}
#[cfg(not(feature = "copypasta"))]
#[cfg(not(feature = "arboard"))]
{
self.clipboard = text;
}
}
}
#[cfg(feature = "copypasta")]
fn init_copypasta() -> Option<copypasta::ClipboardContext> {
match copypasta::ClipboardContext::new() {
#[cfg(feature = "arboard")]
fn init_arboard() -> Option<arboard::Clipboard> {
match arboard::Clipboard::new() {
Ok(clipboard) => Some(clipboard),
Err(err) => {
tracing::error!("Failed to initialize clipboard: {}", err);

Loading…
Cancel
Save