Skip to content

desktop: Use egui-winit clipboard #15566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 4 additions & 108 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions desktop/src/backends/ui.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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> {
Expand Down