Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backends: SDL2: Implement multiple gamepad support
This makes the SDL2 backend work correctly with multiple gamepads. Instead of hard-coding gamepad index 0, we keep a list of all currently available gamepads. When gamepads are added or removed, we update the list accordingly. When processing gamepad input, we then iterate over this list and combine the button and axis state of all gamepads. Note that it's not necessary to enumerate gamepads during initialization of the backend, because SDL automatically sends a `SDL_CONTROLLERDEVICEADDED` event for every gamepad that was already present during initialization of SDL. The main motivation for this change is that I can have multiple gamepads connected to my system and grab any one of them at random, and have ImGui recognize my inputs. Previously, this was not guaranteed, because the gamepad I grabbed might not have index 0. It's also possible now to (for example) use the D-pad on one gamepad and and buttons on another one at the same time, although that seems less useful in practice :) Additionally, we now properly close all previously opened gamepads when shutting down the backend. # Conflicts: # backends/imgui_impl_sdl.cpp
- Loading branch information