Don't overwrite the default binding when changing the binding for a controller that was using the default.
authorSam Lantinga <slouken@libsdl.org>
Wed, 05 Sep 2018 12:16:01 -0700
changeset 121748be6b6e98c3c
parent 12173 e26ef3c19774
child 12175 0061cfbdd0c5
Don't overwrite the default binding when changing the binding for a controller that was using the default.
src/joystick/SDL_gamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Wed Sep 05 11:24:23 2018 -0700
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Wed Sep 05 12:16:01 2018 -0700
     1.3 @@ -422,7 +422,7 @@
     1.4  /*
     1.5   * Helper function to scan the mappings database for a controller with the specified GUID
     1.6   */
     1.7 -static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
     1.8 +static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid, SDL_bool exact_match)
     1.9  {
    1.10      ControllerMapping_t *pSupportedController = s_pSupportedControllers;
    1.11      while (pSupportedController) {
    1.12 @@ -431,16 +431,18 @@
    1.13          }
    1.14          pSupportedController = pSupportedController->next;
    1.15      }
    1.16 -    if (guid->data[14] == 'h') {
    1.17 -        /* This is a HIDAPI device */
    1.18 -        return s_pHIDAPIMapping;
    1.19 +    if (!exact_match) {
    1.20 +        if (guid->data[14] == 'h') {
    1.21 +            /* This is a HIDAPI device */
    1.22 +            return s_pHIDAPIMapping;
    1.23 +        }
    1.24 +#if SDL_JOYSTICK_XINPUT
    1.25 +        if (guid->data[14] == 'x') {
    1.26 +            /* This is an XInput device */
    1.27 +            return s_pXInputMapping;
    1.28 +        }
    1.29 +#endif
    1.30      }
    1.31 -#if SDL_JOYSTICK_XINPUT
    1.32 -    if (guid->data[14] == 'x') {
    1.33 -        /* This is an XInput device */
    1.34 -        return s_pXInputMapping;
    1.35 -    }
    1.36 -#endif
    1.37      return NULL;
    1.38  }
    1.39  
    1.40 @@ -836,7 +838,7 @@
    1.41          return NULL;
    1.42      }
    1.43  
    1.44 -    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
    1.45 +    pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID, SDL_TRUE);
    1.46      if (pControllerMapping) {
    1.47          /* Only overwrite the mapping if the priority is the same or higher. */
    1.48          if (pControllerMapping->priority <= priority) {
    1.49 @@ -1005,7 +1007,7 @@
    1.50  {
    1.51      ControllerMapping_t *mapping;
    1.52  
    1.53 -    mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
    1.54 +    mapping = SDL_PrivateGetControllerMappingForGUID(&guid, SDL_FALSE);
    1.55  #ifdef __LINUX__
    1.56      if (!mapping && name) {
    1.57          if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
    1.58 @@ -1244,7 +1246,7 @@
    1.59  SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
    1.60  {
    1.61      char *pMappingString = NULL;
    1.62 -    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
    1.63 +    ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid, SDL_FALSE);
    1.64      if (mapping) {
    1.65          char pchGUID[33];
    1.66          size_t needed;