diff --git a/internal/backends/winit/Cargo.toml b/internal/backends/winit/Cargo.toml index 17a2e454ae7..482b1b4cb23 100644 --- a/internal/backends/winit/Cargo.toml +++ b/internal/backends/winit/Cargo.toml @@ -38,7 +38,6 @@ const-field-offset = { version = "0.1", path = "../../../helper_crates/const-fie vtable = { version = "0.1.6", path = "../../../helper_crates/vtable" } cfg-if = "1" -copypasta = { version = "0.10", default-features = false } derive_more = "0.99.5" lyon_path = "1.0" once_cell = "1.5" @@ -69,6 +68,7 @@ glutin = { workspace = true, optional = true, default-features = false, features glutin-winit = { version = "0.4.2", optional = true, default-features = false, features = ["egl", "wgl"] } accesskit = { version = "0.12.2", optional = true } accesskit_winit = { version = "0.18.0", optional = true } +copypasta = { version = "0.10", default-features = false } [target.'cfg(target_os = "macos")'.dependencies] # For GL rendering diff --git a/internal/backends/winit/event_loop.rs b/internal/backends/winit/event_loop.rs index 3422a49b73f..ea8dd0ff8af 100644 --- a/internal/backends/winit/event_loop.rs +++ b/internal/backends/winit/event_loop.rs @@ -9,6 +9,7 @@ */ use crate::winitwindowadapter::WinitWindowAdapter; use crate::SlintUserEvent; +#[cfg(not(target_arch = "wasm32"))] use copypasta::ClipboardProvider; use corelib::api::EventLoopError; use corelib::graphics::euclid; @@ -18,15 +19,18 @@ use corelib::lengths::LogicalPoint; use corelib::platform::PlatformError; use corelib::window::*; use i_slint_core as corelib; +#[allow(unused_imports)] use std::cell::{RefCell, RefMut}; use std::rc::{Rc, Weak}; use winit::event::{Event, WindowEvent}; use winit::event_loop::EventLoopWindowTarget; +#[cfg(not(target_arch = "wasm32"))] /// The Default, and the selection clippoard type ClipboardPair = (Box, Box); struct NotRunningEventLoop { + #[cfg(not(target_arch = "wasm32"))] clipboard: RefCell, instance: winit::event_loop::EventLoop, event_loop_proxy: winit::event_loop::EventLoopProxy, @@ -58,20 +62,24 @@ impl NotRunningEventLoop { let instance = builder.build().map_err(|e| format!("Error initializing winit event loop: {e}"))?; let event_loop_proxy = instance.create_proxy(); - let clipboard = RefCell::new(create_clipboard(&instance)); - Ok(Self { clipboard, instance, event_loop_proxy }) + Ok(Self { + #[cfg(not(target_arch = "wasm32"))] + clipboard: RefCell::new(create_clipboard(&instance)), + instance, + event_loop_proxy, + }) } } struct RunningEventLoop<'a> { event_loop_target: &'a winit::event_loop::EventLoopWindowTarget, - event_loop_proxy: &'a winit::event_loop::EventLoopProxy, + #[cfg(not(target_arch = "wasm32"))] clipboard: &'a RefCell, } pub(crate) trait EventLoopInterface { fn event_loop_target(&self) -> &winit::event_loop::EventLoopWindowTarget; - fn event_loop_proxy(&self) -> &winit::event_loop::EventLoopProxy; + #[cfg(not(target_arch = "wasm32"))] fn clipboard( &self, _: i_slint_core::platform::Clipboard, @@ -83,10 +91,7 @@ impl EventLoopInterface for NotRunningEventLoop { &self.instance } - fn event_loop_proxy(&self) -> &winit::event_loop::EventLoopProxy { - &self.event_loop_proxy - } - + #[cfg(not(target_arch = "wasm32"))] fn clipboard( &self, clipboard: i_slint_core::platform::Clipboard, @@ -108,10 +113,7 @@ impl<'a> EventLoopInterface for RunningEventLoop<'a> { self.event_loop_target } - fn event_loop_proxy(&self) -> &winit::event_loop::EventLoopProxy { - self.event_loop_proxy - } - + #[cfg(not(target_arch = "wasm32"))] fn clipboard( &self, clipboard: i_slint_core::platform::Clipboard, @@ -524,18 +526,17 @@ impl EventLoopState { }); let mut winit_loop = not_running_loop_instance.instance; - let clipboard = not_running_loop_instance.clipboard; #[cfg(not(target_arch = "wasm32"))] { use winit::platform::run_on_demand::EventLoopExtRunOnDemand as _; + let clipboard = not_running_loop_instance.clipboard; winit_loop .run_on_demand( |event: Event, event_loop_target: &EventLoopWindowTarget| { let running_instance = RunningEventLoop { event_loop_target, - event_loop_proxy: &event_loop_proxy, clipboard: &clipboard, }; CURRENT_WINDOW_TARGET.set(&running_instance, || { @@ -566,8 +567,6 @@ impl EventLoopState { event_loop_target: &EventLoopWindowTarget| { let running_instance = RunningEventLoop { event_loop_target, - event_loop_proxy: &event_loop_proxy, - clipboard: &clipboard, }; CURRENT_WINDOW_TARGET.set(&running_instance, || { self.process_event(event, event_loop_target) @@ -611,11 +610,8 @@ impl EventLoopState { timeout, |event: Event, event_loop_target: &EventLoopWindowTarget| { - let running_instance = RunningEventLoop { - event_loop_target, - event_loop_proxy: &event_loop_proxy, - clipboard: &clipboard, - }; + let running_instance = + RunningEventLoop { event_loop_target, clipboard: &clipboard }; CURRENT_WINDOW_TARGET .set(&running_instance, || self.process_event(event, event_loop_target)) }, @@ -653,17 +649,12 @@ pub fn spawn() -> Result<(), corelib::platform::PlatformError> { .set_proxy(event_loop_proxy.clone()) }); - let clipboard = not_running_loop_instance.clipboard; let mut loop_state = EventLoopState::default(); not_running_loop_instance.instance.spawn( move |event: Event, event_loop_target: &EventLoopWindowTarget| { - let running_instance = RunningEventLoop { - event_loop_target, - event_loop_proxy: &event_loop_proxy, - clipboard: &clipboard, - }; + let running_instance = RunningEventLoop { event_loop_target }; CURRENT_WINDOW_TARGET .set(&running_instance, || loop_state.process_event(event, event_loop_target)) }, @@ -672,6 +663,7 @@ pub fn spawn() -> Result<(), corelib::platform::PlatformError> { Ok(()) } +#[cfg(not(target_arch = "wasm32"))] fn create_clipboard(_event_loop: &winit::event_loop::EventLoopWindowTarget) -> ClipboardPair { // Provide a truly silent no-op clipboard context, as copypasta's NoopClipboard spams stdout with // println.