diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-08-03 22:37:45 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-08-03 22:37:45 +0200 |
commit | 1610fc2ae78776fbeed8f5eb16781e66c372f051 (patch) | |
tree | 1b8994813534e8564c71500d1b178cbafeac2c86 /platform | |
parent | e4b8dc81b8d06d2e263b9865017c48fe5d98c287 (diff) | |
parent | 3aa340d0814ab001075f707d8c1bf1f77e22a561 (diff) | |
download | redot-engine-1610fc2ae78776fbeed8f5eb16781e66c372f051.tar.gz |
Merge pull request #78539 from EIREXE/input-info
Add the ability to get per-platform information for joypads
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linuxbsd/joypad_linux.cpp | 25 | ||||
-rw-r--r-- | platform/windows/joypad_windows.cpp | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp index 342cff82e9..5d636240b7 100644 --- a/platform/linuxbsd/joypad_linux.cpp +++ b/platform/linuxbsd/joypad_linux.cpp @@ -56,6 +56,14 @@ static const char *ignore_str = "/dev/input/js"; #endif +// On Linux with Steam Input Xbox 360 devices have an index appended to their device name, this index is +// the Steam Input gamepad index +#define VALVE_GAMEPAD_NAME_PREFIX "Microsoft X-Box 360 pad " +// IDs used by Steam Input virtual controllers. +// See https://partner.steamgames.com/doc/features/steam_controller/steam_input_gamepad_emulation_bestpractices +#define VALVE_GAMEPAD_VID 0x28DE +#define VALVE_GAMEPAD_PID 0x11FF + JoypadLinux::Joypad::~Joypad() { for (int i = 0; i < MAX_ABS; i++) { if (abs_info[i]) { @@ -411,8 +419,23 @@ void JoypadLinux::open_joypad(const char *p_path) { setup_joypad_properties(joypad); sprintf(uid, "%04x%04x", BSWAP16(inpid.bustype), 0); if (inpid.vendor && inpid.product && inpid.version) { + Dictionary joypad_info; + joypad_info["vendor_id"] = inpid.vendor; + joypad_info["product_id"] = inpid.product; + joypad_info["raw_name"] = name; + sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor, 0, product, 0, version, 0); - input->joy_connection_changed(joy_num, true, name, uid); + + if (inpid.vendor == VALVE_GAMEPAD_VID && inpid.product == VALVE_GAMEPAD_PID) { + if (name.begins_with(VALVE_GAMEPAD_NAME_PREFIX)) { + String idx_str = name.substr(strlen(VALVE_GAMEPAD_NAME_PREFIX)); + if (idx_str.is_valid_int()) { + joypad_info["steam_input_index"] = idx_str.to_int(); + } + } + } + + input->joy_connection_changed(joy_num, true, name, uid, joypad_info); } else { String uidname = uid; int uidlen = MIN(name.length(), 11); diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index 487cb56ba0..0ac6c2c8b0 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -318,7 +318,9 @@ void JoypadWindows::probe_joypads() { x_joypads[i].ff_end_timestamp = 0; x_joypads[i].vibrating = false; attached_joypads[id] = true; - input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__"); + Dictionary joypad_info; + joypad_info["xinput_index"] = (int)i; + input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__", joypad_info); } } else if (x_joypads[i].attached) { x_joypads[i].attached = false; |