Skip to content

Commit 0b0e19e

Browse files
MarijnS95rib
authored andcommitted
Revert "input: Replace open-coded types with ndk::event definitions (#163)"
This reverts commit 51d05d4 for backwards compatibility with the existing `0.6` releases. For now, it's creating a lot of busy work having to always make this revert in order to test various topic branch changes with winit 0.30. Lets save this breaking change until we have more reasons to break semver compatibility (in itself this doesn't fix or enable any features, so we can live without it for now).
1 parent e686e80 commit 0b0e19e

7 files changed

Lines changed: 904 additions & 53 deletions

File tree

android-activity/CHANGELOG.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
### Changed
10-
- input: Replaced custom types with their `ndk` crate equivalent.
11-
> [!NOTE]
12-
> 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 provide lossless conversions, and not to mention use an ABI type that matches how it is being used by most functions (when the original constants were defined in a "typeless" way), the `ndk` types are used and reexported once again.
9+
### Added
1310

14-
> [!IMPORTANT]
15-
> **Relevant breaking changes**:
16-
> - `repr()` types for some `enum`s have changed to match the ABI type that is used by most functions that are returning or consuming this wrapper type.
17-
> - `Source::is_xxx_class()` functions are replaced by querying `Source::class()` and comparing against variants from the returned `SourceClass` `bitflags` enum.
18-
> - `SourceFlags::TRACKBALL` (from `Source::is_trackball_class()`) is named `SourceClass::NAVIGATION` in the `ndk`.
11+
- The `ndk` and `ndk-sys` crates are now re-exported under `android_activity::ndk` and `android_activity::ndk_sys` ([#194](https://github.com/rust-mobile/android-activity/pull/194))
1912

13+
### Changed
2014
- rust-version bumped to 1.73.0 ([#193](https://github.com/rust-mobile/android-activity/pull/193))
21-
- The `ndk` and `ndk-sys` crates are now re-exported under `android_activity::ndk` and `android_activity::ndk_sys` ([#194](https://github.com/rust-mobile/android-activity/pull/194))
2215
- GameActivity updated to 4.0.0 (requires the corresponding 4.0.0 `.aar` release from Google) ([#191](https://github.com/rust-mobile/android-activity/pull/191))
2316

2417
## [0.6.0] - 2024-04-26

android-activity/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ default = []
3232
game-activity = []
3333
native-activity = []
3434
api-level-30 = ["ndk/api-level-30"]
35-
api-level-33 = ["api-level-30", "ndk/api-level-33"]
3635

3736
[dependencies]
3837
log = "0.4"

android-activity/src/game_activity/input.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
// The `Class` was also bound differently to `android-ndk-rs` considering how the class is defined
1414
// by masking bits from the `Source`.
1515

16-
use ndk::event::ButtonState;
17-
1816
use crate::activity_impl::ffi::{GameActivityKeyEvent, GameActivityMotionEvent};
1917
use crate::input::{
20-
Axis, Button, EdgeFlags, KeyAction, KeyEventFlags, Keycode, MetaState, MotionAction,
21-
MotionEventFlags, Pointer, PointersIter, Source, ToolType,
18+
Axis, Button, ButtonState, EdgeFlags, KeyAction, KeyEventFlags, Keycode, MetaState,
19+
MotionAction, MotionEventFlags, Pointer, PointersIter, Source, ToolType,
2220
};
2321

2422
// Note: try to keep this wrapper API compatible with the AInputEvent API if possible
@@ -49,7 +47,7 @@ impl<'a> MotionEvent<'a> {
4947
///
5048
#[inline]
5149
pub fn source(&self) -> Source {
52-
let source = self.ga_event.source;
50+
let source = self.ga_event.source as u32;
5351
source.into()
5452
}
5553

@@ -65,7 +63,7 @@ impl<'a> MotionEvent<'a> {
6563
/// See [the MotionEvent docs](https://developer.android.com/reference/android/view/MotionEvent#getActionMasked())
6664
#[inline]
6765
pub fn action(&self) -> MotionAction {
68-
let action = self.ga_event.action & ndk_sys::AMOTION_EVENT_ACTION_MASK as i32;
66+
let action = self.ga_event.action as u32 & ndk_sys::AMOTION_EVENT_ACTION_MASK;
6967
action.into()
7068
}
7169

@@ -178,7 +176,6 @@ impl<'a> MotionEvent<'a> {
178176
/// See [the NDK
179177
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getbuttonstate)
180178
#[inline]
181-
// TODO: Button enum to signify only one bitflag can be set?
182179
pub fn button_state(&self) -> ButtonState {
183180
ButtonState(self.ga_event.buttonState as u32)
184181
}
@@ -281,7 +278,7 @@ impl PointerImpl<'_> {
281278
#[inline]
282279
pub fn axis_value(&self, axis: Axis) -> f32 {
283280
let pointer = &self.event.ga_event.pointers[self.index];
284-
let axis: i32 = axis.into();
281+
let axis: u32 = axis.into();
285282
pointer.axisValues[axis as usize]
286283
}
287284

@@ -300,7 +297,8 @@ impl PointerImpl<'_> {
300297
#[inline]
301298
pub fn tool_type(&self) -> ToolType {
302299
let pointer = &self.event.ga_event.pointers[self.index];
303-
pointer.toolType.into()
300+
let tool_type = pointer.toolType as u32;
301+
tool_type.into()
304302
}
305303
}
306304

@@ -667,7 +665,7 @@ impl<'a> KeyEvent<'a> {
667665
///
668666
#[inline]
669667
pub fn source(&self) -> Source {
670-
let source = self.ga_event.source;
668+
let source = self.ga_event.source as u32;
671669
source.into()
672670
}
673671

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

690688
#[inline]
691689
pub fn action_button(&self) -> KeyAction {
692-
let action = self.ga_event.action;
690+
let action = self.ga_event.action as u32;
693691
action.into()
694692
}
695693

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

android-activity/src/game_activity/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,13 @@ impl AndroidAppInner {
547547
}
548548

549549
pub fn enable_motion_axis(&mut self, axis: Axis) {
550-
unsafe { ffi::GameActivityPointerAxes_enableAxis(axis.into()) }
550+
let axis: u32 = axis.into();
551+
unsafe { ffi::GameActivityPointerAxes_enableAxis(axis as i32) }
551552
}
552553

553554
pub fn disable_motion_axis(&mut self, axis: Axis) {
554-
unsafe { ffi::GameActivityPointerAxes_disableAxis(axis.into()) }
555+
let axis: u32 = axis.into();
556+
unsafe { ffi::GameActivityPointerAxes_disableAxis(axis as i32) }
555557
}
556558

557559
pub fn create_waker(&self) -> AndroidAppWaker {

0 commit comments

Comments
 (0)