Added general remapping of controller manufacturer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index f2e4a67..81f0ebf 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1165,6 +1165,19 @@ void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *prod
}
const char *
+SDL_GetCustomJoystickManufacturer(const char *manufacturer)
+{
+ if (manufacturer) {
+ if (SDL_strcmp(manufacturer, "Performance Designed Products") == 0) {
+ return "PDP";
+ } else if (SDL_strcmp(manufacturer, "HORI CO.,LTD") == 0) {
+ return "HORI";
+ }
+ }
+ return manufacturer;
+}
+
+const char *
SDL_GetCustomJoystickName(Uint16 vendor, Uint16 product)
{
return GuessControllerName(vendor, product);
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index 41d797c..cf3dece 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -52,6 +52,9 @@ extern int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id);
/* Function to extract information from an SDL joystick GUID */
extern void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version);
+/* Function to get a custom name for a controller manufacturer, if it's available */
+extern const char *SDL_GetCustomJoystickManufacturer(const char *manufacturer);
+
/* Function to get a custom name for a controller, if it's available */
extern const char *SDL_GetCustomJoystickName(Uint16 vendor, Uint16 product);
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 4789696..328a84c 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -610,6 +610,7 @@ HIDAPI_AddDevice(struct hid_device_info *info)
}
}
if (!device->name && info->manufacturer_string && info->product_string) {
+ const char *manufacturer_remapped;
char *manufacturer_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->manufacturer_string, (SDL_wcslen(info->manufacturer_string)+1)*sizeof(wchar_t));
char *product_string = SDL_iconv_string("UTF-8", "WCHAR_T", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
if (!manufacturer_string && !product_string) {
@@ -621,15 +622,15 @@ HIDAPI_AddDevice(struct hid_device_info *info)
product_string = SDL_iconv_string("UTF-8", "UCS-4-INTERNAL", (char*)info->product_string, (SDL_wcslen(info->product_string)+1)*sizeof(wchar_t));
}
}
- if (manufacturer_string && product_string) {
- size_t name_size;
- if (SDL_strcmp(manufacturer_string, "Performance Designed Products") == 0) {
- /* Shorten this so controller names are more manageable */
- SDL_memcpy(manufacturer_string, "PDP", 4);
- }
+ manufacturer_remapped = SDL_GetCustomJoystickManufacturer(manufacturer_string);
+ if (manufacturer_remapped != manufacturer_string) {
+ SDL_free(manufacturer_string);
+ manufacturer_string = SDL_strdup(manufacturer_remapped);
+ }
- name_size = (SDL_strlen(manufacturer_string) + 1 + SDL_strlen(product_string) + 1);
+ if (manufacturer_string && product_string) {
+ size_t name_size = (SDL_strlen(manufacturer_string) + 1 + SDL_strlen(product_string) + 1);
device->name = (char *)SDL_malloc(name_size);
if (device->name) {
if (SDL_strncasecmp(manufacturer_string, product_string, SDL_strlen(manufacturer_string)) == 0) {