Skip to content

Commit 3f98a54

Browse files
committed
Fix Input.is_joy_known response for SDL joypads
1 parent 9a5d6d1 commit 3f98a54

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

core/input/input.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,16 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, const String &p_
656656
int mapping = fallback_mapping;
657657
// Bypass the mapping system if the joypad's mapping is already handled by its driver
658658
// (for example, the SDL joypad driver).
659-
if (!p_joypad_info.get("mapping_handled", false)) {
659+
if (p_joypad_info.get("mapping_handled", false)) {
660+
js.is_known = true;
661+
} else {
660662
for (int i = 0; i < map_db.size(); i++) {
661663
if (js.uid == map_db[i].uid) {
662664
mapping = i;
665+
if (mapping != fallback_mapping) {
666+
js.is_known = true;
667+
}
668+
break;
663669
}
664670
}
665671
}
@@ -1859,13 +1865,7 @@ void Input::set_fallback_mapping(const String &p_guid) {
18591865

18601866
//platforms that use the remapping system can override and call to these ones
18611867
bool Input::is_joy_known(int p_device) {
1862-
if (joy_names.has(p_device)) {
1863-
int mapping = joy_names[p_device].mapping;
1864-
if (mapping != -1 && mapping != fallback_mapping) {
1865-
return true;
1866-
}
1867-
}
1868-
return false;
1868+
return joy_names.has(p_device) && joy_names[p_device].is_known;
18691869
}
18701870

18711871
String Input::get_joy_guid(int p_device) const {

core/input/input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class Input : public Object {
168168
StringName name;
169169
StringName uid;
170170
bool connected = false;
171+
bool is_known = false;
171172
bool last_buttons[(size_t)JoyButton::MAX] = { false };
172173
float last_axis[(size_t)JoyAxis::MAX] = { 0.0f };
173174
HatMask last_hat = HatMask::CENTER;

drivers/sdl/joypad_sdl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ void JoypadSDL::process_events() {
186186
sdl_instance_id_to_joypad_id.insert(sdl_event.jdevice.which, joy_id);
187187

188188
Dictionary joypad_info;
189-
joypad_info["mapping_handled"] = true; // Skip Godot's mapping system because SDL already handles the joypad's mapping.
189+
// Skip Godot's mapping system if SDL already handles the joypad's mapping.
190+
joypad_info["mapping_handled"] = SDL_IsGamepad(sdl_event.jdevice.which);
190191
joypad_info["raw_name"] = String(SDL_GetJoystickName(joy));
191192
joypad_info["vendor_id"] = itos(SDL_GetJoystickVendor(joy));
192193
joypad_info["product_id"] = itos(SDL_GetJoystickProduct(joy));

0 commit comments

Comments
 (0)