An idea to change the behavior of SDL_GameControllerGetButton

Hello,
I have a proposal for changing the behavior of SDL_GameControllerGetButton. I’m not an expert with SDL’s code, so maybe I’m missing something and it’s not a good idea, just let me know what you think.

The current code looks something like this.

Uint8
SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
{
    int i;

    if (!gamecontroller)
        return 0;

    for (i = 0; i < gamecontroller->num_bindings; ++i) {
        SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
        if (binding->outputType == SDL_CONTROLLER_BINDTYPE_BUTTON && binding->output.button == button) {
               ...
            } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
                return SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
            } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
                int hat_mask = SDL_JoystickGetHat(gamecontroller->joystick, binding->input.hat.hat);
                return (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
            }
        }
    }
    return SDL_RELEASED;
}

I made a pull request to the controllers database because, for the controller I have, the rightShoulder button was wrong: change "NEXT SNES" right shoulder button from b6 to b5 by tuket · Pull Request #441 · gabomdq/SDL_GameControllerDB · GitHub

It turned out there are two models of the same controller that share the same GUID. For one of them the rightShoulder is “b5” for the other it’s “b6”.

So I immediately thought I could just map both “b5” and “b6” to the same button. But it’s not possible because of the way SDL_GameControllerGetButton is implemented.

I think one way to fix this problem is to, instead of returning the first binding we find, we could consider all of them. For example, we could implement something like this:

...
} else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
    if(SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button))
         return SDL_PRESSED;
}
...

What do you think?

Thanks!