Skip to content

Commit

Permalink
ndk/event: Implement SourceClass enum and provide Source::class()
Browse files Browse the repository at this point in the history
… getter

This `enum` was never `pub` even though it serves a slight purpose to
more easily classify various event sources, which is accounted for in
the bitmask-like value of `AINPUT_SOURCE_XXX`.
  • Loading branch information
MarijnS95 committed Dec 25, 2023
1 parent 2d269e1 commit 485b34e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions ndk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Move `MediaFormat` from `media::media_codec` to its own `media::media_format` module. (#442)
- media_format: Expose `MediaFormat::copy()` and `MediaFormat::clear()` from API level 29. (#449)
- event: Implement `SourceClass` enum and provide `Source::class()` getter. (#458)

# 0.8.0 (2023-10-15)

Expand Down
10 changes: 9 additions & 1 deletion ndk/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ pub enum Source {
Any = ffi::AINPUT_SOURCE_ANY,
}

impl Source {
pub fn class(self) -> SourceClass {
let class = u32::from(self) & ffi::AINPUT_SOURCE_CLASS_MASK;
// TODO: Don't use None
class.try_into().unwrap_or(SourceClass::None)
}
}

/// An enum representing the class of an [`InputEvent`] source.
///
/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-35)
#[derive(Debug, Clone, Copy, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
enum Class {
pub enum SourceClass {
None = ffi::AINPUT_SOURCE_CLASS_NONE,
Button = ffi::AINPUT_SOURCE_CLASS_BUTTON,
Pointer = ffi::AINPUT_SOURCE_CLASS_POINTER,
Expand Down

0 comments on commit 485b34e

Please sign in to comment.