diff --git a/ndk/CHANGELOG.md b/ndk/CHANGELOG.md index 767baf68..7297184f 100644 --- a/ndk/CHANGELOG.md +++ b/ndk/CHANGELOG.md @@ -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) diff --git a/ndk/src/event.rs b/ndk/src/event.rs index 0e74f34b..843e1114 100644 --- a/ndk/src/event.rs +++ b/ndk/src/event.rs @@ -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) @@ -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`].