Skip to content

[rcore_android] Restore face-button input on Android gamepads#5824

Open
Tubbles wants to merge 1 commit intoraysan5:masterfrom
Tubbles:fix-android-gamepad-keyboard-source-regression
Open

[rcore_android] Restore face-button input on Android gamepads#5824
Tubbles wants to merge 1 commit intoraysan5:masterfrom
Tubbles:fix-android-gamepad-keyboard-source-regression

Conversation

@Tubbles
Copy link
Copy Markdown

@Tubbles Tubbles commented Apr 29, 2026

raylib 6.0's rcore_android.c:1279 guard !FLAG_IS_SET(source, AINPUT_SOURCE_KEYBOARD) drops face-button key events that arrive with both AINPUT_SOURCE_KEYBOARD and AINPUT_SOURCE_GAMEPAD set on the source bitmask. The keyboard fallback then sees mapKeycode[AKEYCODE_BUTTON_*] == 0 and the press is dropped. The GameSir X2 Type-C exhibits this regression: every face-button key event arrives with source 0x501 (KEYBOARD | GAMEPAD | CLASS_BUTTON). Reproducible on an 8BitDo Ultimate Bluetooth as well.

The combined source-bit pattern is general AOSP behaviour, not a controller quirk, and has shipped in every Android release since 3.2 (Feb 2011). Commit 6f2fba4 extended EventHub::openDeviceLocked to add InputDeviceClass::KEYBOARD to any input device whose evdev keyBitmask claims gamepad buttons (BTN_JOYSTICK..BTN_DIGI), in addition to InputDeviceClass::GAMEPAD. InputDevice::createMappers then ORs both classes into the keyboardSource and installs a KeyboardInputMapper, whose getEventSource() returns deviceSources & (AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_DPAD | AINPUT_SOURCE_GAMEPAD) and stamps that on every outgoing key event. For the X2 (deviceSources = 0x01000511) the mask yields 0x501.

The fix uses the keycode as the discriminator. AndroidTranslateGamepadButton(keycode) already enumerates exactly the keycodes raylib routes as gamepad buttons: a recognised keycode goes to the gamepad path, an unrecognised keycode falls through to the keyboard handler instead of being dropped. This mirrors KeyEvent.isGamepadButton(int), a pure keycode-range test that ignores the source. Side effect: CORE.Input.Gamepad.ready[0] now flips to true only when a recognised gamepad keycode arrives.

Assisted-by: Claude:claude-opus-4-7

@Tubbles Tubbles changed the title Android: trust gamepad keycode instead of source bits fix(rcore_android): trust gamepad keycode, not source bits Apr 29, 2026
@Tubbles Tubbles force-pushed the fix-android-gamepad-keyboard-source-regression branch from ae73a6f to 6b79e2a Compare April 29, 2026 10:41
@Tubbles Tubbles changed the title fix(rcore_android): trust gamepad keycode, not source bits [rcore_android] Restore gamepad input on multi-class controllers Apr 29, 2026
@Tubbles Tubbles force-pushed the fix-android-gamepad-keyboard-source-regression branch 4 times, most recently from b42abcf to 313375c Compare April 30, 2026 09:07
@Tubbles Tubbles marked this pull request as ready for review April 30, 2026 10:01
The KEYBOARD-source veto added in raysan5#5439 drops face-button key
events that arrive with both AINPUT_SOURCE_KEYBOARD and
AINPUT_SOURCE_GAMEPAD set on the source bitmask. Confirmed
reproducible on GameSir X2 Type-C and 8BitDo Ultimate Bluetooth,
both reporting source 0x501 on every face-button key event.

This source-bit pattern is general AOSP behaviour since Android
3.2 (commit 6f2fba4 in frameworks/base, Feb 2011): EventHub adds
InputDeviceClass::KEYBOARD to any device whose evdev keyBitmask
claims gamepad buttons (BTN_JOYSTICK..BTN_DIGI), and
KeyboardInputMapper::getEventSource stamps the resulting
KEYBOARD|GAMEPAD source on every outgoing key event.

Use AndroidTranslateGamepadButton(keycode) as the discriminator
instead. Recognised gamepad keycodes route to the gamepad path;
unknown keycodes fall through to the keyboard handler.

Assisted-by: Claude:claude-opus-4-7
@Tubbles Tubbles force-pushed the fix-android-gamepad-keyboard-source-regression branch from 313375c to 4185094 Compare April 30, 2026 10:03
@Tubbles Tubbles changed the title [rcore_android] Restore gamepad input on multi-class controllers [rcore_android] Restore face-button input on Android gamepads Apr 30, 2026
@Tubbles
Copy link
Copy Markdown
Author

Tubbles commented Apr 30, 2026

It seems like this is also how SDL and Allegro 5 have solved this quirk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant