1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Fix Input.get_joy_info() regression

SDL input driver did not have the "xinput_index", "raw_name", "vendor_id" and "product_id" fields for this method and exposed an additional, essentially useless for the users "mapping_handled" field. This commit fixes these issues.
This commit is contained in:
Nintorch
2025-08-29 14:22:56 +05:00
parent efb40c1524
commit f28acf97d0
3 changed files with 25 additions and 10 deletions

View File

@@ -128,11 +128,12 @@ void JoypadSDL::process_events() {
print_error("A new joypad was attached but couldn't allocate a new id for it because joypad limit was reached.");
} else {
SDL_Joystick *joy = nullptr;
SDL_Gamepad *gamepad = nullptr;
String device_name;
// Gamepads must be opened with SDL_OpenGamepad to get their special remapped events
if (SDL_IsGamepad(sdl_event.jdevice.which)) {
SDL_Gamepad *gamepad = SDL_OpenGamepad(sdl_event.jdevice.which);
gamepad = SDL_OpenGamepad(sdl_event.jdevice.which);
ERR_CONTINUE_MSG(!gamepad,
vformat("Error opening gamepad at index %d: %s", sdl_event.jdevice.which, SDL_GetError()));
@@ -164,9 +165,22 @@ void JoypadSDL::process_events() {
sdl_instance_id_to_joypad_id.insert(sdl_event.jdevice.which, joy_id);
// Skip Godot's mapping system because SDL already handles the joypad's mapping
Dictionary joypad_info;
joypad_info["mapping_handled"] = true;
joypad_info["mapping_handled"] = true; // Skip Godot's mapping system because SDL already handles the joypad's mapping.
joypad_info["raw_name"] = String(SDL_GetJoystickName(joy));
joypad_info["vendor_id"] = itos(SDL_GetJoystickVendor(joy));
joypad_info["product_id"] = itos(SDL_GetJoystickProduct(joy));
const uint64_t steam_handle = SDL_GetGamepadSteamHandle(gamepad);
if (steam_handle != 0) {
joypad_info["steam_input_index"] = itos(steam_handle);
}
const int player_index = SDL_GetJoystickPlayerIndex(joy);
if (player_index >= 0) {
// For XInput controllers SDL_GetJoystickPlayerIndex returns the XInput user index.
joypad_info["xinput_index"] = itos(player_index);
}
Input::get_singleton()->joy_connection_changed(
joy_id,