Skip to content

Commit

Permalink
Replace input enums with ndk
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Sep 3, 2024
1 parent 6ceaa02 commit 2f72d77
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 902 deletions.
44 changes: 27 additions & 17 deletions android-activity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- input: Replaced custom types with their `ndk` crate equivalent.
> [!NOTE]
> These types existed because the `ndk` crate didn't provide them in an extensible way. Now that they have the `#[non_exhaustive]` flag and contain a `__Unknown(T)` variant to result in lossless conversions, and not to mention use an ABI type that how its used by most functions (when the original constants were defined in a "typeless" way), the `ndk` types are used and reexported once again.
> [!IMPORTANT]
> **Relevant breaking changes**:
> - `repr()` types for some `enum`s have changed to match the type that returned and consumed by functions interacting with this wrapper type.
> - `Source::is_xxx_class()` functions are replaced by querying `Source::class()` and comparing against variants from the returned `SourceClass` `bitflags` enum.
> - `SourceFlags::TRACKBALL` (from `Source::is_trackball_class()`) is named `SourceClass::NAVIGATION` in the `ndk`.
## [0.6.0] - 2024-04-26

### Changed
Expand All @@ -25,32 +35,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Avoids depending on default features for `ndk` crate to avoid pulling in any `raw-window-handle` dependencies ([#142](https://github.com/rust-mobile/android-activity/pull/142))

**Note:** Technically, this could be observed as a breaking change in case you
were depending on the `rwh_06` feature that was enabled by default in the
`ndk` crate. This could be observed via the `NativeWindow` type (exposed via
`AndroidApp::native_window()`) no longer implementing `rwh_06::HasWindowHandle`.
**Note:** Technically, this could be observed as a breaking change in case you
were depending on the `rwh_06` feature that was enabled by default in the
`ndk` crate. This could be observed via the `NativeWindow` type (exposed via
`AndroidApp::native_window()`) no longer implementing `rwh_06::HasWindowHandle`.

In the unlikely case that you were depending on the `ndk`'s `rwh_06` API
being enabled by default via `android-activity`'s `ndk` dependency, your crate
should explicitly enable the `rwh_06` feature for the `ndk` crate.
In the unlikely case that you were depending on the `ndk`'s `rwh_06` API
being enabled by default via `android-activity`'s `ndk` dependency, your crate
should explicitly enable the `rwh_06` feature for the `ndk` crate.

As far as could be seen though, it's not expected that anything was
depending on this (e.g. anything based on Winit enables the `ndk` feature
based on an equivalent `winit` feature).
As far as could be seen though, it's not expected that anything was
depending on this (e.g. anything based on Winit enables the `ndk` feature
based on an equivalent `winit` feature).

The benefit of the change is that it can help avoid a redundant
`raw-window-handle 0.6` dependency in projects that still need to use older
(non-default) `raw-window-handle` versions. (Though note that this may be
awkward to achieve in practice since other crates that depend on the `ndk`
are still likely to use default features and also pull in
`raw-window-handles 0.6`)
The benefit of the change is that it can help avoid a redundant
`raw-window-handle 0.6` dependency in projects that still need to use older
(non-default) `raw-window-handle` versions. (Though note that this may be
awkward to achieve in practice since other crates that depend on the `ndk`
are still likely to use default features and also pull in
`raw-window-handles 0.6`)

- The IO thread now gets named `stdio-to-logcat` and main thread is named `android_main` ([#145](https://github.com/rust-mobile/android-activity/pull/145))
- Improved IO error handling in `stdio-to-logcat` IO loop. ([#133](https://github.com/rust-mobile/android-activity/pull/133))

## [0.5.0] - 2023-10-16
### Added
- Added `MotionEvent::action_button()` exposing the button associated with button press/release actions ()
- Added `MotionEvent::action_button()` exposing the button associated with button press/release actions ([#138](https://github.com/rust-mobile/android-activity/pull/138))

### Changed
- rust-version bumped to 0.68 ([#123](https://github.com/rust-mobile/android-activity/pull/123))
Expand Down
18 changes: 10 additions & 8 deletions android-activity/src/game_activity/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
// The `Class` was also bound differently to `android-ndk-rs` considering how the class is defined
// by masking bits from the `Source`.

use ndk::event::ButtonState;

use crate::activity_impl::ffi::{GameActivityKeyEvent, GameActivityMotionEvent};
use crate::input::{
Axis, Button, ButtonState, EdgeFlags, KeyAction, KeyEventFlags, Keycode, MetaState,
MotionAction, MotionEventFlags, Pointer, PointersIter, Source, ToolType,
Axis, Button, EdgeFlags, KeyAction, KeyEventFlags, Keycode, MetaState, MotionAction,
MotionEventFlags, Pointer, PointersIter, Source, ToolType,
};

// Note: try to keep this wrapper API compatible with the AInputEvent API if possible
Expand Down Expand Up @@ -63,7 +65,7 @@ impl<'a> MotionEvent<'a> {
/// See [the MotionEvent docs](https://developer.android.com/reference/android/view/MotionEvent#getActionMasked())
#[inline]
pub fn action(&self) -> MotionAction {
let action = self.ga_event.action as u32 & ndk_sys::AMOTION_EVENT_ACTION_MASK;
let action = self.ga_event.action & ndk_sys::AMOTION_EVENT_ACTION_MASK as i32;
action.into()
}

Expand Down Expand Up @@ -176,6 +178,7 @@ impl<'a> MotionEvent<'a> {
/// See [the NDK
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getbuttonstate)
#[inline]
// TODO: Button enum to signify only one bitflag can be set?
pub fn button_state(&self) -> ButtonState {
ButtonState(self.ga_event.buttonState as u32)
}
Expand Down Expand Up @@ -297,8 +300,7 @@ impl<'a> PointerImpl<'a> {
#[inline]
pub fn tool_type(&self) -> ToolType {
let pointer = &self.event.ga_event.pointers[self.index];
let tool_type = pointer.toolType as i32;
tool_type.into()
pointer.toolType.into()
}
}

Expand Down Expand Up @@ -681,13 +683,13 @@ impl<'a> KeyEvent<'a> {
/// See [the KeyEvent docs](https://developer.android.com/reference/android/view/KeyEvent#getAction())
#[inline]
pub fn action(&self) -> KeyAction {
let action = self.ga_event.action as u32;
let action = self.ga_event.action;
action.into()
}

#[inline]
pub fn action_button(&self) -> KeyAction {
let action = self.ga_event.action as u32;
let action = self.ga_event.action;
action.into()
}

Expand Down Expand Up @@ -717,7 +719,7 @@ impl<'a> KeyEvent<'a> {
/// docs](https://developer.android.com/ndk/reference/group/input#akeyevent_getkeycode)
#[inline]
pub fn key_code(&self) -> Keycode {
let keycode = self.ga_event.keyCode as u32;
let keycode = self.ga_event.keyCode;
keycode.into()
}

Expand Down
Loading

0 comments on commit 2f72d77

Please sign in to comment.