From f2edd235428ed5bce2c3523535272867a1056c8a Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 17 Oct 2023 02:08:33 +0200 Subject: [PATCH] Upgrade to `ndk 0.8`, `ndk-sys 0.5` + `android-activity 0.5` releases Fixes #2905. Co-authored-by: Robert Bragg --- CHANGELOG.md | 5 +++-- Cargo.toml | 10 ++++++---- src/platform_impl/android/keycodes.rs | 4 ++++ src/platform_impl/android/mod.rs | 13 ++++++++----- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c36f71dcb..8ebf4ed493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,10 +36,11 @@ And please only add new entries to the top of this list, right below the `# Unre - **Breaking** add `Event::MemoryWarning`; implemented on iOS/Android. - On Wayland, support `Occluded` event with xdg-shell v6 - Implement `AsFd`/`AsRawFd` for `EventLoop` on X11 and Wayland. +- **Breaking:** Bump `ndk` version to `0.8.0`, ndk-sys to `0.5.0`, `android-activity` to `0.5.0`. # 0.29.1-beta -- **Breaking:** Bump `ndk` version to `0.8.0-beta.0`, ndk-sys to `v0.5.0-beta.0`, `android-activity` to `0.5.0-beta.1`. +- **Breaking:** Bump `ndk` version to `0.8.0-beta.0`, ndk-sys to `0.5.0-beta.0`, `android-activity` to `0.5.0-beta.1`. - **Breaking:** Bump MSRV from `1.64` to `1.65`. - Make iOS windows usable from other threads. - Reexport `raw-window-handle` in `window` module. @@ -87,7 +88,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Web, remove unnecessary `Window::is_dark_mode()`, which was replaced with `Window::theme()`. - On Web, add `WindowBuilderExtWebSys::with_append()` to append the canvas element to the web page on creation. - On Windows, add `drag_resize_window` method support. -- **Breaking** `run() ->!` has been replaced by `run() -> Result<(), EventLoopError>` for returning errors without calling `std::process::exit()` ([#2767](https://github.com/rust-windowing/winit/pull/2767)) +- **Breaking** `run() -> !` has been replaced by `run() -> Result<(), EventLoopError>` for returning errors without calling `std::process::exit()` ([#2767](https://github.com/rust-windowing/winit/pull/2767)) - **Breaking** Removed `EventLoopExtRunReturn` / `run_return` in favor of `EventLoopExtPumpEvents` / `pump_events` and `EventLoopExtRunOnDemand` / `run_ondemand` ([#2767](https://github.com/rust-windowing/winit/pull/2767)) - `RedrawRequested` is no longer guaranteed to be emitted after `MainEventsCleared`, it is now platform-specific when the event is emitted after being requested via `redraw_request()`. - On Windows, `RedrawRequested` is now driven by `WM_PAINT` messages which are requested via `redraw_request()` diff --git a/Cargo.toml b/Cargo.toml index 9ee521722e..02febce867 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,9 @@ wayland-csd-adwaita-notitle = ["sctk-adwaita"] android-native-activity = ["android-activity/native-activity"] android-game-activity = ["android-activity/game-activity"] serde = ["dep:serde", "cursor-icon/serde", "smol_str/serde"] +rwh_04 = ["dep:rwh_04", "ndk/rwh_04"] +rwh_05 = ["dep:rwh_05", "ndk/rwh_05"] +rwh_06 = ["dep:rwh_06", "ndk/rwh_06"] [build-dependencies] cfg_aliases = "0.1.1" @@ -69,10 +72,9 @@ simple_logger = { version = "2.1.0", default_features = false } softbuffer = "0.3.0" [target.'cfg(target_os = "android")'.dependencies] -# Coordinate the next winit release android-activity 0.5 release -android-activity = "=0.5.0-beta.1" -ndk = "=0.8.0-beta.0" -ndk-sys = "=0.5.0-beta.0" +android-activity = "0.5.0" +ndk = "0.8.0" +ndk-sys = "0.5.0" [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] core-foundation = "0.9.3" diff --git a/src/platform_impl/android/keycodes.rs b/src/platform_impl/android/keycodes.rs index 583bd0a06c..b9731d60ad 100644 --- a/src/platform_impl/android/keycodes.rs +++ b/src/platform_impl/android/keycodes.rs @@ -555,6 +555,10 @@ pub fn to_logical(key_char: Option, keycode: Keycode) -> Key { ThumbsUp => Key::Unidentified(native), ThumbsDown => Key::Unidentified(native), ProfileSwitch => Key::Unidentified(native), + + // It's always possible that new versions of Android could introduce + // key codes we can't know about at compile time. + _ => Key::Unidentified(native), }, } } diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 2c6ef65c38..a6596ef297 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -946,10 +946,10 @@ impl Window { #[cfg(feature = "rwh_04")] pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle { + use rwh_04::HasRawWindowHandle; + if let Some(native_window) = self.app.native_window().as_ref() { - let mut handle = rwh_04::AndroidNdkHandle::empty(); - handle.a_native_window = native_window.ptr().as_ptr() as *mut _; - rwh_04::RawWindowHandle::AndroidNdk(handle) + native_window.raw_window_handle() } else { panic!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events."); } @@ -972,10 +972,13 @@ impl Window { } #[cfg(feature = "rwh_06")] + // Allow the usage of HasRawWindowHandle inside this function + #[allow(deprecated)] pub fn raw_window_handle_rwh_06(&self) -> Result { + use rwh_06::HasRawWindowHandle; + if let Some(native_window) = self.app.native_window().as_ref() { - let handle = rwh_06::AndroidNdkWindowHandle::new(native_window.ptr().cast()); - Ok(rwh_06::RawWindowHandle::AndroidNdk(handle)) + native_window.raw_window_handle() } else { log::error!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events."); Err(rwh_06::HandleError::Unavailable)