Skip to content

Commit 08fb2e6

Browse files
committed
Merge pull request godotengine#111503 from JestemStefan/fix_111176
Fix `Input.is_joy_known` response for SDL joypads
2 parents fdcc29d + 3f98a54 commit 08fb2e6

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
}
@@ -1877,13 +1883,7 @@ void Input::set_fallback_mapping(const String &p_guid) {
18771883

18781884
//platforms that use the remapping system can override and call to these ones
18791885
bool Input::is_joy_known(int p_device) {
1880-
if (joy_names.has(p_device)) {
1881-
int mapping = joy_names[p_device].mapping;
1882-
if (mapping != -1 && mapping != fallback_mapping) {
1883-
return true;
1884-
}
1885-
}
1886-
return false;
1886+
return joy_names.has(p_device) && joy_names[p_device].is_known;
18871887
}
18881888

18891889
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
@@ -177,6 +177,7 @@ class Input : public Object {
177177
StringName name;
178178
StringName uid;
179179
bool connected = false;
180+
bool is_known = false;
180181
bool last_buttons[(size_t)JoyButton::MAX] = { false };
181182
float last_axis[(size_t)JoyAxis::MAX] = { 0.0f };
182183
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)