From 57a53bda74fa9a46e7e282d0f857d02048e64353 Mon Sep 17 00:00:00 2001 From: Osspial Date: Fri, 13 Sep 2019 19:09:45 -0400 Subject: [PATCH] Officially remove the Emscripten backend (#1159) --- CHANGELOG.md | 1 + FEATURES.md | 69 +- README.md | 2 +- examples/window_run_return.rs | 2 +- src/platform_impl/emscripten/ffi.rs | 363 -------- src/platform_impl/emscripten/mod.rs | 1246 --------------------------- src/platform_impl/mod.rs | 4 - 7 files changed, 37 insertions(+), 1650 deletions(-) delete mode 100644 src/platform_impl/emscripten/ffi.rs delete mode 100644 src/platform_impl/emscripten/mod.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 90cb469e..de34b407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - On Windows, add touch pressure information for touch events. - On macOS, differentiate between `CursorIcon::Grab` and `CursorIcon::Grabbing`. - On Wayland, fix event processing sometimes stalling when using OpenGL with vsync. +- Officially remove the Emscripten backend # 0.20.0 Alpha 3 (2019-08-14) diff --git a/FEATURES.md b/FEATURES.md index cd3712b9..9610b7ba 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -12,7 +12,6 @@ be used to create both games and applications. It supports the main graphical pl - iOS - Android - Web - - via Emscripten - via WASM Most platforms expose capabilities that cannot be meaningfully transposed onto others. Winit does not @@ -162,57 +161,57 @@ Legend: - ❓: Unknown status ### Windowing -|Feature |Windows|MacOS |Linux x11 |Linux Wayland |Android|iOS |Emscripten| +|Feature |Windows|MacOS |Linux x11 |Linux Wayland |Android|iOS |WASM | |-------------------------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- | |Window initialization |✔️ |✔️ |▢[#5] |✔️ |▢[#33]|▢[#33] |❓ | |Providing pointer to init OpenGL |✔️ |✔️ |✔️ |✔️ |✔️ |✔️ |❓ | -|Providing pointer to init Vulkan |✔️ |✔️ |✔️ |✔️ |✔️ |❓ |**N/A** | -|Window decorations |✔️ |✔️ |✔️ |▢[#306] |**N/A**|**N/A**|**N/A** | -|Window decorations toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** | +|Providing pointer to init Vulkan |✔️ |✔️ |✔️ |✔️ |✔️ |❓ |❓ | +|Window decorations |✔️ |✔️ |✔️ |▢[#306] |**N/A**|**N/A**|❓ | +|Window decorations toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|❓ | |Window resizing |✔️ |▢[#219]|✔️ |▢[#306] |**N/A**|**N/A**|❓ | -|Window resize increments |❌ |❌ |❌ |❌ |❌ |❌ |❌ | -|Window transparency |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** | -|Window maximization |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** | -|Window maximization toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** | -|Fullscreen |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |❌ | -|Fullscreen toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |❌ | -|Exclusive fullscreen |✔️ |✔️ |✔️ |**N/A** |❌ |✔️ |❌ | -|HiDPI support |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |✔️ | -|Popup windows |❌ |❌ |❌ |❌ |❌ |❌ |❌ | +|Window resize increments |❌ |❌ |❌ |❌ |❌ |❌ |❓ | +|Window transparency |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|❓ | +|Window maximization |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|❓ | +|Window maximization toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|❓ | +|Fullscreen |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |❓ | +|Fullscreen toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |❓ | +|Exclusive fullscreen |✔️ |✔️ |✔️ |**N/A** |❌ |✔️ |❓ | +|HiDPI support |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |❓ | +|Popup windows |❌ |❌ |❌ |❌ |❌ |❌ |❓ | ### System information -|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |Emscripten| -|---------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- | -|Monitor list |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |**N/A** | -|Video mode query |✔️ |✔️ |✔️ |✔️ |❌ |✔️ |❌ | +|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM | +|---------------- | ----- | ---- | ------- | ----------- | ----- | ------- | -------- | +|Monitor list |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |❓ | +|Video mode query |✔️ |✔️ |✔️ |✔️ |❌ |✔️ |❓ | ### Input handling -|Feature |Windows |MacOS |Linux x11|Linux Wayland|Android|iOS |Emscripten| +|Feature |Windows |MacOS |Linux x11|Linux Wayland|Android|iOS |WASM | |----------------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- | -|Mouse events |✔️ |▢[#63] |✔️ |✔️ |**N/A**|**N/A**|✔️ | -|Mouse set location |✔️ |✔️ |✔️ |❓ |**N/A**|**N/A**|**N/A** | -|Cursor grab |✔️ |▢[#165] |▢[#242] |❌[#306] |**N/A**|**N/A**|✔️ | -|Cursor icon |✔️ |✔️ |✔️ |❌[#306] |**N/A**|**N/A**|❌ | -|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |✔️ | -|Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |❌ | -|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |❌ | -|Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |✔️ | +|Mouse events |✔️ |▢[#63] |✔️ |✔️ |**N/A**|**N/A**|❓ | +|Mouse set location |✔️ |✔️ |✔️ |❓ |**N/A**|**N/A**|❓ | +|Cursor grab |✔️ |▢[#165] |▢[#242] |❌[#306] |**N/A**|**N/A**|❓ | +|Cursor icon |✔️ |✔️ |✔️ |❌[#306] |**N/A**|**N/A**|❓ | +|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |❓ | +|Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |❓ | +|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |❓ | +|Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |❓ | |Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ | -|Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❌ | -|Gamepad/Joystick events |❌[#804] |❌ |❌ |❌ |❌ |❌ |❌ | -|Device movement events |❓ |❓ |❓ |❓ |❌ |❌ |❌ | +|Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❓ | +|Gamepad/Joystick events |❌[#804] |❌ |❌ |❌ |❌ |❌ |❓ | +|Device movement events |❓ |❓ |❓ |❓ |❌ |❌ |❓ | ### Pending API Reworks Changes in the API that have been agreed upon but aren't implemented across all platforms. -|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |Emscripten| +|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM | |------------------------------ | ----- | ---- | ------- | ----------- | ----- | ----- | -------- | -|New API for HiDPI ([#315] [#319]) |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |✔️ | -|Event Loop 2.0 ([#459]) |✔️ |✔️ |❌ |✔️ |❌ |✔️ |❌ | -|Keyboard Input ([#812]) |❌ |❌ |❌ |❌ |❌ |❌ |❌ | +|New API for HiDPI ([#315] [#319]) |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |❓ | +|Event Loop 2.0 ([#459]) |✔️ |✔️ |❌ |✔️ |❌ |✔️ |❓ | +|Keyboard Input ([#812]) |❌ |❌ |❌ |❌ |❌ |❌ |❓ | ### Completed API Reworks -|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |Emscripten| +|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM | |------------------------------ | ----- | ---- | ------- | ----------- | ----- | ----- | -------- | [#165]: https://github.com/rust-windowing/winit/issues/165 diff --git a/README.md b/README.md index 3524bfaf..8d685f26 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Winit provides the following features, which can be enabled in your `Cargo.toml` ### Platform-specific usage -#### Emscripten and WebAssembly +#### WebAssembly Building a binary will yield a `.js` file. In order to use it in an HTML file, you need to: diff --git a/examples/window_run_return.rs b/examples/window_run_return.rs index 374703e1..1dd7c5ac 100644 --- a/examples/window_run_return.rs +++ b/examples/window_run_return.rs @@ -50,7 +50,7 @@ fn main() { println!("Okay we're done now for real."); } -#[cfg(any(target_os = "ios", target_os = "android", target_os = "emscripten"))] +#[cfg(any(target_os = "ios", target_os = "android"))] fn main() { println!("This platform doesn't support run_return."); } diff --git a/src/platform_impl/emscripten/ffi.rs b/src/platform_impl/emscripten/ffi.rs deleted file mode 100644 index 6eb9d743..00000000 --- a/src/platform_impl/emscripten/ffi.rs +++ /dev/null @@ -1,363 +0,0 @@ -#![allow(dead_code, non_camel_case_types, non_snake_case)] - -#[cfg(test)] -use std::mem; -use std::os::raw::{c_char, c_double, c_int, c_long, c_ulong, c_ushort, c_void}; - -pub type EM_BOOL = c_int; -pub type EM_UTF8 = c_char; -pub type EMSCRIPTEN_RESULT = c_int; - -pub const EM_TRUE: EM_BOOL = 1; -pub const EM_FALSE: EM_BOOL = 0; - -// values for EMSCRIPTEN_RESULT -pub const EMSCRIPTEN_RESULT_SUCCESS: c_int = 0; -pub const EMSCRIPTEN_RESULT_DEFERRED: c_int = 1; -pub const EMSCRIPTEN_RESULT_NOT_SUPPORTED: c_int = -1; -pub const EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED: c_int = -2; -pub const EMSCRIPTEN_RESULT_INVALID_TARGET: c_int = -3; -pub const EMSCRIPTEN_RESULT_UNKNOWN_TARGET: c_int = -4; -pub const EMSCRIPTEN_RESULT_INVALID_PARAM: c_int = -5; -pub const EMSCRIPTEN_RESULT_FAILED: c_int = -6; -pub const EMSCRIPTEN_RESULT_NO_DATA: c_int = -7; - -// values for EMSCRIPTEN EVENT -pub const EMSCRIPTEN_EVENT_KEYPRESS: c_int = 1; -pub const EMSCRIPTEN_EVENT_KEYDOWN: c_int = 2; -pub const EMSCRIPTEN_EVENT_KEYUP: c_int = 3; -pub const EMSCRIPTEN_EVENT_CLICK: c_int = 4; -pub const EMSCRIPTEN_EVENT_MOUSEDOWN: c_int = 5; -pub const EMSCRIPTEN_EVENT_MOUSEUP: c_int = 6; -pub const EMSCRIPTEN_EVENT_DBLCLICK: c_int = 7; -pub const EMSCRIPTEN_EVENT_MOUSEMOVE: c_int = 8; -pub const EMSCRIPTEN_EVENT_WHEEL: c_int = 9; -pub const EMSCRIPTEN_EVENT_RESIZE: c_int = 10; -pub const EMSCRIPTEN_EVENT_SCROLL: c_int = 11; -pub const EMSCRIPTEN_EVENT_BLUR: c_int = 12; -pub const EMSCRIPTEN_EVENT_FOCUS: c_int = 13; -pub const EMSCRIPTEN_EVENT_FOCUSIN: c_int = 14; -pub const EMSCRIPTEN_EVENT_FOCUSOUT: c_int = 15; -pub const EMSCRIPTEN_EVENT_DEVICEORIENTATION: c_int = 16; -pub const EMSCRIPTEN_EVENT_DEVICEMOTION: c_int = 17; -pub const EMSCRIPTEN_EVENT_ORIENTATIONCHANGE: c_int = 18; -pub const EMSCRIPTEN_EVENT_FULLSCREENCHANGE: c_int = 19; -pub const EMSCRIPTEN_EVENT_POINTERLOCKCHANGE: c_int = 20; -pub const EMSCRIPTEN_EVENT_VISIBILITYCHANGE: c_int = 21; -pub const EMSCRIPTEN_EVENT_TOUCHSTART: c_int = 22; -pub const EMSCRIPTEN_EVENT_TOUCHEND: c_int = 23; -pub const EMSCRIPTEN_EVENT_TOUCHMOVE: c_int = 24; -pub const EMSCRIPTEN_EVENT_TOUCHCANCEL: c_int = 25; -pub const EMSCRIPTEN_EVENT_GAMEPADCONNECTED: c_int = 26; -pub const EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED: c_int = 27; -pub const EMSCRIPTEN_EVENT_BEFOREUNLOAD: c_int = 28; -pub const EMSCRIPTEN_EVENT_BATTERYCHARGINGCHANGE: c_int = 29; -pub const EMSCRIPTEN_EVENT_BATTERYLEVELCHANGE: c_int = 30; -pub const EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST: c_int = 31; -pub const EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED: c_int = 32; -pub const EMSCRIPTEN_EVENT_MOUSEENTER: c_int = 33; -pub const EMSCRIPTEN_EVENT_MOUSELEAVE: c_int = 34; -pub const EMSCRIPTEN_EVENT_MOUSEOVER: c_int = 35; -pub const EMSCRIPTEN_EVENT_MOUSEOUT: c_int = 36; -pub const EMSCRIPTEN_EVENT_CANVASRESIZED: c_int = 37; -pub const EMSCRIPTEN_EVENT_POINTERLOCKERROR: c_int = 38; - -pub const EM_HTML5_SHORT_STRING_LEN_BYTES: usize = 32; - -pub const DOM_KEY_LOCATION_STANDARD: c_ulong = 0x00; -pub const DOM_KEY_LOCATION_LEFT: c_ulong = 0x01; -pub const DOM_KEY_LOCATION_RIGHT: c_ulong = 0x02; -pub const DOM_KEY_LOCATION_NUMPAD: c_ulong = 0x03; - -pub type em_callback_func = Option; - -pub type em_key_callback_func = Option< - unsafe extern "C" fn( - eventType: c_int, - keyEvent: *const EmscriptenKeyboardEvent, - userData: *mut c_void, - ) -> EM_BOOL, ->; - -pub type em_mouse_callback_func = Option< - unsafe extern "C" fn( - eventType: c_int, - mouseEvent: *const EmscriptenMouseEvent, - userData: *mut c_void, - ) -> EM_BOOL, ->; - -pub type em_pointerlockchange_callback_func = Option< - unsafe extern "C" fn( - eventType: c_int, - pointerlockChangeEvent: *const EmscriptenPointerlockChangeEvent, - userData: *mut c_void, - ) -> EM_BOOL, ->; - -pub type em_fullscreenchange_callback_func = Option< - unsafe extern "C" fn( - eventType: c_int, - fullscreenChangeEvent: *const EmscriptenFullscreenChangeEvent, - userData: *mut c_void, - ) -> EM_BOOL, ->; - -pub type em_touch_callback_func = Option< - unsafe extern "C" fn( - eventType: c_int, - touchEvent: *const EmscriptenTouchEvent, - userData: *mut c_void, - ) -> EM_BOOL, ->; - -#[repr(C)] -pub struct EmscriptenFullscreenChangeEvent { - pub isFullscreen: c_int, - pub fullscreenEnabled: c_int, - pub nodeName: [c_char; 128usize], - pub id: [c_char; 128usize], - pub elementWidth: c_int, - pub elementHeight: c_int, - pub screenWidth: c_int, - pub screenHeight: c_int, -} -#[test] -fn bindgen_test_layout_EmscriptenFullscreenChangeEvent() { - assert_eq!(mem::size_of::(), 280usize); - assert_eq!(mem::align_of::(), 4usize); -} - -#[repr(C)] -#[derive(Debug, Copy)] -pub struct EmscriptenKeyboardEvent { - pub key: [c_char; 32usize], - pub code: [c_char; 32usize], - pub location: c_ulong, - pub ctrlKey: c_int, - pub shiftKey: c_int, - pub altKey: c_int, - pub metaKey: c_int, - pub repeat: c_int, - pub locale: [c_char; 32usize], - pub charValue: [c_char; 32usize], - pub charCode: c_ulong, - pub keyCode: c_ulong, - pub which: c_ulong, -} -#[test] -fn bindgen_test_layout_EmscriptenKeyboardEvent() { - assert_eq!(mem::size_of::(), 184usize); - assert_eq!(mem::align_of::(), 8usize); -} -impl Clone for EmscriptenKeyboardEvent { - fn clone(&self) -> Self { - *self - } -} - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct EmscriptenMouseEvent { - pub timestamp: f64, - pub screenX: c_long, - pub screenY: c_long, - pub clientX: c_long, - pub clientY: c_long, - pub ctrlKey: c_int, - pub shiftKey: c_int, - pub altKey: c_int, - pub metaKey: c_int, - pub button: c_ushort, - pub buttons: c_ushort, - pub movementX: c_long, - pub movementY: c_long, - pub targetX: c_long, - pub targetY: c_long, - pub canvasX: c_long, - pub canvasY: c_long, - pub padding: c_long, -} -#[test] -fn bindgen_test_layout_EmscriptenMouseEvent() { - assert_eq!(mem::size_of::(), 120usize); - assert_eq!(mem::align_of::(), 8usize); -} - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct EmscriptenTouchPoint { - pub identifier: c_long, - pub screenX: c_long, - pub screenY: c_long, - pub clientX: c_long, - pub clientY: c_long, - pub pageX: c_long, - pub pageY: c_long, - pub isChanged: c_int, - pub onTarget: c_int, - pub targetX: c_long, - pub targetY: c_long, - pub canvasX: c_long, - pub canvasY: c_long, -} -#[test] -fn bindgen_test_layout_EmscriptenTouchPoint() { - assert_eq!(mem::size_of::(), 96usize); - assert_eq!(mem::align_of::(), 8usize); -} - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct EmscriptenTouchEvent { - pub numTouches: c_int, - pub ctrlKey: c_int, - pub shiftKey: c_int, - pub altKey: c_int, - pub metaKey: c_int, - pub touches: [EmscriptenTouchPoint; 32usize], -} -#[test] -fn bindgen_test_layout_EmscriptenTouchEvent() { - assert_eq!(mem::size_of::(), 3096usize); - assert_eq!(mem::align_of::(), 8usize); -} - -#[repr(C)] -pub struct EmscriptenPointerlockChangeEvent { - pub isActive: c_int, - pub nodeName: [c_char; 128usize], - pub id: [c_char; 128usize], -} -#[test] -fn bindgen_test_layout_EmscriptenPointerlockChangeEvent() { - assert_eq!(mem::size_of::(), 260usize); - assert_eq!(mem::align_of::(), 4usize); -} - -extern "C" { - pub fn emscripten_set_canvas_size(width: c_int, height: c_int) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_get_canvas_size( - width: *mut c_int, - height: *mut c_int, - is_fullscreen: *mut c_int, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_element_css_size( - target: *const c_char, - width: c_double, - height: c_double, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_get_element_css_size( - target: *const c_char, - width: *mut c_double, - height: *mut c_double, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_request_pointerlock( - target: *const c_char, - deferUntilInEventHandler: EM_BOOL, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_exit_pointerlock() -> EMSCRIPTEN_RESULT; - - pub fn emscripten_request_fullscreen( - target: *const c_char, - deferUntilInEventHandler: EM_BOOL, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_exit_fullscreen() -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_keydown_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: EM_BOOL, - callback: em_key_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_keyup_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: EM_BOOL, - callback: em_key_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_mousemove_callback( - target: *const c_char, - user_data: *mut c_void, - use_capture: EM_BOOL, - callback: em_mouse_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_mousedown_callback( - target: *const c_char, - user_data: *mut c_void, - use_capture: EM_BOOL, - callback: em_mouse_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_mouseup_callback( - target: *const c_char, - user_data: *mut c_void, - use_capture: EM_BOOL, - callback: em_mouse_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_hide_mouse(); - - pub fn emscripten_get_device_pixel_ratio() -> f64; - - pub fn emscripten_set_pointerlockchange_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: EM_BOOL, - callback: em_pointerlockchange_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_fullscreenchange_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: EM_BOOL, - callback: em_fullscreenchange_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_asm_const(code: *const c_char); - - pub fn emscripten_set_main_loop( - func: em_callback_func, - fps: c_int, - simulate_infinite_loop: EM_BOOL, - ); - - pub fn emscripten_cancel_main_loop(); - - pub fn emscripten_set_touchstart_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: c_int, - callback: em_touch_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_touchend_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: c_int, - callback: em_touch_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_touchmove_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: c_int, - callback: em_touch_callback_func, - ) -> EMSCRIPTEN_RESULT; - - pub fn emscripten_set_touchcancel_callback( - target: *const c_char, - userData: *mut c_void, - useCapture: c_int, - callback: em_touch_callback_func, - ) -> EMSCRIPTEN_RESULT; -} diff --git a/src/platform_impl/emscripten/mod.rs b/src/platform_impl/emscripten/mod.rs deleted file mode 100644 index 2e9c9709..00000000 --- a/src/platform_impl/emscripten/mod.rs +++ /dev/null @@ -1,1246 +0,0 @@ -#![cfg(target_os = "emscripten")] - -mod ffi; - -use std::{ - cell::RefCell, - collections::VecDeque, - mem, - os::raw::{c_char, c_double, c_int, c_ulong, c_void}, - ptr, str, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, Mutex, - }, -}; - -use crate::{ - dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}, - error::{ExternalError, NotSupportedError}, - window::MonitorHandle as RootMonitorHandle, -}; - -const DOCUMENT_NAME: &'static str = "#document\0"; - -fn hidpi_factor() -> f64 { - unsafe { ffi::emscripten_get_device_pixel_ratio() as f64 } -} - -#[derive(Clone, Default)] -pub struct PlatformSpecificWindowBuilderAttributes; - -unsafe impl Send for PlatformSpecificWindowBuilderAttributes {} -unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {} - -pub type OsError = std::io::Error; - -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct DeviceId; - -impl DeviceId { - pub unsafe fn dummy() -> Self { - DeviceId - } -} - -#[derive(Clone, Default)] -pub struct PlatformSpecificHeadlessBuilderAttributes; - -#[derive(Debug, Clone)] -pub struct MonitorHandle; - -impl MonitorHandle { - #[inline] - pub fn name(&self) -> Option { - Some("Canvas".to_owned()) - } - - #[inline] - pub fn outer_position(&self) -> PhysicalPosition { - unimplemented!() - } - - #[inline] - pub fn size(&self) -> PhysicalSize { - (0, 0).into() - } - - #[inline] - pub fn hidpi_factor(&self) -> f64 { - hidpi_factor() - } -} - -// Used to assign a callback to emscripten main loop -thread_local!(static MAIN_LOOP_CALLBACK: RefCell<*mut c_void> = RefCell::new(ptr::null_mut())); - -// Used to assign a callback to emscripten main loop -pub fn set_main_loop_callback(callback: F) -where - F: FnMut(), -{ - MAIN_LOOP_CALLBACK.with(|log| { - *log.borrow_mut() = &callback as *const _ as *mut c_void; - }); - - unsafe { - ffi::emscripten_set_main_loop(Some(wrapper::), 0, 1); - } - - unsafe extern "C" fn wrapper() - where - F: FnMut(), - { - MAIN_LOOP_CALLBACK.with(|z| { - let closure = *z.borrow_mut() as *mut F; - (*closure)(); - }); - } -} - -#[derive(Clone)] -pub struct EventLoopProxy; - -impl EventLoopProxy { - pub fn wakeup(&self) -> Result<(), ::EventLoopClosed> { - unimplemented!() - } -} - -pub struct EventLoop { - window: Mutex>>, - interrupted: AtomicBool, -} - -impl EventLoop { - pub fn new() -> EventLoop { - EventLoop { - window: Mutex::new(None), - interrupted: AtomicBool::new(false), - } - } - - #[inline] - pub fn interrupt(&self) { - self.interrupted.store(true, Ordering::Relaxed); - } - - #[inline] - pub fn create_proxy(&self) -> EventLoopProxy { - unimplemented!() - } - - #[inline] - pub fn available_monitors(&self) -> VecDeque { - let mut list = VecDeque::with_capacity(1); - list.push_back(MonitorHandle); - list - } - - #[inline] - pub fn primary_monitor(&self) -> MonitorHandle { - MonitorHandle - } - - pub fn poll_events(&self, mut callback: F) - where - F: FnMut(::Event), - { - let ref mut window = *self.window.lock().unwrap(); - if let &mut Some(ref mut window) = window { - while let Some(event) = window.events.lock().unwrap().pop_front() { - callback(event) - } - } - } - - pub fn run_forever(&self, mut callback: F) - where - F: FnMut(::Event) -> ::ControlFlow, - { - self.interrupted.store(false, Ordering::Relaxed); - - // TODO: handle control flow - - set_main_loop_callback(|| { - self.poll_events(|e| { - callback(e); - }); - ::std::thread::sleep(::std::time::Duration::from_millis(5)); - if self.interrupted.load(Ordering::Relaxed) { - unsafe { - ffi::emscripten_cancel_main_loop(); - } - } - }); - } -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct WindowId(usize); - -impl WindowId { - pub unsafe fn dummy() -> Self { - WindowId(0) - } -} - -pub struct Window2 { - cursor_grabbed: Mutex, - cursor_visible: Mutex, - is_fullscreen: bool, - events: Box>>, -} - -pub struct Window { - window: Arc, -} - -fn show_mouse() { - // Hide mouse hasn't show mouse equivalent. - // There is a pull request on emscripten that hasn't been merged #4616 - // that contains: - // - // var styleSheet = document.styleSheets[0]; - // var rules = styleSheet.cssRules; - // for (var i = 0; i < rules.length; i++) { - // if (rules[i].cssText.substr(0, 6) == 'canvas') { - // styleSheet.deleteRule(i); - // i--; - // } - // } - // styleSheet.insertRule('canvas.emscripten { border: none; cursor: auto; }', 0); - unsafe { - ffi::emscripten_asm_const(b"var styleSheet = document.styleSheets[0]; var rules = styleSheet.cssRules; for (var i = 0; i < rules.length; i++) { if (rules[i].cssText.substr(0, 6) == 'canvas') { styleSheet.deleteRule(i); i--; } } styleSheet.insertRule('canvas.emscripten { border: none; cursor: auto; }', 0);\0".as_ptr() as *const c_char); - } -} - -extern "C" fn mouse_callback( - event_type: c_int, - event: *const ffi::EmscriptenMouseEvent, - event_queue: *mut c_void, -) -> ffi::EM_BOOL { - unsafe { - let queue: &Mutex> = mem::transmute(event_queue); - - let modifiers = ::ModifiersState { - shift: (*event).shiftKey == ffi::EM_TRUE, - ctrl: (*event).ctrlKey == ffi::EM_TRUE, - alt: (*event).altKey == ffi::EM_TRUE, - logo: (*event).metaKey == ffi::EM_TRUE, - }; - - match event_type { - ffi::EMSCRIPTEN_EVENT_MOUSEMOVE => { - let dpi_factor = hidpi_factor(); - let position = LogicalPosition::from_physical( - ((*event).canvasX as f64, (*event).canvasY as f64), - dpi_factor, - ); - queue.lock().unwrap().push_back(::Event::WindowEvent { - window_id: ::WindowId(WindowId(0)), - event: ::WindowEvent::CursorMoved { - device_id: ::DeviceId(DeviceId), - position, - modifiers, - }, - }); - queue.lock().unwrap().push_back(::Event::DeviceEvent { - device_id: ::DeviceId(DeviceId), - event: ::DeviceEvent::MouseMotion { - delta: ((*event).movementX as f64, (*event).movementY as f64), - }, - }); - } - mouse_input @ ffi::EMSCRIPTEN_EVENT_MOUSEDOWN - | mouse_input @ ffi::EMSCRIPTEN_EVENT_MOUSEUP => { - let button = match (*event).button { - 0 => ::MouseButton::Left, - 1 => ::MouseButton::Middle, - 2 => ::MouseButton::Right, - other => ::MouseButton::Other(other as u8), - }; - let state = match mouse_input { - ffi::EMSCRIPTEN_EVENT_MOUSEDOWN => ::ElementState::Pressed, - ffi::EMSCRIPTEN_EVENT_MOUSEUP => ::ElementState::Released, - _ => unreachable!(), - }; - queue.lock().unwrap().push_back(::Event::WindowEvent { - window_id: ::WindowId(WindowId(0)), - event: ::WindowEvent::MouseInput { - device_id: ::DeviceId(DeviceId), - state, - button, - modifiers, - }, - }) - } - _ => {} - } - } - ffi::EM_FALSE -} - -extern "C" fn keyboard_callback( - event_type: c_int, - event: *const ffi::EmscriptenKeyboardEvent, - event_queue: *mut c_void, -) -> ffi::EM_BOOL { - unsafe { - let queue: &Mutex> = mem::transmute(event_queue); - - let modifiers = ::ModifiersState { - shift: (*event).shiftKey == ffi::EM_TRUE, - ctrl: (*event).ctrlKey == ffi::EM_TRUE, - alt: (*event).altKey == ffi::EM_TRUE, - logo: (*event).metaKey == ffi::EM_TRUE, - }; - - match event_type { - ffi::EMSCRIPTEN_EVENT_KEYDOWN => { - queue.lock().unwrap().push_back(::Event::WindowEvent { - window_id: ::WindowId(WindowId(0)), - event: ::WindowEvent::KeyboardInput { - device_id: ::DeviceId(DeviceId), - input: ::KeyboardInput { - scancode: key_translate((*event).key) as u32, - state: ::ElementState::Pressed, - virtual_keycode: key_translate_virt((*event).key, (*event).location), - modifiers, - }, - }, - }); - } - ffi::EMSCRIPTEN_EVENT_KEYUP => { - queue.lock().unwrap().push_back(::Event::WindowEvent { - window_id: ::WindowId(WindowId(0)), - event: ::WindowEvent::KeyboardInput { - device_id: ::DeviceId(DeviceId), - input: ::KeyboardInput { - scancode: key_translate((*event).key) as u32, - state: ::ElementState::Released, - virtual_keycode: key_translate_virt((*event).key, (*event).location), - modifiers, - }, - }, - }); - } - _ => {} - } - } - ffi::EM_FALSE -} - -extern "C" fn touch_callback( - event_type: c_int, - event: *const ffi::EmscriptenTouchEvent, - event_queue: *mut c_void, -) -> ffi::EM_BOOL { - unsafe { - let queue: &Mutex> = mem::transmute(event_queue); - - let phase = match event_type { - ffi::EMSCRIPTEN_EVENT_TOUCHSTART => ::TouchPhase::Started, - ffi::EMSCRIPTEN_EVENT_TOUCHEND => ::TouchPhase::Ended, - ffi::EMSCRIPTEN_EVENT_TOUCHMOVE => ::TouchPhase::Moved, - ffi::EMSCRIPTEN_EVENT_TOUCHCANCEL => ::TouchPhase::Cancelled, - _ => return ffi::EM_FALSE, - }; - - for touch in 0..(*event).numTouches as usize { - let touch = (*event).touches[touch]; - if touch.isChanged == ffi::EM_TRUE { - let dpi_factor = hidpi_factor(); - let location = LogicalPosition::from_physical( - (touch.canvasX as f64, touch.canvasY as f64), - dpi_factor, - ); - queue.lock().unwrap().push_back(::Event::WindowEvent { - window_id: ::WindowId(WindowId(0)), - event: ::WindowEvent::Touch(::Touch { - device_id: ::DeviceId(DeviceId), - phase, - id: touch.identifier as u64, - location, - force: None, // TODO - }), - }); - } - } - } - ffi::EM_FALSE -} - -// In case of fullscreen window this method will request fullscreen on change -#[allow(non_snake_case)] -unsafe extern "C" fn fullscreen_callback( - _eventType: c_int, - _fullscreenChangeEvent: *const ffi::EmscriptenFullscreenChangeEvent, - _userData: *mut c_void, -) -> ffi::EM_BOOL { - ffi::emscripten_request_fullscreen(ptr::null(), ffi::EM_TRUE); - ffi::EM_FALSE -} - -// In case of pointer grabbed this method will request pointer lock on change -#[allow(non_snake_case)] -unsafe extern "C" fn pointerlockchange_callback( - _eventType: c_int, - _pointerlockChangeEvent: *const ffi::EmscriptenPointerlockChangeEvent, - _userData: *mut c_void, -) -> ffi::EM_BOOL { - ffi::emscripten_request_pointerlock(ptr::null(), ffi::EM_TRUE); - ffi::EM_FALSE -} - -fn em_try(res: ffi::EMSCRIPTEN_RESULT) -> Result<(), String> { - match res { - ffi::EMSCRIPTEN_RESULT_SUCCESS | ffi::EMSCRIPTEN_RESULT_DEFERRED => Ok(()), - r @ _ => Err(error_to_str(r).to_string()), - } -} - -impl Window { - pub fn new( - event_loop: &EventLoop, - attribs: ::WindowAttributes, - _pl_attribs: PlatformSpecificWindowBuilderAttributes, - ) -> Result { - if event_loop.window.lock().unwrap().is_some() { - return Err(::CreationError::OsError( - "Cannot create another window".to_owned(), - )); - } - - let w = Window2 { - cursor_grabbed: Mutex::new(false), - cursor_visible: Mutex::new(true), - events: Default::default(), - is_fullscreen: attribs.fullscreen.is_some(), - }; - - let window = Window { - window: Arc::new(w), - }; - - // TODO: set up more event callbacks - unsafe { - em_try(ffi::emscripten_set_mousemove_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(mouse_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_mousedown_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(mouse_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_mouseup_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(mouse_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_keydown_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(keyboard_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_keyup_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(keyboard_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_touchstart_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(touch_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_touchend_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(touch_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_touchmove_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(touch_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - em_try(ffi::emscripten_set_touchcancel_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - mem::transmute(&*window.window.events), - ffi::EM_FALSE, - Some(touch_callback), - )) - .map_err(|e| ::CreationError::OsError(format!("emscripten error: {}", e)))?; - } - - if attribs.fullscreen.is_some() { - unsafe { - em_try(ffi::emscripten_request_fullscreen( - ptr::null(), - ffi::EM_TRUE, - )) - .map_err(|e| ::CreationError::OsError(e))?; - em_try(ffi::emscripten_set_fullscreenchange_callback( - ptr::null(), - 0 as *mut c_void, - ffi::EM_FALSE, - Some(fullscreen_callback), - )) - .map_err(|e| ::CreationError::OsError(e))?; - } - } else if let Some(size) = attribs.inner_size { - window.set_inner_size(size); - } - - *event_loop.window.lock().unwrap() = Some(window.window.clone()); - Ok(window) - } - - #[inline] - pub fn id(&self) -> WindowId { - WindowId(0) - } - - #[inline] - pub fn set_title(&self, _title: &str) {} - - #[inline] - pub fn outer_position(&self) -> Option { - Some((0, 0).into()) - } - - #[inline] - pub fn inner_position(&self) -> Option { - Some((0, 0).into()) - } - - #[inline] - pub fn set_outer_position(&self, _: LogicalPosition) {} - - #[inline] - pub fn inner_size(&self) -> Option { - unsafe { - let mut width = 0; - let mut height = 0; - let mut fullscreen = 0; - - if ffi::emscripten_get_canvas_size(&mut width, &mut height, &mut fullscreen) - != ffi::EMSCRIPTEN_RESULT_SUCCESS - { - None - } else { - let dpi_factor = self.hidpi_factor(); - let logical = LogicalSize::from_physical((width as u32, height as u32), dpi_factor); - Some(logical) - } - } - } - - #[inline] - pub fn outer_size(&self) -> Option { - self.inner_size() - } - - #[inline] - pub fn set_inner_size(&self, size: LogicalSize) { - unsafe { - let dpi_factor = self.hidpi_factor(); - let physical = PhysicalSize::from_logical(size, dpi_factor); - let (width, height): (u32, u32) = physical.into(); - ffi::emscripten_set_element_css_size( - ptr::null(), - width as c_double, - height as c_double, - ); - } - } - - #[inline] - pub fn set_min_inner_size(&self, _dimensions: Option) { - // N/A - } - - #[inline] - pub fn set_max_inner_size(&self, _dimensions: Option) { - // N/A - } - - #[inline] - pub fn set_resizable(&self, _resizable: bool) { - // N/A - } - - #[inline] - pub fn show(&self) { - // N/A - } - - #[inline] - pub fn hide(&self) { - // N/A - } - - #[inline] - pub fn set_cursor_icon(&self, _cursor: ::CursorIcon) { - // N/A - } - - #[inline] - pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> { - let mut grabbed_lock = self.window.cursor_grabbed.lock().unwrap(); - if grab == *grabbed_lock { - return Ok(()); - } - unsafe { - if grab { - em_try(ffi::emscripten_set_pointerlockchange_callback( - ptr::null(), - 0 as *mut c_void, - ffi::EM_FALSE, - Some(pointerlockchange_callback), - ))?; - em_try(ffi::emscripten_request_pointerlock( - ptr::null(), - ffi::EM_TRUE, - ))?; - } else { - em_try(ffi::emscripten_set_pointerlockchange_callback( - ptr::null(), - 0 as *mut c_void, - ffi::EM_FALSE, - None, - ))?; - em_try(ffi::emscripten_exit_pointerlock())?; - } - } - *grabbed_lock = grab; - Ok(()) - } - - #[inline] - pub fn set_cursor_visible(&self, visible: bool) { - let mut visible_lock = self.window.cursor_visible.lock().unwrap(); - if visible == *visible_lock { - return; - } - if visible { - show_mouse(); - } else { - unsafe { ffi::emscripten_hide_mouse() }; - } - *visible_lock = visible; - } - - #[inline] - pub fn hidpi_factor(&self) -> f64 { - hidpi_factor() - } - - #[inline] - pub fn set_cursor_position(&self, _position: LogicalPosition) -> Result<(), ExternalError> { - Err("Setting cursor position is not possible on Emscripten.".to_owned()) - } - - #[inline] - pub fn set_maximized(&self, _maximized: bool) { - // iOS has single screen maximized apps so nothing to do - } - - #[inline] - pub fn fullscreen(&self) -> Option<::MonitorHandle> { - None - } - - #[inline] - pub fn set_fullscreen(&self, _monitor: Option<::MonitorHandle>) { - // iOS has single screen maximized apps so nothing to do - } - - #[inline] - pub fn set_decorations(&self, _decorations: bool) { - // N/A - } - - #[inline] - pub fn set_always_on_top(&self, _always_on_top: bool) { - // N/A - } - - #[inline] - pub fn set_window_icon(&self, _icon: Option<::Icon>) { - // N/A - } - - #[inline] - pub fn set_ime_position(&self, _logical_spot: LogicalPosition) { - // N/A - } - - #[inline] - pub fn current_monitor(&self) -> RootMonitorHandle { - RootMonitorHandle { - inner: MonitorHandle, - } - } - - #[inline] - pub fn available_monitors(&self) -> VecDeque { - let mut list = VecDeque::with_capacity(1); - list.push_back(MonitorHandle); - list - } - - #[inline] - pub fn primary_monitor(&self) -> MonitorHandle { - MonitorHandle - } -} - -impl Drop for Window { - fn drop(&mut self) { - // Delete window from event_loop - // TODO: ? - /*if let Some(ev) = self.event_loop.upgrade() { - let _ = ev.window.lock().unwrap().take().unwrap(); - }*/ - - unsafe { - // Return back to normal cursor state - self.hide_cursor(false); - self.set_cursor_grab(false); - - // Exit fullscreen if on - if self.window.is_fullscreen { - ffi::emscripten_set_fullscreenchange_callback( - ptr::null(), - 0 as *mut c_void, - ffi::EM_FALSE, - None, - ); - ffi::emscripten_exit_fullscreen(); - } - - // Delete callbacks - ffi::emscripten_set_keydown_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - 0 as *mut c_void, - ffi::EM_FALSE, - None, - ); - ffi::emscripten_set_keyup_callback( - DOCUMENT_NAME.as_ptr() as *const c_char, - 0 as *mut c_void, - ffi::EM_FALSE, - None, - ); - } - } -} - -fn error_to_str(code: ffi::EMSCRIPTEN_RESULT) -> &'static str { - match code { - ffi::EMSCRIPTEN_RESULT_SUCCESS | ffi::EMSCRIPTEN_RESULT_DEFERRED => { - "Internal error in the library (success detected as failure)" - } - - ffi::EMSCRIPTEN_RESULT_NOT_SUPPORTED => "Not supported", - ffi::EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED => "Failed not deferred", - ffi::EMSCRIPTEN_RESULT_INVALID_TARGET => "Invalid target", - ffi::EMSCRIPTEN_RESULT_UNKNOWN_TARGET => "Unknown target", - ffi::EMSCRIPTEN_RESULT_INVALID_PARAM => "Invalid parameter", - ffi::EMSCRIPTEN_RESULT_FAILED => "Failed", - ffi::EMSCRIPTEN_RESULT_NO_DATA => "No data", - - _ => "Undocumented error", - } -} - -fn key_translate(input: [ffi::EM_UTF8; ffi::EM_HTML5_SHORT_STRING_LEN_BYTES]) -> u8 { - let slice = &input[0..input.iter().take_while(|x| **x != 0).count()]; - let maybe_key = unsafe { str::from_utf8(mem::transmute::<_, &[u8]>(slice)) }; - let key = match maybe_key { - Ok(key) => key, - Err(_) => { - return 0; - } - }; - if key.chars().count() == 1 { - key.as_bytes()[0] - } else { - 0 - } -} - -fn key_translate_virt( - input: [ffi::EM_UTF8; ffi::EM_HTML5_SHORT_STRING_LEN_BYTES], - location: c_ulong, -) -> Option<::VirtualKeyCode> { - let slice = &input[0..input.iter().take_while(|x| **x != 0).count()]; - let maybe_key = unsafe { str::from_utf8(mem::transmute::<_, &[u8]>(slice)) }; - let key = match maybe_key { - Ok(key) => key, - Err(_) => { - return None; - } - }; - use VirtualKeyCode::*; - match key { - "Alt" => match location { - ffi::DOM_KEY_LOCATION_LEFT => Some(LAlt), - ffi::DOM_KEY_LOCATION_RIGHT => Some(RAlt), - _ => None, - }, - "AltGraph" => None, - "CapsLock" => None, - "Control" => match location { - ffi::DOM_KEY_LOCATION_LEFT => Some(LControl), - ffi::DOM_KEY_LOCATION_RIGHT => Some(RControl), - _ => None, - }, - "Fn" => None, - "FnLock" => None, - "Hyper" => None, - "Meta" => None, - "NumLock" => Some(Numlock), - "ScrollLock" => Some(Scroll), - "Shift" => match location { - ffi::DOM_KEY_LOCATION_LEFT => Some(LShift), - ffi::DOM_KEY_LOCATION_RIGHT => Some(RShift), - _ => None, - }, - "Super" => None, - "Symbol" => None, - "SymbolLock" => None, - - "Enter" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadEnter), - _ => Some(Return), - }, - "Tab" => Some(Tab), - " " => Some(Space), - - "ArrowDown" => Some(Down), - "ArrowLeft" => Some(Left), - "ArrowRight" => Some(Right), - "ArrowUp" => Some(Up), - "End" => None, - "Home" => None, - "PageDown" => None, - "PageUp" => None, - - "Backspace" => Some(Back), - "Clear" => None, - "Copy" => None, - "CrSel" => None, - "Cut" => None, - "Delete" => None, - "EraseEof" => None, - "ExSel" => None, - "Insert" => Some(Insert), - "Paste" => None, - "Redo" => None, - "Undo" => None, - - "Accept" => None, - "Again" => None, - "Attn" => None, - "Cancel" => None, - "ContextMenu" => None, - "Escape" => Some(Escape), - "Execute" => None, - "Find" => None, - "Finish" => None, - "Help" => None, - "Pause" => Some(Pause), - "Play" => None, - "Props" => None, - "Select" => None, - "ZoomIn" => None, - "ZoomOut" => None, - - "BrightnessDown" => None, - "BrightnessUp" => None, - "Eject" => None, - "LogOff" => None, - "Power" => Some(Power), - "PowerOff" => None, - "PrintScreen" => Some(Snapshot), - "Hibernate" => None, - "Standby" => Some(Sleep), - "WakeUp" => Some(Wake), - - "AllCandidates" => None, - "Alphanumeric" => None, - "CodeInput" => None, - "Compose" => Some(Compose), - "Convert" => Some(Convert), - "Dead" => None, - "FinalMode" => None, - "GroupFirst" => None, - "GroupLast" => None, - "GroupNext" => None, - "GroupPrevious" => None, - "ModeChange" => None, - "NextCandidate" => None, - "NonConvert" => None, - "PreviousCandidate" => None, - "Process" => None, - "SingleCandidate" => None, - - "HangulMode" => None, - "HanjaMode" => None, - "JunjaMode" => None, - - "Eisu" => None, - "Hankaku" => None, - "Hiragana" => None, - "HiraganaKatakana" => None, - "KanaMode" => Some(Kana), - "KanjiMode" => Some(Kanji), - "Romaji" => None, - "Zenkaku" => None, - "ZenkakuHanaku" => None, - - "F1" => Some(F1), - "F2" => Some(F2), - "F3" => Some(F3), - "F4" => Some(F4), - "F5" => Some(F5), - "F6" => Some(F6), - "F7" => Some(F7), - "F8" => Some(F8), - "F9" => Some(F9), - "F10" => Some(F10), - "F11" => Some(F11), - "F12" => Some(F12), - "F13" => Some(F13), - "F14" => Some(F14), - "F15" => Some(F15), - "F16" => Some(F16), - "F17" => Some(F17), - "F18" => Some(F18), - "F19" => Some(F19), - "F20" => Some(F20), - "F21" => Some(F21), - "F22" => Some(F22), - "F23" => Some(F23), - "F24" => Some(F24), - "Soft1" => None, - "Soft2" => None, - "Soft3" => None, - "Soft4" => None, - - "AppSwitch" => None, - "Call" => None, - "Camera" => None, - "CameraFocus" => None, - "EndCall" => None, - "GoBack" => None, - "GoHome" => None, - "HeadsetHook" => None, - "LastNumberRedial" => None, - "Notification" => None, - "MannerMode" => None, - "VoiceDial" => None, - - "ChannelDown" => None, - "ChannelUp" => None, - "MediaFastForward" => None, - "MediaPause" => None, - "MediaPlay" => None, - "MediaPlayPause" => Some(PlayPause), - "MediaRecord" => None, - "MediaRewind" => None, - "MediaStop" => Some(MediaStop), - "MediaTrackNext" => Some(NextTrack), - "MediaTrackPrevious" => Some(PrevTrack), - - "AudioBalanceLeft" => None, - "AudioBalanceRight" => None, - "AudioBassDown" => None, - "AudioBassBoostDown" => None, - "AudioBassBoostToggle" => None, - "AudioBassBoostUp" => None, - "AudioBassUp" => None, - "AudioFaderFront" => None, - "AudioFaderRear" => None, - "AudioSurroundModeNext" => None, - "AudioTrebleDown" => None, - "AudioTrebleUp" => None, - "AudioVolumeDown" => Some(VolumeDown), - "AudioVolumeMute" => Some(Mute), - "AudioVolumeUp" => Some(VolumeUp), - "MicrophoneToggle" => None, - "MicrophoneVolumeDown" => None, - "MicrophoneVolumeMute" => None, - "MicrophoneVolumeUp" => None, - - "TV" => None, - "TV3DMode" => None, - "TVAntennaCable" => None, - "TVAudioDescription" => None, - "TVAudioDescriptionMixDown" => None, - "TVAudioDescriptionMixUp" => None, - "TVContentsMenu" => None, - "TVDataService" => None, - "TVInput" => None, - "TVInputComponent1" => None, - "TVInputComponent2" => None, - "TVInputComposite1" => None, - "TVInputComposite2" => None, - "TVInputHDM1" => None, - "TVInputHDM2" => None, - "TVInputHDM3" => None, - "TVInputHDM4" => None, - "TVInputVGA1" => None, - "TVMediaContext" => None, - "TVNetwork" => None, - "TVNumberEntry" => None, - "TVPower" => None, - "TVRadioService" => None, - "TVSatellite" => None, - "TVSatelliteBS" => None, - "TVSatelliteCS" => None, - "TVSatelliteToggle" => None, - "TVTerrestrialAnalog" => None, - "TVTerrestrialDigital" => None, - "TVTimer" => None, - - "AVRInput" => None, - "AVRPower" => None, - "ColorF0Red" => None, - "ColorF1Green" => None, - "ColorF2Yellow" => None, - "ColorF3Blue" => None, - "ColorF4Grey" => None, - "ColorF5Brown" => None, - "ClosedCaptionToggle" => None, - "Dimmer" => None, - "DisplaySwap" => None, - "DVR" => None, - "Exit" => None, - "FavoriteClear0" => None, - "FavoriteClear1" => None, - "FavoriteClear2" => None, - "FavoriteClear3" => None, - "FavoriteRecall0" => None, - "FavoriteRecall1" => None, - "FavoriteRecall2" => None, - "FavoriteRecall3" => None, - "FavoriteStore0" => None, - "FavoriteStore1" => None, - "FavoriteStore2" => None, - "FavoriteStore3" => None, - "FavoriteStore4" => None, - "Guide" => None, - "GuideNextDay" => None, - "GuidePreviousDay" => None, - "Info" => None, - "InstantReplay" => None, - "Link" => None, - "ListProgram" => None, - "LiveContent" => None, - "Lock" => None, - "MediaApps" => None, - "MediaAudioTrack" => None, - "MediaLast" => None, - "MediaSkipBackward" => None, - "MediaSkipForward" => None, - "MediaStepBackward" => None, - "MediaStepForward" => None, - "MediaTopMenu" => None, - "NavigateIn" => None, - "NavigateNext" => None, - "NavigateOut" => None, - "NavigatePrevious" => None, - "NextFavoriteChannel" => None, - "NextUserProfile" => None, - "OnDemand" => None, - "Pairing" => None, - "PinPDown" => None, - "PinPMove" => None, - "PinPToggle" => None, - "PinPUp" => None, - "PlaySpeedDown" => None, - "PlaySpeedReset" => None, - "PlaySpeedUp" => None, - "RandomToggle" => None, - "RcLowBattery" => None, - "RecordSpeedNext" => None, - "RfBypass" => None, - "ScanChannelsToggle" => None, - "ScreenModeNext" => None, - "Settings" => None, - "SplitScreenToggle" => None, - "STBInput" => None, - "STBPower" => None, - "Subtitle" => None, - "Teletext" => None, - "VideoModeNext" => None, - "Wink" => None, - "ZoomToggle" => None, - - "SpeechCorrectionList" => None, - "SpeechInputToggle" => None, - - "Close" => None, - "New" => None, - "Open" => None, - "Print" => None, - "Save" => None, - "SpellCheck" => None, - "MailForward" => None, - "MailReply" => None, - "MailSend" => None, - - "LaunchCalculator" => Some(Calculator), - "LaunchCalendar" => None, - "LaunchContacts" => None, - "LaunchMail" => Some(Mail), - "LaunchMediaPlayer" => None, - "LaunchMusicPlayer" => None, - "LaunchMyComputer" => Some(MyComputer), - "LaunchPhone" => None, - "LaunchScreenSaver" => None, - "LaunchSpreadsheet" => None, - "LaunchWebCam" => None, - "LaunchWordProcessor" => None, - "LaunchApplication1" => None, - "LaunchApplication2" => None, - "LaunchApplication3" => None, - "LaunchApplication4" => None, - "LaunchApplication5" => None, - "LaunchApplication6" => None, - "LaunchApplication7" => None, - "LaunchApplication8" => None, - "LaunchApplication9" => None, - "LaunchApplication10" => None, - "LaunchApplication11" => None, - "LaunchApplication12" => None, - "LaunchApplication13" => None, - "LaunchApplication14" => None, - "LaunchApplication15" => None, - "LaunchApplication16" => None, - - "BrowserBack" => Some(WebBack), - "BrowserFavorites" => Some(WebFavorites), - "BrowserForward" => Some(WebForward), - "BrowserHome" => Some(WebHome), - "BrowserRefresh" => Some(WebRefresh), - "BrowserSearch" => Some(WebSearch), - "BrowserStop" => Some(WebStop), - - "Decimal" => Some(Decimal), - "Key11" => None, - "Key12" => None, - "Multiply" | "*" => Some(Multiply), - "Add" | "+" => Some(Add), - // "Clear" => None, - "Divide" => Some(Divide), - "Subtract" | "-" => Some(Subtract), - "Separator" => None, - "0" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad0), - _ => Some(Key0), - }, - "1" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad1), - _ => Some(Key1), - }, - "2" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad2), - _ => Some(Key2), - }, - "3" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad3), - _ => Some(Key3), - }, - "4" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad4), - _ => Some(Key4), - }, - "5" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad5), - _ => Some(Key5), - }, - "6" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad6), - _ => Some(Key6), - }, - "7" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad7), - _ => Some(Key7), - }, - "8" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad8), - _ => Some(Key8), - }, - "9" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(Numpad9), - _ => Some(Key9), - }, - - "A" | "a" => Some(A), - "B" | "b" => Some(B), - "C" | "c" => Some(C), - "D" | "d" => Some(D), - "E" | "e" => Some(E), - "F" | "f" => Some(F), - "G" | "g" => Some(G), - "H" | "h" => Some(H), - "I" | "i" => Some(I), - "J" | "j" => Some(J), - "K" | "k" => Some(K), - "L" | "l" => Some(L), - "M" | "m" => Some(M), - "N" | "n" => Some(N), - "O" | "o" => Some(O), - "P" | "p" => Some(P), - "Q" | "q" => Some(Q), - "R" | "r" => Some(R), - "S" | "s" => Some(S), - "T" | "t" => Some(T), - "U" | "u" => Some(U), - "V" | "v" => Some(V), - "W" | "w" => Some(W), - "X" | "x" => Some(X), - "Y" | "y" => Some(Y), - "Z" | "z" => Some(Z), - - "'" => Some(Apostrophe), - "\\" => Some(Backslash), - ":" => Some(Colon), - "," => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadComma), - _ => Some(Comma), - }, - "=" => match location { - ffi::DOM_KEY_LOCATION_NUMPAD => Some(NumpadEquals), - _ => Some(Equals), - }, - "{" => Some(LBracket), - "." => Some(Period), - "}" => Some(RBracket), - ";" => Some(Semicolon), - "/" => Some(Slash), - - _ => None, - } -} diff --git a/src/platform_impl/mod.rs b/src/platform_impl/mod.rs index 3b815208..bc8fc2c4 100644 --- a/src/platform_impl/mod.rs +++ b/src/platform_impl/mod.rs @@ -21,9 +21,6 @@ mod platform; #[cfg(target_os = "ios")] #[path = "ios/mod.rs"] mod platform; -#[cfg(target_os = "emscripten")] -#[path = "emscripten/mod.rs"] -mod platform; #[cfg(all( not(target_os = "ios"), @@ -35,6 +32,5 @@ mod platform; not(target_os = "freebsd"), not(target_os = "netbsd"), not(target_os = "openbsd"), - not(target_os = "emscripten") ))] compile_error!("The platform you're compiling for is not supported by winit");