Added general remapping of controller manufacturer
authorSam Lantinga <slouken@libsdl.org>
Fri, 13 Dec 2019 16:07:25 -0800
changeset 13341f4c907df37f5
parent 13340 37662e38b645
child 13342 f778fa778ec8
Added general remapping of controller manufacturer
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
src/joystick/hidapi/SDL_hidapijoystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Fri Dec 13 16:07:22 2019 -0800
     1.2 +++ b/src/joystick/SDL_joystick.c	Fri Dec 13 16:07:25 2019 -0800
     1.3 @@ -1165,6 +1165,19 @@
     1.4  }
     1.5  
     1.6  const char *
     1.7 +SDL_GetCustomJoystickManufacturer(const char *manufacturer)
     1.8 +{
     1.9 +    if (manufacturer) {
    1.10 +        if (SDL_strcmp(manufacturer, "Performance Designed Products") == 0) {
    1.11 +            return "PDP";
    1.12 +        } else if (SDL_strcmp(manufacturer, "HORI CO.,LTD") == 0) {
    1.13 +            return "HORI";
    1.14 +        }
    1.15 +    }
    1.16 +    return manufacturer;
    1.17 +}
    1.18 +
    1.19 +const char *
    1.20  SDL_GetCustomJoystickName(Uint16 vendor, Uint16 product)
    1.21  {
    1.22      return GuessControllerName(vendor, product);
     2.1 --- a/src/joystick/SDL_joystick_c.h	Fri Dec 13 16:07:22 2019 -0800
     2.2 +++ b/src/joystick/SDL_joystick_c.h	Fri Dec 13 16:07:25 2019 -0800
     2.3 @@ -52,6 +52,9 @@
     2.4  /* Function to extract information from an SDL joystick GUID */
     2.5  extern void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version);
     2.6  
     2.7 +/* Function to get a custom name for a controller manufacturer, if it's available */
     2.8 +extern const char *SDL_GetCustomJoystickManufacturer(const char *manufacturer);
     2.9 +
    2.10  /* Function to get a custom name for a controller, if it's available */
    2.11  extern const char *SDL_GetCustomJoystickName(Uint16 vendor, Uint16 product);
    2.12  
     3.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Fri Dec 13 16:07:22 2019 -0800
     3.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Fri Dec 13 16:07:25 2019 -0800
     3.3 @@ -610,6 +610,7 @@
     3.4          }
     3.5      }
     3.6      if (!device->name && info->manufacturer_string && info->product_string) {
     3.7 +        const char *manufacturer_remapped;
     3.8          char *manufacturer_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
     3.9          char *product_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
    3.10          if (!manufacturer_string && !product_string) {
    3.11 @@ -621,15 +622,15 @@
    3.12                  product_string = SDL_iconv_string("UTF-8", "UCS-4-INTERNAL", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
    3.13              }
    3.14          }
    3.15 -        if (manufacturer_string && product_string) {
    3.16 -            size_t name_size;
    3.17  
    3.18 -            if (SDL_strcmp(manufacturer_string, "Performance Designed Products") == 0) {
    3.19 -                /* Shorten this so controller names are more manageable */
    3.20 -                SDL_memcpy(manufacturer_string, "PDP", 4);
    3.21 -            }
    3.22 +        manufacturer_remapped = SDL_GetCustomJoystickManufacturer(manufacturer_string);
    3.23 +        if (manufacturer_remapped != manufacturer_string) {
    3.24 +            SDL_free(manufacturer_string);
    3.25 +            manufacturer_string = SDL_strdup(manufacturer_remapped);
    3.26 +        }
    3.27  
    3.28 -            name_size = (SDL_strlen(manufacturer_string) + 1 + SDL_strlen(product_string) + 1);
    3.29 +        if (manufacturer_string && product_string) {
    3.30 +            size_t name_size = (SDL_strlen(manufacturer_string) + 1 + SDL_strlen(product_string) + 1);
    3.31              device->name = (char *)SDL_malloc(name_size);
    3.32              if (device->name) {
    3.33                  if (SDL_strncasecmp(manufacturer_string, product_string, SDL_strlen(manufacturer_string)) == 0) {