input: Split out InputEventJava into Motion and Key with Deref#503
input: Split out InputEventJava into Motion and Key with Deref#503
InputEventJava into Motion and Key with Deref#503Conversation
|
I'm going to refactor this PR a little bit further, at least to remove the Java moniker and change it to a proper https://developer.android.com/ndk/reference/group/native-activity#ainputreceiver_onkeyevent |
When I implemented the `from_java()` constructors for `MotionEvent` and `KeyEvent` in #456, I used a single `InputEventJava` wrapper since that could wrap the existing `enum InputEvent` and only need a single destructor calling `AInputEvent_release()` (which must only be called when the input event was created from Java). This however requires existing callers to `MotionEvent::from_java()` and `KeyEvent::from_java()` to _unwrap_/unpack that nested `enum InputEvent` again in order to get access to the underlying native methods, despite already calling a specific constructor method (since Android makes a distinction between both types). Not that that is even reachable, since the nested `InputEvent` member was private and there was no `Deref` into `&InputEvent` anywhere making it impossible to use this API in any meaningful way. Solve both issues by splitting the `struct` into a `Motion` and `Key` variant, and implement `Deref` on both to their respective type. No wrapper `InputEventJava` remains since there does not appear to be any reason to pass both of these types into a single API.
20fc5e6 to
8b9f422
Compare
|
I may or may not end up renaming it in a followup. |
Fixes #502
When I implemented the
from_java()constructors forMotionEventandKeyEventin #456, I used a singleInputEventJavawrapper since that could wrap the existingenum InputEventand only need a single destructor callingAInputEvent_release()(which must only be called when the input event was created from Java).This however requires existing callers to
MotionEvent::from_java()andKeyEvent::from_java()to unwrap/unpack that nestedenum InputEventagain in order to get access to the underlying native methods, despite already calling a specific constructor method (since Android makes a distinction between both types).Not that that is even reachable, since the nested
InputEventmember was private and there was noDerefinto&InputEventanywhere making it impossible to use this API in any meaningful way.Solve both issues by splitting the
structinto aMotionandKeyvariant, and implementDerefon both to their respective type. No wrapperInputEventJavaremains since there does not appear to be any reason to pass both of these types into a single API.