From 13c686b671eb8d3f890cace9700fceb3b4f538eb Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 19 May 2019 13:31:03 -0700 Subject: [PATCH 1/2] Add wasm32 platform reusing emscripten implementation for eventloop-2.0 https://github.com/iceiix/winit/pull/2 for https://github.com/rust-windowing/winit/blob/eventloop-2.0/ --- src/platform_impl/emscripten/mod.rs | 2 +- src/platform_impl/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index 95baa7f8e4..4786dc0388 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -1,4 +1,4 @@ -#![cfg(target_os = "emscripten")] +#![cfg(any(target_os = "emscripten", target_arch = "wasm32"))] mod ffi; diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index be96878500..367bb61c93 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -15,12 +15,13 @@ mod platform; #[cfg(target_os = "ios")] #[path="ios/mod.rs"] mod platform; -#[cfg(target_os = "emscripten")] +#[cfg(any(target_os = "emscripten", target_arch = "wasm32"))] #[path="emscripten/mod.rs"] mod platform; #[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"), not(target_os = "freebsd"), not(target_os = "netbsd"), not(target_os = "openbsd"), + not(target_arch = "wasm32"), not(target_os = "emscripten")))] compile_error!("The platform you're compiling for is not supported by winit"); From 22af63afc1713fdfff2855bbdfdd101235d60c9a Mon Sep 17 00:00:00 2001 From: ice_iix Date: Sun, 19 May 2019 15:46:23 -0700 Subject: [PATCH 2/2] Add new wasm32 backend completely unimplemented to fix compilation --- src/platform_impl/emscripten/mod.rs | 2 +- src/platform_impl/mod.rs | 6 +- src/platform_impl/wasm32/mod.rs | 280 ++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 src/platform_impl/wasm32/mod.rs diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs index 4786dc0388..95baa7f8e4 100644 --- a/src/platform_impl/emscripten/mod.rs +++ b/src/platform_impl/emscripten/mod.rs @@ -1,4 +1,4 @@ -#![cfg(any(target_os = "emscripten", target_arch = "wasm32"))] +#![cfg(target_os = "emscripten")] mod ffi; diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index 367bb61c93..0ce796a803 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -15,9 +15,13 @@ mod platform; #[cfg(target_os = "ios")] #[path="ios/mod.rs"] mod platform; -#[cfg(any(target_os = "emscripten", target_arch = "wasm32"))] +#[cfg(target_os = "emscripten")] #[path="emscripten/mod.rs"] mod platform; +#[cfg(target_arch = "wasm32")] +#[path="wasm32/mod.rs"] +mod platform; + #[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"), diff --git a/src/platform_impl/wasm32/mod.rs b/src/platform_impl/wasm32/mod.rs new file mode 100644 index 0000000000..dbf98a2097 --- /dev/null +++ b/src/platform_impl/wasm32/mod.rs @@ -0,0 +1,280 @@ +#![cfg(target_arch = "wasm32")] +#![allow(dead_code, unused_variables)] + +use std::collections::VecDeque; + +use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; +use icon::Icon; +//use event::Event; +use event_loop::{EventLoopClosed, ControlFlow, EventLoopWindowTarget as RootELW}; +use monitor::MonitorHandle as RootMonitorHandle; +use window::{WindowAttributes, CreationError, MouseCursor}; + +#[derive(Clone, Default)] +pub struct PlatformSpecificWindowBuilderAttributes { +} + +pub enum Window { +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum WindowId { +} + +impl WindowId { + pub unsafe fn dummy() -> Self { + unimplemented!() + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum DeviceId { +} + +impl DeviceId { + pub unsafe fn dummy() -> Self { + unimplemented!() + } +} + +#[derive(Debug, Clone)] +pub enum MonitorHandle { +} + +impl MonitorHandle { + #[inline] + pub fn get_name(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn get_native_identifier(&self) -> u32 { + unimplemented!() + } + + #[inline] + pub fn get_dimensions(&self) -> PhysicalSize { + unimplemented!() + } + + #[inline] + pub fn get_position(&self) -> PhysicalPosition { + unimplemented!() + } + + #[inline] + pub fn get_hidpi_factor(&self) -> f64 { + unimplemented!() + } +} + +impl Window { + #[inline] + pub fn new( + window_target: &EventLoopWindowTarget, + attribs: WindowAttributes, + pl_attribs: PlatformSpecificWindowBuilderAttributes, + ) -> Result { + unimplemented!() + } + + #[inline] + pub fn id(&self) -> WindowId { + unimplemented!() + } + + #[inline] + pub fn set_title(&self, title: &str) { + unimplemented!() + } + + #[inline] + pub fn show(&self) { + unimplemented!() + } + + #[inline] + pub fn hide(&self) { + unimplemented!() + } + + #[inline] + pub fn get_position(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn get_inner_position(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn set_position(&self, position: LogicalPosition) { + unimplemented!() + } + + #[inline] + pub fn get_inner_size(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn get_outer_size(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn set_inner_size(&self, size: LogicalSize) { + unimplemented!() + } + + #[inline] + pub fn set_min_dimensions(&self, dimensions: Option) { + unimplemented!() + } + + #[inline] + pub fn set_max_dimensions(&self, dimensions: Option) { + unimplemented!() + } + + #[inline] + pub fn set_resizable(&self, resizable: bool) { + unimplemented!() + } + + #[inline] + pub fn set_cursor(&self, cursor: MouseCursor) { + unimplemented!() + } + + #[inline] + pub fn grab_cursor(&self, grab: bool) -> Result<(), String> { + unimplemented!() + } + + #[inline] + pub fn hide_cursor(&self, hide: bool) { + unimplemented!() + } + + #[inline] + pub fn get_hidpi_factor(&self) -> f64 { + unimplemented!() + } + + #[inline] + pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), String> { + unimplemented!() + } + + #[inline] + pub fn set_maximized(&self, maximized: bool) { + } + + #[inline] + pub fn get_fullscreen(&self) -> Option { + unimplemented!() + } + + #[inline] + pub fn set_fullscreen(&self, monitor: Option) { + unimplemented!() + } + + #[inline] + pub fn set_decorations(&self, decorations: bool) { + unimplemented!() + } + + #[inline] + pub fn set_always_on_top(&self, always_on_top: bool) { + unimplemented!() + } + + #[inline] + pub fn set_window_icon(&self, window_icon: Option) { + unimplemented!() + } + + #[inline] + pub fn set_ime_spot(&self, position: LogicalPosition) { + unimplemented!() + } + + #[inline] + pub fn request_redraw(&self) { + unimplemented!() + } + + #[inline] + pub fn get_current_monitor(&self) -> RootMonitorHandle { + unimplemented!() + } + + #[inline] + pub fn get_available_monitors(&self) -> VecDeque { + unimplemented!() + } + + #[inline] + pub fn get_primary_monitor(&self) -> MonitorHandle { + unimplemented!() + } +} + + +pub enum EventLoop { + TODO(T) +} + +#[derive(Clone)] +pub enum EventLoopProxy { + TODO(T) +} + +impl EventLoop { + pub fn new() -> EventLoop { + unimplemented!() + } + + #[inline] + pub fn get_available_monitors(&self) -> VecDeque { + unimplemented!() + } + + #[inline] + pub fn get_primary_monitor(&self) -> MonitorHandle { + unimplemented!() + } + + pub fn create_proxy(&self) -> EventLoopProxy { + unimplemented!() + } + + pub fn run_return(&mut self, callback: F) + where F: FnMut(::event::Event, &RootELW, &mut ControlFlow) + { + unimplemented!() + } + + pub fn run(self, callback: F) -> ! + where F: 'static + FnMut(::event::Event, &RootELW, &mut ControlFlow) + { + unimplemented!() + } + + pub fn window_target(&self) -> &::event_loop::EventLoopWindowTarget { + unimplemented!() + } +} + +impl EventLoopProxy { + pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> { + unimplemented!() + } +} + +pub enum EventLoopWindowTarget { + TODO(T) +}