Skip to content

Commit

Permalink
Upgrade ndk crate to 0.9.0
Browse files Browse the repository at this point in the history
The next breaking `ndk` release puts a lot of emphasis in improving
`enum`s to finally be marked `non_exhaustive`, and carry possible future
values in `__Unknown(i32)` variants.  This removes the lossy conversions
that previously required `android-activity` to redefine its types, which
could all be removed again.

The `repr()` types have also been updated, as `enum` constants in C are
translated to `u32` by default in `bindgen` even though they're commonly
passed as `int` to every API function that consumes them.
  • Loading branch information
MarijnS95 committed Apr 26, 2024
1 parent c9faa9c commit 2fded1d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ resolver = "2"
members = ["android-activity"]

exclude = ["examples"]

[patch.crates-io]
ndk = { git = "https://github.com/rust-mobile/ndk", rev = "3bd4388" }
ndk-sys = { git = "https://github.com/rust-mobile/ndk", rev = "3bd4388" }
12 changes: 4 additions & 8 deletions android-activity/src/native_activity/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,8 @@ impl<'a> PointerImpl<'a> {
#[inline]
pub fn axis_value(&self, axis: Axis) -> f32 {
let value: u32 = axis.into();
if let Ok(ndk_axis) = value.try_into() {
self.ndk_pointer.axis_value(ndk_axis)
} else {
// FIXME: We should also be able to query `Axis::__Unknown(u32)` values
// that can't currently be queried via the `ndk` `Pointer` API
0.0f32
}
let value = value as i32;
self.ndk_pointer.axis_value(value.into())

Check failure on line 266 in android-activity/src/native_activity/input.rs

View workflow job for this annotation

GitHub Actions / build (stable)

the trait bound `ndk::event::Axis: From<i32>` is not satisfied

Check failure on line 266 in android-activity/src/native_activity/input.rs

View workflow job for this annotation

GitHub Actions / build (stable)

the trait bound `ndk::event::Axis: From<i32>` is not satisfied
}

#[inline]
Expand All @@ -283,7 +278,8 @@ impl<'a> PointerImpl<'a> {

#[inline]
pub fn tool_type(&self) -> ToolType {
let value: u32 = self.ndk_pointer.tool_type().into();
let value: i32 = self.ndk_pointer.tool_type().into();

Check failure on line 281 in android-activity/src/native_activity/input.rs

View workflow job for this annotation

GitHub Actions / build (stable)

the trait bound `i32: From<ndk::event::ToolType>` is not satisfied

Check failure on line 281 in android-activity/src/native_activity/input.rs

View workflow job for this annotation

GitHub Actions / build (stable)

the trait bound `i32: From<ndk::event::ToolType>` is not satisfied
let value = value as u32;
value.into()
}
}
Expand Down
1 change: 1 addition & 0 deletions android-activity/src/native_activity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ impl<'a> InputIteratorInner<'a> {
ndk::event::InputEvent::KeyEvent(e) => {
input::InputEvent::KeyEvent(input::KeyEvent::new(e))
}
_ => todo!("NDK added a new type"),
};

// `finish_event` needs to be called for each event otherwise
Expand Down

0 comments on commit 2fded1d

Please sign in to comment.