Skip to content
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

Fix build for iOS #717

Merged
merged 1 commit into from
Jan 2, 2025
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")]
Expand Down
51 changes: 29 additions & 22 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -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<Option<Clipboard>> = Mutex::new(None);
Expand Down Expand Up @@ -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::<Primary>::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::<X11SelectionClipboard>::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,
Expand Down
2 changes: 1 addition & 1 deletion src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions src/menu.rs
Original file line number Diff line number Diff line change
@@ -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`]).
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
23 changes: 13 additions & 10 deletions src/window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading