mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Prevent double input events on gamepad when running through steam input
During GDC and general testing on Steam Deck units, we found that single gamepads would often register inputs twice under certain circumstances. This was caused by SteamInput creating a new virtual device, which Godot registers as a second gamepad. This resulted in two gamepad devices reporting the same button presses, often leading to buggy input response on games with no multi-device logic and other-wise could cause intended Steam rebindings to not work as intended (for example, swapping o and x on a playstation pad if that feature isn't supported by the game.) SDL gets around this by taking in a list of devices that are to be ignored. When valve sees a controller that wants to be rebound via SteamInput, they push a new VID/PID entry onto the environment variable `SDL_GAMECONTROLLER_IGNORE_DEVICES` for the original gamepad so that all game inputs can be read from the virtual gamepad instead. This leverages the same logic as we are already using SDL gamepad related HID mappings.
This commit is contained in:
@@ -113,6 +113,7 @@ void Input::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &Input::get_joy_axis);
|
||||
ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &Input::get_joy_name);
|
||||
ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &Input::get_joy_guid);
|
||||
ClassDB::bind_method(D_METHOD("should_ignore_device", "vendor_id", "product_id"), &Input::should_ignore_device);
|
||||
ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads);
|
||||
ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
|
||||
ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
|
||||
@@ -1498,6 +1499,11 @@ String Input::get_joy_guid(int p_device) const {
|
||||
return joy_names[p_device].uid;
|
||||
}
|
||||
|
||||
bool Input::should_ignore_device(int p_vendor_id, int p_product_id) const {
|
||||
uint32_t full_id = (((uint32_t)p_vendor_id) << 16) | ((uint16_t)p_product_id);
|
||||
return ignored_device_ids.has(full_id);
|
||||
}
|
||||
|
||||
TypedArray<int> Input::get_connected_joypads() {
|
||||
TypedArray<int> ret;
|
||||
HashMap<int, Joypad>::Iterator elem = joy_names.begin();
|
||||
@@ -1542,6 +1548,27 @@ Input::Input() {
|
||||
}
|
||||
}
|
||||
|
||||
String env_ignore_devices = OS::get_singleton()->get_environment("SDL_GAMECONTROLLER_IGNORE_DEVICES");
|
||||
if (!env_ignore_devices.is_empty()) {
|
||||
Vector<String> entries = env_ignore_devices.split(",");
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
Vector<String> vid_pid = entries[i].split("/");
|
||||
|
||||
if (vid_pid.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
print_verbose(vformat("Device Ignored -- Vendor: %s Product: %s", vid_pid[0], vid_pid[1]));
|
||||
const uint16_t vid_unswapped = vid_pid[0].hex_to_int();
|
||||
const uint16_t pid_unswapped = vid_pid[1].hex_to_int();
|
||||
const uint16_t vid = BSWAP16(vid_unswapped);
|
||||
const uint16_t pid = BSWAP16(pid_unswapped);
|
||||
|
||||
uint32_t full_id = (((uint32_t)vid) << 16) | ((uint16_t)pid);
|
||||
ignored_device_ids.insert(full_id);
|
||||
}
|
||||
}
|
||||
|
||||
legacy_just_pressed_behavior = GLOBAL_DEF("input_devices/compatibility/legacy_just_pressed_behavior", false);
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
// Always use standard behavior in the editor.
|
||||
|
||||
Reference in New Issue
Block a user