Skip to content

Small GameInput joystick backend improvements#15173

Merged
slouken merged 1 commit intolibsdl-org:mainfrom
Nintorch:gameinput-improvements
Mar 9, 2026
Merged

Small GameInput joystick backend improvements#15173
slouken merged 1 commit intolibsdl-org:mainfrom
Nintorch:gameinput-improvements

Conversation

@Nintorch
Copy link
Copy Markdown
Contributor

@Nintorch Nintorch commented Mar 6, 2026

Description

While making a PR for Godot to use GameInput ( godotengine/godot#116055 ) I had to make small changes to the SDL GameInput joystick backend for it to not cause regressions in Godot:

  • GUID compatibility with DirectInput joystick mappings if the controller is not a gamepad, i.e. GAMEINPUT_InternalIsGamepad() returns false
  • Fallback to DirectInput/XInput for currently unsupported devices (the ones that are neither gamepads nor controllers, I'm not sure if that's possible, but maybe racing wheels and other device subtypes would count (?) and the ones with force feedback if both SDL_JOYSTICK_DINPUT and SDL_HAPTIC_DINPUT are defined and enabled via hints)
  • DirectInput controller opening is skipped if it can be handled with GameInput (I observed that sometimes when a DirectInput controller is connected, it first gets recognized by DirectInput, after that it gets recognized by GameInput, and then the DirectInput one is disconnected, resulting in the controller having a player ID of 1 instead of 0) We will need to think of a different solution.
  • The driver also checks for SDL_ShouldIgnoreJoystick() just in case

One more small improvement is the addition of device subtypes, it would be more useful when proper reading of other device subtypes is added, so I can remove this one if it's not desired at the moment.

Please let me know if these changes are good for SDL. :D

Existing Issue(s)

I couldn't find any.

@Nintorch Nintorch force-pushed the gameinput-improvements branch 2 times, most recently from 64d3e4d to 969a2ec Compare March 6, 2026 13:51
@Nintorch Nintorch force-pushed the gameinput-improvements branch from 969a2ec to e39c79c Compare March 9, 2026 09:16
@Nintorch Nintorch force-pushed the gameinput-improvements branch from e39c79c to 5cf464d Compare March 9, 2026 15:47
CHECK(!SDL_ShouldIgnoreJoystick(vendor, product, version, product_string));
CHECK(!SDL_JoystickHandledByAnotherDriver(&SDL_WINDOWS_JoystickDriver, vendor, product, version, product_string));

#ifdef SDL_JOYSTICK_GAMEINPUT
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory if GameInput picks up the controller, SDL_JoystickHandledByAnotherDriver() will return true and it won't show up for DirectInput. Is the issue that the DirectInput enumeration happens before the GameInput connection callback?

In general we don't want the logic here, since there are lots of controllers which are supported by DirectInput, but don't show up in GameInput.

Copy link
Copy Markdown
Contributor Author

@Nintorch Nintorch Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, yes, because after I added this piece of code I couldn't reproduce the issue anymore.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, well we can't accept this change as-is, because it will break support for lots of other controllers that don't have GameInput support yet.

In the long run I would like to make the drivers dynamically override each other as controllers are detected, but that's a much larger change and some other bandaid would be welcome in the meantime.

My practical solution has been not to use GameInput because it (currently) doesn't provide any advantage over existing backends.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this change, we can think about the solution for the issue later!
I'm making the PR for Godot to support GameInput to properly support more than 4 XInput controllers, that's more or less the only advantage of GameInput for us, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, would it be a good idea to ignore all non-gamepad controllers in GameInput backend if DInput/XInput backends are enabled?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, probably. There is similar logic in the rawinput driver to do this already.

This PR includes small improvements to the GameInput joystick backend:
- Device subtypes
- Compatibility with DirectInput joystick mappings (if the controller is not a gamepad, i.e. `GAMEINPUT_InternalIsGamepad()` returns `false`)
- Fallback to DirectInput/XInput for currently unsupported devices (force feedback ones and the ones that are neither gamepads nor controllers, I'm not sure if that's possible, but maybe racing wheels and other device subtypes would count?)
@Nintorch Nintorch force-pushed the gameinput-improvements branch from 5cf464d to 49fe013 Compare March 9, 2026 18:07
@slouken slouken merged commit 0138843 into libsdl-org:main Mar 9, 2026
45 checks passed
@slouken
Copy link
Copy Markdown
Collaborator

slouken commented Mar 9, 2026

Okay, merged for 3.4.4!

@slouken slouken added this to the 3.4.4 milestone Mar 9, 2026
@Nintorch Nintorch deleted the gameinput-improvements branch March 9, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants