desktop: Use egui-winit clipboard

The `egui-winit` clipboard implementation provides a nice interface to
`smithay-clipboard` which correctly implements the core wayland
selection protocol. It uses `arboard` as a fallback for other platforms.
This commit is contained in:
Colin Kinloch 2024-03-13 20:46:40 +00:00 committed by TÖRÖK Attila
parent 8d193f8944
commit f472bbc701
3 changed files with 19 additions and 124 deletions

112
Cargo.lock generated
View File

@ -211,16 +211,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2041f1943049c7978768d84e6d0fd95de98b76d6c4727b09e78ec253d29fa58"
dependencies = [
"clipboard-win",
"core-graphics",
"image",
"log",
"objc",
"objc-foundation",
"objc_id",
"parking_lot",
"thiserror",
"windows-sys 0.48.0",
"wl-clipboard-rs",
"x11rb",
]
@ -633,12 +629,6 @@ version = "3.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b"
[[package]]
name = "bytecount"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205"
[[package]]
name = "bytemuck"
version = "1.14.3"
@ -1388,17 +1378,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "derive-new"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "diff"
version = "0.1.13"
@ -1848,12 +1827,6 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flash-lso"
version = "0.6.0"
@ -2277,7 +2250,7 @@ dependencies = [
"libc",
"libudev-sys",
"log",
"nix 0.28.0",
"nix",
"uuid",
"vec_map",
"wasm-bindgen",
@ -3176,15 +3149,6 @@ dependencies = [
"libc",
]
[[package]]
name = "memoffset"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [
"autocfg",
]
[[package]]
name = "memoffset"
version = "0.9.0"
@ -3379,19 +3343,6 @@ dependencies = [
"nihav_core",
]
[[package]]
name = "nix"
version = "0.26.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"libc",
"memoffset 0.7.1",
"pin-utils",
]
[[package]]
name = "nix"
version = "0.28.0"
@ -3402,7 +3353,7 @@ dependencies = [
"cfg-if",
"cfg_aliases",
"libc",
"memoffset 0.9.0",
"memoffset",
]
[[package]]
@ -3685,16 +3636,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "os_pipe"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]]
name = "overload"
version = "0.1.1"
@ -3757,16 +3698,6 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "petgraph"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]]
name = "pin-project"
version = "1.1.4"
@ -4286,7 +4217,6 @@ name = "ruffle_desktop"
version = "0.1.0"
dependencies = [
"anyhow",
"arboard",
"async-channel 2.2.0",
"async-io",
"async-net",
@ -5522,20 +5452,6 @@ dependencies = [
"strength_reduce",
]
[[package]]
name = "tree_magic_mini"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91adfd0607cacf6e4babdb870e9bec4037c1c4b151cfd279ccefc5e0c7feaa6d"
dependencies = [
"bytecount",
"fnv",
"lazy_static",
"nom",
"once_cell",
"petgraph",
]
[[package]]
name = "ttf-parser"
version = "0.20.0"
@ -5572,7 +5488,7 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9"
dependencies = [
"memoffset 0.9.0",
"memoffset",
"tempfile",
"winapi",
]
@ -6581,26 +6497,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "wl-clipboard-rs"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57af79e973eadf08627115c73847392e6b766856ab8e3844a59245354b23d2fa"
dependencies = [
"derive-new",
"libc",
"log",
"nix 0.26.4",
"os_pipe",
"tempfile",
"thiserror",
"tree_magic_mini",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols-wlr",
]
[[package]]
name = "x11-dl"
version = "2.21.0"
@ -6712,7 +6608,7 @@ dependencies = [
"futures-sink",
"futures-util",
"hex",
"nix 0.28.0",
"nix",
"ordered-stream",
"rand",
"serde",

View File

@ -30,7 +30,6 @@ slotmap = { workspace = true }
winit = "0.29.15"
webbrowser = "0.8.13"
url = "2.5.0"
arboard = { version = "3.3.2", features = ["wayland-data-control"] }
dirs = "5.0"
isahc = { version = "1.7.2", features = ["cookies"] }
rfd = "0.14.0"

View File

@ -1,7 +1,7 @@
use crate::preferences::GlobalPreferences;
use anyhow::Error;
use arboard::Clipboard;
use chrono::{DateTime, Utc};
use egui_winit::clipboard::Clipboard;
use fontdb::Family;
use rfd::{
AsyncFileDialog, FileHandle, MessageButtons, MessageDialog, MessageDialogResult, MessageLevel,
@ -14,6 +14,7 @@ use ruffle_core::backend::ui::{
use std::rc::Rc;
use tracing::error;
use url::Url;
use winit::raw_window_handle::HasDisplayHandle;
use winit::window::{Fullscreen, Window};
pub struct DesktopFileDialogResult {
@ -117,7 +118,7 @@ impl FileDialogResult for DesktopFileDialogResult {
pub struct DesktopUiBackend {
window: Rc<Window>,
cursor_visible: bool,
clipboard: Option<Clipboard>,
clipboard: Clipboard,
preferences: GlobalPreferences,
preferred_cursor: MouseCursor,
open_url_mode: OpenURLMode,
@ -133,12 +134,19 @@ impl DesktopUiBackend {
font_database: Rc<fontdb::Database>,
preferences: GlobalPreferences,
) -> Result<Self, Error> {
// The window handle is only relevant to linux/wayland
// If it fails it'll fallback to x11 or wlr-data-control
let clipboard = Clipboard::new(
window
.clone()
.display_handle()
.ok()
.map(|handle| handle.as_raw()),
);
Ok(Self {
window,
cursor_visible: true,
clipboard: Clipboard::new()
.inspect_err(|err| tracing::error!("Failed to initialize clipboard: {err}"))
.ok(),
clipboard,
preferences,
preferred_cursor: MouseCursor::Arrow,
open_url_mode,
@ -177,19 +185,11 @@ impl UiBackend for DesktopUiBackend {
}
fn clipboard_content(&mut self) -> String {
if let Some(ref mut clipboard) = self.clipboard {
clipboard.get_text().unwrap_or_default()
} else {
"".to_string()
}
self.clipboard.get().unwrap_or_default()
}
fn set_clipboard_content(&mut self, content: String) {
if let Some(ref mut clipboard) = self.clipboard {
if let Err(e) = clipboard.set_text(content) {
error!("Couldn't set clipboard contents: {:?}", e);
}
}
self.clipboard.set(content);
}
fn set_fullscreen(&mut self, is_full: bool) -> Result<(), FullscreenError> {