Skip to content

Commit

Permalink
ndk: Add tool_type getter for Pointer events (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atilogit authored Sep 6, 2022
1 parent 0bfdb87 commit 914439e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ndk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- event: Add `tool_type` getter for `Pointer`. (#323)

# 0.7.0 (2022-07-24)

- hardware_buffer: Make `HardwareBuffer::as_ptr()` public for interop with Vulkan. (#213)
Expand Down
22 changes: 22 additions & 0 deletions ndk/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ pub enum Axis {
Generic16 = ffi::AMOTION_EVENT_AXIS_GENERIC_16,
}

/// The tool type of a pointer.
///
/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-48)
#[derive(Copy, Clone, Debug, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)]
#[repr(u32)]
pub enum ToolType {
Unknown = ffi::AMOTION_EVENT_TOOL_TYPE_UNKNOWN,
Finger = ffi::AMOTION_EVENT_TOOL_TYPE_FINGER,
Stylus = ffi::AMOTION_EVENT_TOOL_TYPE_STYLUS,
Mouse = ffi::AMOTION_EVENT_TOOL_TYPE_MOUSE,
Eraser = ffi::AMOTION_EVENT_TOOL_TYPE_ERASER,
Palm = ffi::AMOTION_EVENT_TOOL_TYPE_PALM,
}

/// A bitfield representing the state of buttons during a motion event.
///
/// See [the NDK docs](https://developer.android.com/ndk/reference/group/input#anonymous-enum-33)
Expand Down Expand Up @@ -656,6 +670,14 @@ impl<'a> Pointer<'a> {
pub fn touch_minor(&self) -> f32 {
unsafe { ffi::AMotionEvent_getTouchMinor(self.event.as_ptr(), self.index as ffi::size_t) }
}

#[inline]
pub fn tool_type(&self) -> ToolType {
let tool_type = unsafe {
ffi::AMotionEvent_getToolType(self.event.as_ptr(), self.index as ffi::size_t) as u32
};
tool_type.try_into().unwrap()
}
}

/// An iterator over the pointers in a [`MotionEvent`].
Expand Down

0 comments on commit 914439e

Please sign in to comment.