Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GameControllerDB mappings before initializing the SDL gamecontroller subsystem #799

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

briaguya-ai
Copy link
Collaborator

controllers that don't have built in mappings and rely on gamecontrollerdb.txt mappings were firing SDL_JOYDEVICEADDED events at boot but not SDL_CONTROLLERDEVICEADDED events

The documentation for SDL_ControllerDeviceEvent states:

Joysticks that are supported game controllers receive both an SDL_JoyDeviceEvent and an SDL_ControllerDeviceEvent.

SDL will send CONTROLLERDEVICEADDED events for joysticks that are already plugged in during SDL_Init() and are recognized as game controllers.

i looked a bit and found we weren't loading gamecontrollerdb.txt until after initializing the game controller subsystem, so the "already plugged in" events were firing when the devices weren't recognized as game controllers yet.

this PR ensures SDL_GameControllerAddMappingsFromFile happens before the subsystem is initialized. i have verified this makes it so we get SDL_CONTROLLERDEVICEADDED events on boot.

relevant discourse post from someone with a similar issue: https://discourse.libsdl.org/t/deviced-added-events-for-devices-plugged-in-at-game-start/55039

@briaguya-ai
Copy link
Collaborator Author

confirmed working by cobeck on discord

@briaguya-ai briaguya-ai marked this pull request as ready for review January 25, 2025 20:38
@Kenix3 Kenix3 merged commit d60e847 into Kenix3:main Jan 26, 2025
5 checks passed
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