From febc1c33c74eab23888b7db8b4781ab8353dfe20 Mon Sep 17 00:00:00 2001 From: Manuel Adameit Date: Mon, 30 Dec 2024 00:40:47 +0100 Subject: [PATCH] Fix build for iOS --- Cargo.toml | 6 ++++-- src/app_handle.rs | 6 +++--- src/clipboard.rs | 51 +++++++++++++++++++++++++------------------- src/keyboard.rs | 2 +- src/menu.rs | 8 +++---- src/window_handle.rs | 23 +++++++++++--------- 6 files changed, 54 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fbb24fe1..bc87c0e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ wgpu = { version = "22.0.0" } parking_lot = { version = "0.12.1" } swash = { version = "0.1.17" } muda = { version = "0.15.3" } -winit = { git = "https://github.com/rust-windowing/winit", rev = "fc6cf89ac0674c64320024f800a41ffb365dab97" } +winit = { git = "https://github.com/rust-windowing/winit", rev = "5ea81efc74ebaa04a7cb4621ec522bce14d700e5" } [dependencies] slotmap = "1.0.7" @@ -80,11 +80,13 @@ parking_lot = { workspace = true } image = { workspace = true } im = { workspace = true } wgpu = { workspace = true } -muda = { workspace = true } winit = { workspace = true } futures = { version = "0.3.30", optional = true } crossbeam = "0.8" +[target.'cfg(not(any(target_os = "ios", target_os = "android")))'.dependencies] +muda = { workspace = true } + [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-futures = { version = "0.4" } web-time = "1" diff --git a/src/app_handle.rs b/src/app_handle.rs index 6e88e748..a7b1a0a4 100644 --- a/src/app_handle.rs +++ b/src/app_handle.rs @@ -314,7 +314,7 @@ impl ApplicationHandle { canvas.set_height(size.height as u32); } - window_builder = window_builder.with_canvas(Some(canvas)); + window_attributes = window_attributes.with_canvas(Some(canvas)); }; if let Some(Point { x, y }) = position { @@ -327,13 +327,13 @@ impl ApplicationHandle { #[cfg(not(target_os = "macos"))] if !show_titlebar { - window_builder = window_builder.with_decorations(false); + window_attributes = window_attributes.with_decorations(false); } #[cfg(target_os = "windows")] { use floem_winit::platform::windows::WindowBuilderExtWindows; - window_builder = window_builder.with_undecorated_shadow(undecorated_shadow); + window_attributes = window_attributes.with_undecorated_shadow(undecorated_shadow); } #[cfg(target_os = "macos")] diff --git a/src/clipboard.rs b/src/clipboard.rs index 9d0ffe72..b3bb7374 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -1,12 +1,6 @@ use parking_lot::Mutex; use raw_window_handle::RawDisplayHandle; -#[cfg(not(any(target_os = "macos", windows, target_arch = "wasm32")))] -use copypasta::{ - wayland_clipboard, - x11_clipboard::{Primary as X11SelectionClipboard, X11ClipboardContext}, -}; - use copypasta::{ClipboardContext, ClipboardProvider}; static CLIPBOARD: Mutex> = Mutex::new(None); @@ -65,26 +59,39 @@ impl Clipboard { unsafe fn new( #[allow(unused_variables)] /* on some platforms */ display: RawDisplayHandle, ) -> Self { - #[cfg(not(any(target_os = "macos", windows, target_arch = "wasm32")))] - if let RawDisplayHandle::Wayland(display) = display { - let (selection, clipboard) = - wayland_clipboard::create_clipboards_from_external(display.display.as_ptr()); + #[cfg(not(any( + target_os = "macos", + target_os = "windows", + target_os = "ios", + target_os = "android", + target_arch = "wasm32" + )))] + { + if let RawDisplayHandle::Wayland(display) = display { + use copypasta::wayland_clipboard; + let (selection, clipboard) = + wayland_clipboard::create_clipboards_from_external(display.display.as_ptr()); + return Self { + clipboard: Box::new(clipboard), + selection: Some(Box::new(selection)), + }; + } + + use copypasta::x11_clipboard::{Primary, X11ClipboardContext}; return Self { - clipboard: Box::new(clipboard), - selection: Some(Box::new(selection)), + clipboard: Box::new(ClipboardContext::new().unwrap()), + selection: Some(Box::new(X11ClipboardContext::::new().unwrap())), }; } - #[cfg(not(any(target_os = "macos", windows, target_arch = "wasm32")))] - return Self { - clipboard: Box::new(ClipboardContext::new().unwrap()), - selection: Some(Box::new( - X11ClipboardContext::::new().unwrap(), - )), - }; - - // TODO: Implement clipboard support for the web - #[cfg(any(target_os = "macos", windows, target_arch = "wasm32"))] + // TODO: Implement clipboard support for the web, ios, and android + #[cfg(any( + target_os = "macos", + target_os = "windows", + target_os = "ios", + target_os = "android", + target_arch = "wasm32" + ))] return Self { clipboard: Box::new(ClipboardContext::new().unwrap()), selection: None, diff --git a/src/keyboard.rs b/src/keyboard.rs index 8ca9496f..b48cefd8 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -2,7 +2,7 @@ use bitflags::bitflags; pub use winit::keyboard::{ Key, KeyCode, KeyLocation, ModifiersState, NamedKey, NativeKey, PhysicalKey, }; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "android")))] pub use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; #[derive(Debug, Clone, Eq, PartialEq, Hash)] diff --git a/src/menu.rs b/src/menu.rs index 4a49ff9f..c04236ed 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -1,7 +1,5 @@ use std::sync::atomic::AtomicU64; -use muda::PredefinedMenuItem; - /// An entry in a menu. /// /// An entry is either a [`MenuItem`], a submenu (i.e. [`Menu`]). @@ -48,12 +46,13 @@ impl Menu { self.entry(MenuEntry::Separator) } + #[cfg(not(any(target_os = "ios", target_os = "android")))] pub(crate) fn platform_menu(&self) -> muda::Menu { let menu = muda::Menu::new(); for entry in &self.children { match entry { MenuEntry::Separator => { - menu.append(&PredefinedMenuItem::separator()); + menu.append(&muda::PredefinedMenuItem::separator()); } MenuEntry::Item(item) => { menu.append(&muda::MenuItem::with_id( @@ -71,12 +70,13 @@ impl Menu { menu } + #[cfg(not(any(target_os = "ios", target_os = "android")))] pub(crate) fn platform_submenu(&self) -> muda::Submenu { let menu = muda::Submenu::new(self.item.title.clone(), self.item.enabled); for entry in &self.children { match entry { MenuEntry::Separator => { - menu.append(&PredefinedMenuItem::separator()); + menu.append(&muda::PredefinedMenuItem::separator()); } MenuEntry::Item(item) => { menu.append(&muda::MenuItem::with_id( diff --git a/src/window_handle.rs b/src/window_handle.rs index 24b4d24d..34f9d00a 100644 --- a/src/window_handle.rs +++ b/src/window_handle.rs @@ -948,16 +948,19 @@ impl WindowHandle { self.paint_state.set_scale(scale); } UpdateMessage::ShowContextMenu { menu, pos } => { - let mut menu = menu.popup(); - let platform_menu = menu.platform_menu(); - cx.app_state.context_menu.clear(); - cx.app_state.update_context_menu(&mut menu); - #[cfg(target_os = "macos")] - self.show_context_menu(platform_menu, pos); - #[cfg(target_os = "windows")] - self.show_context_menu(platform_menu, pos); - #[cfg(any(target_os = "linux", target_os = "freebsd"))] - self.show_context_menu(menu, platform_menu, pos); + #[cfg(not(any(target_os = "ios", target_os = "android")))] + { + let mut menu = menu.popup(); + let platform_menu = menu.platform_menu(); + cx.app_state.context_menu.clear(); + cx.app_state.update_context_menu(&mut menu); + #[cfg(target_os = "macos")] + self.show_context_menu(platform_menu, pos); + #[cfg(target_os = "windows")] + self.show_context_menu(platform_menu, pos); + #[cfg(any(target_os = "linux", target_os = "freebsd"))] + self.show_context_menu(menu, platform_menu, pos); + } } UpdateMessage::WindowMenu { menu } => { // let platform_menu = menu.platform_menu();