|
@@ -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,
|