Browse Source
Closes eden-emulator/Issue-Reports#8 Closes eden-emulator/Issue-Reports#428 Currently, [Android's input layer](https://android.googlesource.com/platform/frameworks/base.git/+/refs/heads/android16-release/data/keyboards/Vendor_057e_Product_2009.kl#54) doesn't return `KEYCODE_DPAD_*` for the left Joy-Con, we fall back to the scan code in this case, this will also fix most third party Joy-Con controllers. - The scan codes are not reliable and may vary from device to another. I searched for (0x220-0x223) values in the [android repo](https://android.googlesource.com/platform/frameworks/base.git/+/refs/heads/android16-release/data/keyboards) and they all have the same DPAD_* key mapping, so not a big issue just might cause future issues if Google change the mapping in another vendor. I could simply limit the fix to the [left Joy-Con](https://github.com/torvalds/linux/blob/master/drivers/hid/hid-ids.h#L1096-L1105) `if (event.keyCode == 0 && event.device.vendorId == 0x057e && event.device.productId == 0x2006)`. - Auto mapping doesn't work, I'm not very familiar with the JNI Specification, I managed to implement the below workaround, it basically checks if it's the left Joy-Con and add the first four DPAD_* keycodes ```cpp // ./src/input_common/drivers/android.cpp ButtonMapping Android::GetButtonMappingForDevice(const Common::ParamPackage& params) { // ... const char *yuzu_device_name = env->GetStringUTFChars((jstring) env->CallObjectMethod(j_device, Common::Android::GetYuzuDeviceGetName()), &isCopy); const char *switch_left_string_name = "Nintendo Switch Left Joy-Con"; bool is_switch_left = strncmp(yuzu_device_name, switch_left_string_name, strlen(switch_left_string_name)) == 0; std::set<s32> available_keys; for (size_t i = 0; i < keycode_ids.size(); ++i) { if (j_has_keys[i] || (is_switch_left && i <= 3)) { available_keys.insert(keycode_ids[i]); } } // ... } ``` Signed-off-by: crueter <crueter@eden-emu.dev> Authored-by: Anas Bouzid <bouzid.anas.1@gmail.com> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4225 Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: Maufeat <sahyno1996@gmail.com>pull/4227/head
2 changed files with 22 additions and 3 deletions
Loading…
Reference in new issue