Skip to content

Commit 52a5644

Browse files
committed
Merge pull request #108214 from Nintorch/fix-joypad-vendor-product
Fix `Input.get_joy_info()` regression after the SDL input driver PR
2 parents cbed98c + f28acf9 commit 52a5644

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

core/input/input.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, const String &p_
663663
}
664664
}
665665
}
666+
// We don't want this setting to be exposed to the user, because it's not very useful outside of this method.
667+
js.info.erase("mapping_handled");
668+
666669
_set_joypad_mapping(js, mapping);
667670
} else {
668671
js.connected = false;

doc/classes/Input.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,14 @@
130130
<param index="0" name="device" type="int" />
131131
<description>
132132
Returns a dictionary with extra platform-specific information about the device, e.g. the raw gamepad name from the OS or the Steam Input index.
133-
On Windows, the dictionary contains the following fields:
134-
[code]xinput_index[/code]: The index of the controller in the XInput system. Undefined for DirectInput devices.
135-
[code]vendor_id[/code]: The USB vendor ID of the device.
136-
[code]product_id[/code]: The USB product ID of the device.
137-
On Linux:
138-
[code]raw_name[/code]: The name of the controller as it came from the OS, before getting renamed by the godot controller database.
133+
On Windows, Linux, and macOS, the dictionary contains the following fields:
134+
[code]raw_name[/code]: The name of the controller as it came from the OS, before getting renamed by the controller database.
139135
[code]vendor_id[/code]: The USB vendor ID of the device.
140136
[code]product_id[/code]: The USB product ID of the device.
141137
[code]steam_input_index[/code]: The Steam Input gamepad index, if the device is not a Steam Input device this key won't be present.
142-
[b]Note:[/b] The returned dictionary is always empty on Web, iOS, Android, and macOS.
138+
On Windows, the dictionary can have an additional field:
139+
[code]xinput_index[/code]: The index of the controller in the XInput system. This key won't be present for devices not handled by XInput.
140+
[b]Note:[/b] The returned dictionary is always empty on Android, iOS, visionOS, and Web.
143141
</description>
144142
</method>
145143
<method name="get_joy_name">

drivers/sdl/joypad_sdl.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ void JoypadSDL::process_events() {
144144
print_error("A new joypad was attached but couldn't allocate a new id for it because joypad limit was reached.");
145145
} else {
146146
SDL_Joystick *joy = nullptr;
147+
SDL_Gamepad *gamepad = nullptr;
147148
String device_name;
148149

149150
// Gamepads must be opened with SDL_OpenGamepad to get their special remapped events
150151
if (SDL_IsGamepad(sdl_event.jdevice.which)) {
151-
SDL_Gamepad *gamepad = SDL_OpenGamepad(sdl_event.jdevice.which);
152+
gamepad = SDL_OpenGamepad(sdl_event.jdevice.which);
152153

153154
ERR_CONTINUE_MSG(!gamepad,
154155
vformat("Error opening gamepad at index %d: %s", sdl_event.jdevice.which, SDL_GetError()));
@@ -180,9 +181,22 @@ void JoypadSDL::process_events() {
180181

181182
sdl_instance_id_to_joypad_id.insert(sdl_event.jdevice.which, joy_id);
182183

183-
// Skip Godot's mapping system because SDL already handles the joypad's mapping
184184
Dictionary joypad_info;
185-
joypad_info["mapping_handled"] = true;
185+
joypad_info["mapping_handled"] = true; // Skip Godot's mapping system because SDL already handles the joypad's mapping.
186+
joypad_info["raw_name"] = String(SDL_GetJoystickName(joy));
187+
joypad_info["vendor_id"] = itos(SDL_GetJoystickVendor(joy));
188+
joypad_info["product_id"] = itos(SDL_GetJoystickProduct(joy));
189+
190+
const uint64_t steam_handle = SDL_GetGamepadSteamHandle(gamepad);
191+
if (steam_handle != 0) {
192+
joypad_info["steam_input_index"] = itos(steam_handle);
193+
}
194+
195+
const int player_index = SDL_GetJoystickPlayerIndex(joy);
196+
if (player_index >= 0) {
197+
// For XInput controllers SDL_GetJoystickPlayerIndex returns the XInput user index.
198+
joypad_info["xinput_index"] = itos(player_index);
199+
}
186200

187201
Input::get_singleton()->joy_connection_changed(
188202
joy_id,

0 commit comments

Comments
 (0)