Skip to content

input: Split out InputEventJava into Motion and Key with Deref #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MarijnS95
Copy link
Member

Fixes #502

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.

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.
@MarijnS95 MarijnS95 requested a review from rib April 25, 2025 16:11
@MarijnS95 MarijnS95 added this to the 0.10.0 release milestone Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant