Skip to content

Commit f472bbc

Browse files
ColinKinlochtorokati44
authored andcommitted
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.
1 parent 8d193f8 commit f472bbc

File tree

3 files changed

+19
-124
lines changed

3 files changed

+19
-124
lines changed

Cargo.lock

Lines changed: 4 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ slotmap = { workspace = true }
3030
winit = "0.29.15"
3131
webbrowser = "0.8.13"
3232
url = "2.5.0"
33-
arboard = { version = "3.3.2", features = ["wayland-data-control"] }
3433
dirs = "5.0"
3534
isahc = { version = "1.7.2", features = ["cookies"] }
3635
rfd = "0.14.0"

desktop/src/backends/ui.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::preferences::GlobalPreferences;
22
use anyhow::Error;
3-
use arboard::Clipboard;
43
use chrono::{DateTime, Utc};
4+
use egui_winit::clipboard::Clipboard;
55
use fontdb::Family;
66
use rfd::{
77
AsyncFileDialog, FileHandle, MessageButtons, MessageDialog, MessageDialogResult, MessageLevel,
@@ -14,6 +14,7 @@ use ruffle_core::backend::ui::{
1414
use std::rc::Rc;
1515
use tracing::error;
1616
use url::Url;
17+
use winit::raw_window_handle::HasDisplayHandle;
1718
use winit::window::{Fullscreen, Window};
1819

1920
pub struct DesktopFileDialogResult {
@@ -117,7 +118,7 @@ impl FileDialogResult for DesktopFileDialogResult {
117118
pub struct DesktopUiBackend {
118119
window: Rc<Window>,
119120
cursor_visible: bool,
120-
clipboard: Option<Clipboard>,
121+
clipboard: Clipboard,
121122
preferences: GlobalPreferences,
122123
preferred_cursor: MouseCursor,
123124
open_url_mode: OpenURLMode,
@@ -133,12 +134,19 @@ impl DesktopUiBackend {
133134
font_database: Rc<fontdb::Database>,
134135
preferences: GlobalPreferences,
135136
) -> Result<Self, Error> {
137+
// The window handle is only relevant to linux/wayland
138+
// If it fails it'll fallback to x11 or wlr-data-control
139+
let clipboard = Clipboard::new(
140+
window
141+
.clone()
142+
.display_handle()
143+
.ok()
144+
.map(|handle| handle.as_raw()),
145+
);
136146
Ok(Self {
137147
window,
138148
cursor_visible: true,
139-
clipboard: Clipboard::new()
140-
.inspect_err(|err| tracing::error!("Failed to initialize clipboard: {err}"))
141-
.ok(),
149+
clipboard,
142150
preferences,
143151
preferred_cursor: MouseCursor::Arrow,
144152
open_url_mode,
@@ -177,19 +185,11 @@ impl UiBackend for DesktopUiBackend {
177185
}
178186

179187
fn clipboard_content(&mut self) -> String {
180-
if let Some(ref mut clipboard) = self.clipboard {
181-
clipboard.get_text().unwrap_or_default()
182-
} else {
183-
"".to_string()
184-
}
188+
self.clipboard.get().unwrap_or_default()
185189
}
186190

187191
fn set_clipboard_content(&mut self, content: String) {
188-
if let Some(ref mut clipboard) = self.clipboard {
189-
if let Err(e) = clipboard.set_text(content) {
190-
error!("Couldn't set clipboard contents: {:?}", e);
191-
}
192-
}
192+
self.clipboard.set(content);
193193
}
194194

195195
fn set_fullscreen(&mut self, is_full: bool) -> Result<(), FullscreenError> {

0 commit comments

Comments
 (0)