fix: Correct inverted Android D-pad Up/Down (AXIS_HAT_Y double-inversion) - #128
Open
GhagSagar23 wants to merge 1 commit into
Open
Conversation
GhagSagar23
marked this pull request as ready for review
August 17, 2026 07:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #123.
On Android, pressing the D-pad Up emitted
GamepadButton.dpadDown(value 1.0), and Down emitteddpadUp. Root cause is a double inversion of the D-pad Y hat axis:gamepads_android'sEventListenerregistersAXIS_HAT_Ywithinvert = true(EventListener.kt:27), so the value delivered to Dart is already flipped to up = +1.0 / down = −1.0 — the opposite of Android's nativeAXIS_HAT_Y(up = −1.0 / down = +1.0).AndroidMapping.normalizeDpadAxisstill mapped per Android's native convention (value > 0 → dpadDown,value < 0 → dpadUp), so the two flips compounded.AXIS_HAT_Xis not inverted natively, so D-pad left/right were unaffected — matching the report.Change
Corrected the sign comparison in a single canonical location — the
AXIS_HAT_Ybranch ofAndroidMapping.normalizeDpadAxis— sodpadUpfires onvalue > 0anddpadDownonvalue < 0, with a comment citing #123.EventListener.ktis intentionally left unchanged to avoid re-introducing a double-inversion.packages/gamepads/lib/src/mappings/android_mapping.dartpackages/gamepads/test/mappings_test.dart— both-directionAXIS_HAT_YregressionFix-location decision (maintainer call welcome)
The reporter raised a genuine design choice for where to fix this:
EventListener.kt): drop theAXIS_HAT_Yinversion → raw/unnormalized values would then follow Android's1.0 == down.android_mapping.dart, this PR): keeps the library's existing1.0 == upraw convention.This PR takes option 2 to preserve the current raw-value convention (no breaking change) and because the mapping is pure Dart and directly unit-testable. Happy to switch to the Kotlin approach if you prefer — but the fix must live in exactly one place; applying it in both would double-invert and silently reintroduce the bug.
Tests
Added a both-direction regression to
AndroidMapping > "normalizes hat d-pad axes":AXIS_HAT_Y = +1.0(physical up) →dpadUp = 1.0,dpadDown = 0.0AXIS_HAT_Y = -1.0(physical down) →dpadDown = 1.0,dpadUp = 0.0This fails on the pre-fix code (which returned
dpadDown = 1.0for+1.0) and passes after the fix.Deferred
leftStickY/rightStickY): the reporter separately observed up reading-1.0. Left untouched here — confirm it's a genuine inversion vs. Android's native joystick convention before changing; tracked as a follow-up reusing this PR's convention decision.fix:PR title (CONTRIBUTING.md, "Creating a release").Coordination
Thanks @fescrb for the precise root-cause analysis. You'd offered to submit this — glad to defer to you or just help with review; sharing this as a ready-to-go option while the fix-location question is settled.