diff --git a/Cargo.lock b/Cargo.lock index 42d60da13..995a2ee64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,20 +320,23 @@ dependencies = [ [[package]] name = "android-activity" -version = "0.4.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64529721f27c2314ced0890ce45e469574a73e5e6fdd6e9da1860eb29285f5e0" +checksum = "052ad56e336bcc615a214bffbeca6c181ee9550acec193f0327e0b103b033a4d" dependencies = [ "android-properties", - "bitflags 1.3.2", + "bitflags 2.4.1", "cc", + "cesu8", + "jni 0.21.1", "jni-sys", "libc", "log", - "ndk", + "ndk 0.8.0", "ndk-context", - "ndk-sys", - "num_enum 0.6.1", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.1", + "thiserror", ] [[package]] @@ -611,7 +614,7 @@ dependencies = [ "futures-lite", "log", "parking", - "polling", + "polling 2.8.0", "rustix 0.37.26", "slab", "socket2 0.4.10", @@ -910,21 +913,21 @@ dependencies = [ [[package]] name = "block-sys" -version = "0.1.0-beta.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" +checksum = "2dd7cf50912cddc06dc5ea7c08c5e81c1b2c842a70d19def1848d54c586fed92" dependencies = [ "objc-sys", ] [[package]] name = "block2" -version = "0.2.0-alpha.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" +checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" dependencies = [ "block-sys", - "objc2-encode", + "objc2", ] [[package]] @@ -992,6 +995,20 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "calloop" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50b5a44d59a98c55a9eeb518f39bf7499ba19fd98ee7d22618687f3f10adbf" +dependencies = [ + "bitflags 2.4.1", + "log", + "polling 3.2.0", + "rustix 0.38.20", + "slab", + "thiserror", +] + [[package]] name = "camino" version = "1.1.6" @@ -1199,8 +1216,8 @@ dependencies = [ "block", "cocoa-foundation", "core-foundation", - "core-graphics 0.23.1", - "foreign-types 0.5.0", + "core-graphics", + "foreign-types", "libc", "objc", ] @@ -1343,19 +1360,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" -[[package]] -name = "core-graphics" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", - "foreign-types 0.3.2", - "libc", -] - [[package]] name = "core-graphics" version = "0.23.1" @@ -1365,7 +1369,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -1414,7 +1418,7 @@ dependencies = [ "js-sys", "libc", "mach2", - "ndk", + "ndk 0.7.0", "ndk-context", "oboe", "once_cell", @@ -1599,6 +1603,12 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "cursor-icon" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" + [[package]] name = "d3d12" version = "0.7.0" @@ -1606,7 +1616,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20" dependencies = [ "bitflags 2.4.1", - "libloading 0.8.1", + "libloading 0.7.4", "winapi", ] @@ -2048,15 +2058,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared 0.1.1", -] - [[package]] name = "foreign-types" version = "0.5.0" @@ -2064,7 +2065,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared 0.3.1", + "foreign-types-shared", ] [[package]] @@ -2078,12 +2079,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -2600,6 +2595,17 @@ dependencies = [ "want", ] +[[package]] +name = "icrate" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d3aaff8a54577104bafdf686ff18565c3b6903ca5782a2026ef06e2c7aa319" +dependencies = [ + "block2", + "dispatch", + "objc2", +] + [[package]] name = "idna" version = "0.4.0" @@ -2795,6 +2801,22 @@ dependencies = [ "walkdir", ] +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", + "windows-sys 0.45.0", +] + [[package]] name = "jni-sys" version = "0.3.0" @@ -3075,7 +3097,7 @@ dependencies = [ "bitflags 2.4.1", "block", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "log", "objc", "paste", @@ -3203,9 +3225,25 @@ checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" dependencies = [ "bitflags 1.3.2", "jni-sys", - "ndk-sys", + "ndk-sys 0.4.1+23.1.7779620", "num_enum 0.5.11", - "raw-window-handle", + "raw-window-handle 0.5.2", + "thiserror", +] + +[[package]] +name = "ndk" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +dependencies = [ + "bitflags 2.4.1", + "jni-sys", + "log", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.1", + "raw-window-handle 0.5.2", + "raw-window-handle 0.6.0", "thiserror", ] @@ -3224,6 +3262,15 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ndk-sys" +version = "0.5.0+25.2.9519653" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c196769dd60fd4f363e11d948139556a344e79d451aeb2fa2fd040738ef7691" +dependencies = [ + "jni-sys", +] + [[package]] name = "nix" version = "0.24.3" @@ -3361,11 +3408,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +checksum = "683751d591e6d81200c39fb0d1032608b77724f34114db54f571ff1317b337c0" dependencies = [ - "num_enum_derive 0.6.1", + "num_enum_derive 0.7.1", ] [[package]] @@ -3382,9 +3429,9 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3430,29 +3477,25 @@ dependencies = [ [[package]] name = "objc-sys" -version = "0.2.0-beta.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" +checksum = "99e1d07c6eab1ce8b6382b8e3c7246fe117ff3f8b34be065f5ebace6749fe845" [[package]] name = "objc2" -version = "0.3.0-beta.3.patch-leaks.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468" +checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" dependencies = [ - "block2", "objc-sys", "objc2-encode", ] [[package]] name = "objc2-encode" -version = "2.0.0-pre.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" -dependencies = [ - "objc-sys", -] +checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" [[package]] name = "objc_exception" @@ -3488,7 +3531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8868cc237ee02e2d9618539a23a8d228b9bb3fc2e7a5b11eed3831de77c395d0" dependencies = [ "jni 0.20.0", - "ndk", + "ndk 0.7.0", "ndk-context", "num-derive", "num-traits", @@ -3750,6 +3793,20 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "polling" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62a79e457c9898100b4298d57d69ec53d06f9a6ed352431ce5f377e082d2e846" +dependencies = [ + "cfg-if", + "concurrent-queue", + "pin-project-lite", + "rustix 0.38.20", + "tracing", + "windows-sys 0.48.0", +] + [[package]] name = "pollster" version = "0.3.0" @@ -4002,6 +4059,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" +[[package]] +name = "raw-window-handle" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544" + [[package]] name = "rawpointer" version = "0.2.1" @@ -4477,7 +4540,7 @@ dependencies = [ "objc-foundation", "objc_id", "pollster", - "raw-window-handle", + "raw-window-handle 0.5.2", "urlencoding", "wasm-bindgen", "wasm-bindgen-futures", @@ -4887,6 +4950,15 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +[[package]] +name = "smol_str" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +dependencies = [ + "serde", +] + [[package]] name = "snapbox" version = "0.4.14" @@ -4948,13 +5020,13 @@ dependencies = [ "bytemuck", "cfg_aliases", "cocoa", - "core-graphics 0.23.1", + "core-graphics", "fastrand 2.0.1", - "foreign-types 0.5.0", + "foreign-types", "js-sys", "log", "objc", - "raw-window-handle", + "raw-window-handle 0.5.2", "redox_syscall 0.4.1", "rustix 0.38.20", "tiny-xlib", @@ -5769,17 +5841,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wayland-scanner" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" -dependencies = [ - "proc-macro2", - "quote", - "xml-rs", -] - [[package]] name = "wayland-sys" version = "0.31.1" @@ -5831,7 +5892,7 @@ dependencies = [ "naga", "parking_lot", "profiling", - "raw-window-handle", + "raw-window-handle 0.5.2", "smallvec", "static_assertions", "wasm-bindgen", @@ -5856,7 +5917,7 @@ dependencies = [ "naga", "parking_lot", "profiling", - "raw-window-handle", + "raw-window-handle 0.5.2", "rustc-hash", "smallvec", "thiserror", @@ -5888,7 +5949,7 @@ dependencies = [ "js-sys", "khronos-egl", "libc", - "libloading 0.8.1", + "libloading 0.7.4", "log", "metal", "naga", @@ -5897,7 +5958,7 @@ dependencies = [ "parking_lot", "profiling", "range-alloc", - "raw-window-handle", + "raw-window-handle 0.5.2", "renderdoc-sys", "rustc-hash", "smallvec", @@ -6127,32 +6188,42 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winit" -version = "0.28.7" +version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9596d90b45384f5281384ab204224876e8e8bf7d58366d9b795ad99aa9894b94" +checksum = "b829f75d02fe1e225b97c91a04c326900147a50234d1141a1cbe215ce8798c11" dependencies = [ "android-activity", - "bitflags 1.3.2", + "atomic-waker", + "bitflags 2.4.1", + "bytemuck", + "calloop", "cfg_aliases", "core-foundation", - "core-graphics 0.22.3", - "dispatch", - "instant", + "core-graphics", + "cursor-icon", + "icrate", + "js-sys", "libc", "log", - "mio", - "ndk", + "ndk 0.8.0", + "ndk-sys 0.5.0+25.2.9519653", "objc2", "once_cell", "orbclient", "percent-encoding", - "raw-window-handle", + "raw-window-handle 0.5.2", "redox_syscall 0.3.5", + "rustix 0.38.20", + "smol_str", + "unicode-segmentation", "wasm-bindgen", - "wayland-scanner", + "wasm-bindgen-futures", "web-sys", - "windows-sys 0.45.0", + "web-time", + "windows-sys 0.48.0", "x11-dl", + "x11rb", + "xkbcommon-dl", ] [[package]] @@ -6203,7 +6274,9 @@ dependencies = [ "as-raw-xcb-connection", "gethostname", "libc", + "libloading 0.7.4", "nix 0.26.4", + "once_cell", "winapi", "winapi-wsapoll", "x11rb-protocol", @@ -6228,6 +6301,25 @@ dependencies = [ "winapi", ] +[[package]] +name = "xkbcommon-dl" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699" +dependencies = [ + "bitflags 2.4.1", + "dlib", + "log", + "once_cell", + "xkeysym", +] + +[[package]] +name = "xkeysym" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621" + [[package]] name = "xml-rs" version = "0.8.19" diff --git a/all-is-cubes-desktop/Cargo.toml b/all-is-cubes-desktop/Cargo.toml index 3f3d74899..fc18fd2f6 100644 --- a/all-is-cubes-desktop/Cargo.toml +++ b/all-is-cubes-desktop/Cargo.toml @@ -56,7 +56,8 @@ tokio = { workspace = true, features = ["rt-multi-thread", "sync"] } tui = { version = "0.19.0", default-features = false, features = ["crossterm"] } unicode-width = { version = "0.1.9", default-features = false } # Note on feature selection: winit requires either "x11" or "wayland" to build at all on Linux, which is harmless elsewhere. I picked x11 because it should be the most compatible. -winit = { version = "0.28.1", default-features = false, features = ["x11"] } +# TODO: drop rwh_05 when wgpu and softbuffer are updated +winit = { version = "0.29.2", default-features = false, features = ["x11", "rwh_05"] } # Enable the log_hiccups feature yield-progress = { workspace = true, features = ["log_hiccups"] } diff --git a/all-is-cubes-desktop/src/aic_winit.rs b/all-is-cubes-desktop/src/aic_winit.rs index 9f6914c7d..8cf4d622c 100644 --- a/all-is-cubes-desktop/src/aic_winit.rs +++ b/all-is-cubes-desktop/src/aic_winit.rs @@ -5,8 +5,8 @@ use std::time::Instant; use anyhow::anyhow; use image::imageops::{self, FilterType}; -use winit::event::{DeviceEvent, ElementState, Event, KeyboardInput, WindowEvent}; -use winit::event_loop::{ControlFlow, EventLoop}; +use winit::event::{DeviceEvent, ElementState, Event, WindowEvent}; +use winit::event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}; use winit::window::{CursorGrabMode, Window}; use all_is_cubes::camera::{self, StandardCameras, Viewport}; @@ -121,7 +121,7 @@ pub(crate) fn winit_main_loop( ) -> Result<(), anyhow::Error> { let loop_start_time = Instant::now(); let mut first_frame = true; - event_loop.run(move |event, _, control_flow| { + Ok(event_loop.run(move |event, elwt| { if first_frame { first_frame = false; log::debug!( @@ -138,11 +138,11 @@ pub(crate) fn winit_main_loop( // Compute when we want to resume. // Note that handle_winit_event() might override this. if let Some(t) = dsession.session.frame_clock.next_step_or_draw_time() { - *control_flow = ControlFlow::WaitUntil(t); + elwt.set_control_flow(ControlFlow::WaitUntil(t)); } - handle_winit_event(event, &mut dsession, control_flow) - }) + handle_winit_event(event, &mut dsession, elwt) + })?) } pub(crate) fn create_window( @@ -309,29 +309,50 @@ pub(crate) fn create_winit_rt_desktop_session( /// This is separated from [`winit_main_loop`] for the sake of readability (more overall structure /// fitting on the screen) and possible refactoring towards having a common abstract main-loop. fn handle_winit_event( - event: Event<'_, ()>, + event: Event<()>, dsession: &mut DesktopSession, - control_flow: &mut ControlFlow, + elwt: &EventLoopWindowTarget<()>, ) { let input_processor = &mut dsession.session.input_processor; match event { Event::NewEvents(_) => {} Event::WindowEvent { window_id, event } if window_id == dsession.window.window.id() => { match event { - WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, + WindowEvent::CloseRequested => elwt.exit(), + + WindowEvent::RedrawRequested => { + if dsession.window.occluded + || dsession.window.window.is_visible() == Some(false) + || dsession.window.window.is_minimized() == Some(true) + { + return; + } + + dsession.renderer.update_world_camera(); + dsession.session.update_cursor(dsession.renderer.cameras()); + dsession + .window + .window + .set_cursor_icon(cursor_icon_to_winit(dsession.session.cursor_icon())); + + dsession + .renderer + .redraw(&dsession.session, &dsession.window.window); + + dsession.session.frame_clock.did_draw(); + } // Keyboard input WindowEvent::KeyboardInput { - input: - KeyboardInput { - virtual_keycode, + event: + winit::event::KeyEvent { + physical_key, state, .. }, .. } => { - // TODO: use KeyboardInput::scancode once we have editable bindings - if let Some(key) = virtual_keycode.and_then(map_key) { + if let Some(key) = map_key(physical_key) { match state { ElementState::Pressed => { input_processor.key_down(key); @@ -345,7 +366,6 @@ fn handle_winit_event( WindowEvent::Ime(ime_event) => { log::warn!("received IME event even though IME not enabled: {ime_event:?}"); } - WindowEvent::ReceivedCharacter(..) => {} WindowEvent::ModifiersChanged(..) => {} // Mouse input @@ -391,10 +411,11 @@ fn handle_winit_event( } WindowEvent::ScaleFactorChanged { scale_factor, - new_inner_size, - } => dsession - .viewport_cell - .set(physical_size_to_viewport(scale_factor, *new_inner_size)), + inner_size_writer: _, + } => dsession.viewport_cell.set(physical_size_to_viewport( + scale_factor, + dsession.window.window.inner_size(), + )), WindowEvent::Focused(has_focus) => { input_processor.key_focus(has_focus); } @@ -415,6 +436,7 @@ fn handle_winit_event( WindowEvent::HoveredFileCancelled => {} // Unused + WindowEvent::ActivationTokenDone { .. } => {} WindowEvent::Moved(_) => {} WindowEvent::Destroyed => {} WindowEvent::TouchpadPressure { .. } => {} @@ -445,13 +467,12 @@ fn handle_winit_event( DeviceEvent::Motion { .. } => {} DeviceEvent::Button { .. } => {} DeviceEvent::Key(_) => {} - DeviceEvent::Text { .. } => {} }, e @ Event::WindowEvent { .. } => { log::error!("event for a window we aren't managing: {:?}", e) } - Event::MainEventsCleared => { + Event::AboutToWait => { // Run simulation if it's time dsession.advance_time_and_maybe_step(); if dsession.session.frame_clock.should_draw() { @@ -459,36 +480,11 @@ fn handle_winit_event( } } - Event::RedrawRequested(id) if id == dsession.window.window.id() => { - if dsession.window.occluded - || dsession.window.window.is_visible() == Some(false) - || dsession.window.window.is_minimized() == Some(true) - { - return; - } - - dsession.renderer.update_world_camera(); - dsession.session.update_cursor(dsession.renderer.cameras()); - dsession - .window - .window - .set_cursor_icon(cursor_icon_to_winit(dsession.session.cursor_icon())); - - dsession - .renderer - .redraw(&dsession.session, &dsession.window.window); - - dsession.session.frame_clock.did_draw(); - } - e @ Event::RedrawRequested(_) => { - log::error!("event for a window we aren't managing: {:?}", e) - } - e @ Event::UserEvent(()) => log::error!("unexpected UserEvent: {e:?}"), Event::Suspended => {} Event::Resumed => {} - Event::RedrawEventsCleared => {} - Event::LoopDestroyed => {} + Event::LoopExiting => {} + Event::MemoryWarning => {} } } diff --git a/all-is-cubes-desktop/src/glue/winit.rs b/all-is-cubes-desktop/src/glue/winit.rs index fc9254285..36602b222 100644 --- a/all-is-cubes-desktop/src/glue/winit.rs +++ b/all-is-cubes-desktop/src/glue/winit.rs @@ -30,50 +30,56 @@ pub fn map_mouse_button(button: winit::event::MouseButton) -> usize { winit::event::MouseButton::Left => 0, winit::event::MouseButton::Right => 1, winit::event::MouseButton::Middle => 2, + winit::event::MouseButton::Back => 3, + winit::event::MouseButton::Forward => 4, winit::event::MouseButton::Other(other) => other.into(), } } -pub fn map_key(key: winit::event::VirtualKeyCode) -> Option { +pub fn map_key(key: winit::keyboard::PhysicalKey) -> Option { use all_is_cubes_ui::apps::Key as A; - use winit::event::VirtualKeyCode as V; + use winit::keyboard::KeyCode as V; + let key = match key { + winit::keyboard::PhysicalKey::Code(key_code) => key_code, + winit::keyboard::PhysicalKey::Unidentified(_) => return None, + }; Some(match key { - V::Key1 => A::Character('1'), - V::Key2 => A::Character('2'), - V::Key3 => A::Character('3'), - V::Key4 => A::Character('4'), - V::Key5 => A::Character('5'), - V::Key6 => A::Character('6'), - V::Key7 => A::Character('7'), - V::Key8 => A::Character('8'), - V::Key9 => A::Character('9'), - V::Key0 => A::Character('0'), - V::A => A::Character('a'), - V::B => A::Character('b'), - V::C => A::Character('c'), - V::D => A::Character('d'), - V::E => A::Character('e'), - V::F => A::Character('f'), - V::G => A::Character('g'), - V::H => A::Character('h'), - V::I => A::Character('i'), - V::J => A::Character('j'), - V::K => A::Character('k'), - V::L => A::Character('l'), - V::M => A::Character('m'), - V::N => A::Character('n'), - V::O => A::Character('o'), - V::P => A::Character('p'), - V::Q => A::Character('q'), - V::R => A::Character('r'), - V::S => A::Character('s'), - V::T => A::Character('t'), - V::U => A::Character('u'), - V::V => A::Character('v'), - V::W => A::Character('w'), - V::X => A::Character('x'), - V::Y => A::Character('y'), - V::Z => A::Character('z'), + V::Digit0 => A::Character('0'), + V::Digit1 => A::Character('1'), + V::Digit2 => A::Character('2'), + V::Digit3 => A::Character('3'), + V::Digit4 => A::Character('4'), + V::Digit5 => A::Character('5'), + V::Digit6 => A::Character('6'), + V::Digit7 => A::Character('7'), + V::Digit8 => A::Character('8'), + V::Digit9 => A::Character('9'), + V::KeyA => A::Character('a'), + V::KeyB => A::Character('b'), + V::KeyC => A::Character('c'), + V::KeyD => A::Character('d'), + V::KeyE => A::Character('e'), + V::KeyF => A::Character('f'), + V::KeyG => A::Character('g'), + V::KeyH => A::Character('h'), + V::KeyI => A::Character('i'), + V::KeyJ => A::Character('j'), + V::KeyK => A::Character('k'), + V::KeyL => A::Character('l'), + V::KeyM => A::Character('m'), + V::KeyN => A::Character('n'), + V::KeyO => A::Character('o'), + V::KeyP => A::Character('p'), + V::KeyQ => A::Character('q'), + V::KeyR => A::Character('r'), + V::KeyS => A::Character('s'), + V::KeyT => A::Character('t'), + V::KeyU => A::Character('u'), + V::KeyV => A::Character('v'), + V::KeyW => A::Character('w'), + V::KeyX => A::Character('x'), + V::KeyY => A::Character('y'), + V::KeyZ => A::Character('z'), V::Escape => A::Escape, V::F1 => return None, V::F2 => return None, @@ -99,25 +105,11 @@ pub fn map_key(key: winit::event::VirtualKeyCode) -> Option return None, V::F23 => return None, V::F24 => return None, - V::Snapshot => return None, - V::Scroll => return None, - V::Pause => return None, - V::Insert => return None, - V::Home => return None, - V::Delete => return None, - V::End => return None, - V::PageDown => return None, - V::PageUp => return None, - V::Left => A::Left, - V::Up => A::Up, - V::Right => A::Right, - V::Down => A::Down, - V::Back => return None, - V::Return => A::Character('\r'), + V::ArrowLeft => A::Left, + V::ArrowUp => A::Up, + V::ArrowRight => A::Right, + V::ArrowDown => A::Down, V::Space => A::Character(' '), - V::Compose => return None, - V::Caret => A::Character('^'), - V::Numlock => return None, V::Numpad0 => A::Character('0'), V::Numpad1 => A::Character('1'), V::Numpad2 => A::Character('2'), @@ -128,79 +120,25 @@ pub fn map_key(key: winit::event::VirtualKeyCode) -> Option A::Character('7'), V::Numpad8 => A::Character('8'), V::Numpad9 => A::Character('9'), - V::NumpadAdd => A::Character(']'), + V::NumpadAdd => A::Character('+'), V::NumpadDivide => A::Character('/'), V::NumpadDecimal => A::Character('.'), V::NumpadComma => A::Character(','), V::NumpadEnter => A::Character('\r'), - V::NumpadEquals => A::Character('='), + V::NumpadEqual => A::Character('='), V::NumpadMultiply => A::Character('*'), V::NumpadSubtract => A::Character('-'), - V::AbntC1 => return None, - V::AbntC2 => return None, - V::Apostrophe => A::Character('\''), - V::Apps => return None, - V::Asterisk => A::Character('*'), - V::At => A::Character('@'), - V::Ax => return None, + V::Quote => A::Character('\''), V::Backslash => A::Character('\\'), - V::Calculator => return None, - V::Capital => return None, - V::Colon => A::Character(':'), V::Comma => A::Character(','), - V::Convert => return None, - V::Equals => A::Character('='), - V::Grave => A::Character('`'), - V::Kana => return None, - V::Kanji => return None, - V::LAlt => return None, - V::LBracket => return None, - V::LControl => return None, - V::LShift => return None, - V::LWin => return None, - V::Mail => return None, - V::MediaSelect => return None, - V::MediaStop => return None, + V::Equal => A::Character('='), + V::Backquote => A::Character('`'), V::Minus => A::Character('-'), - V::Mute => return None, - V::MyComputer => return None, - V::NavigateForward => return None, - V::NavigateBackward => return None, - V::NextTrack => return None, - V::NoConvert => return None, - V::OEM102 => return None, V::Period => A::Character('.'), - V::PlayPause => return None, - V::Plus => A::Character('+'), - V::Power => return None, - V::PrevTrack => return None, - V::RAlt => return None, - V::RBracket => return None, - V::RControl => return None, - V::RShift => return None, - V::RWin => return None, V::Semicolon => A::Character(';'), V::Slash => A::Character('/'), - V::Sleep => return None, - V::Stop => return None, - V::Sysrq => return None, V::Tab => A::Character('\t'), - V::Underline => A::Character('_'), - V::Unlabeled => return None, - V::VolumeDown => return None, - V::VolumeUp => return None, - V::Wake => return None, - V::WebBack => return None, - V::WebFavorites => return None, - V::WebForward => return None, - V::WebHome => return None, - V::WebRefresh => return None, - V::WebSearch => return None, - V::WebStop => return None, - V::Yen => return None, - V::Copy => return None, - V::Paste => return None, - V::Cut => return None, + _ => return None, }) } @@ -209,7 +147,7 @@ pub fn cursor_icon_to_winit(icon: &all_is_cubes_ui::apps::CursorIcon) -> winit:: use winit::window::CursorIcon as W; match icon { A::Crosshair => W::Crosshair, - A::PointingHand => W::Hand, + A::PointingHand => W::Pointer, /* A::Normal | */ _ => W::Default, } } diff --git a/all-is-cubes-desktop/src/main.rs b/all-is-cubes-desktop/src/main.rs index 83d065891..14c85396f 100644 --- a/all-is-cubes-desktop/src/main.rs +++ b/all-is-cubes-desktop/src/main.rs @@ -206,7 +206,7 @@ fn main() -> Result<(), anyhow::Error> { // ever return “successfully”, so no code should follow it. match graphics_type { GraphicsType::Window => { - let event_loop = winit::event_loop::EventLoop::new(); + let event_loop = winit::event_loop::EventLoop::new()?; let dsession = inner_params .runtime .block_on(create_winit_wgpu_desktop_session( @@ -228,7 +228,7 @@ fn main() -> Result<(), anyhow::Error> { ) } GraphicsType::WindowRt => { - let event_loop = winit::event_loop::EventLoop::new(); + let event_loop = winit::event_loop::EventLoop::new()?; let dsession = create_winit_rt_desktop_session( session, aic_winit::create_window(