Joystick mapping support for MacOS using SDL2 #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability to map joystick inputs on MacOS by adding an SDL2 backend to match Mednafen.
The base implementation uses SDL_Joystick like Mednafen does but I also have a somewhat experimental path that opportunistically uses SDL_GameController when a mapping is available, this is mainly to work around having no real way to identify triggers and as a side benefit mappings can trivially have nice names that adapt to whichever controller type the gamecontroller subsystem identifies.
In spite of that the gamecontroller path is relatively complex due to having to parse the mapping manually (all of the real functionality for exploring mappings is all private) and also currently makes a few assumptions such as the polarity of the triggers and devices marked as mapped not having more buttons and/or axes than gamecontroller can express.
A better option with SDL_Joystick may be to store initial axis positions when the user starts mapping and deduce triggers and polarity from there. Currently there is no hook as far as I can tell for a joystick impl to know when the user begins mapping and I didn't look into hacking one in, OTOH SDL_JoystickGetAxisInitialState is unreliable because it just records the state of axes on launch and when the user starts the program accidentally depressing a trigger or twiddling a stick they're going to be in for a nasty surprise.
This has been tested on Mac with a handful of different PS and Xbox controllers and they all seem to be mappable, the code should work on other Unix though it wouldn't be useful on platforms like Linux that already have a provider. I'd appreciate all the testing this can get though especially with more exotic controllers than I have access to.