Add the manufacturer to the joystick name on Mac OS X, for consistency with other drivers
authorSam Lantinga <slouken@libsdl.org>
Tue, 10 Dec 2019 11:46:22 -0800
changeset 133282bbe6560b557
parent 13327 4f5f7a1ed7cc
child 13329 732a469df95c
Add the manufacturer to the joystick name on Mac OS X, for consistency with other drivers
src/joystick/darwin/SDL_sysjoystick.c
     1.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Tue Dec 10 11:30:56 2019 -0800
     1.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Tue Dec 10 11:46:22 2019 -0800
     1.3 @@ -399,6 +399,8 @@
     1.4      Sint32 vendor = 0;
     1.5      Sint32 product = 0;
     1.6      Sint32 version = 0;
     1.7 +    char manufacturer_string[256];
     1.8 +    char product_string[256];
     1.9      CFTypeRef refCF = NULL;
    1.10      CFArrayRef array = NULL;
    1.11      Uint16 *guid16 = (Uint16 *)pDevice->guid.data;
    1.12 @@ -426,13 +428,18 @@
    1.13      pDevice->deviceRef = hidDevice;
    1.14  
    1.15      /* get device name */
    1.16 +    refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
    1.17 +    if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
    1.18 +        manufacturer_string[0] = '\0';
    1.19 +    }
    1.20      refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
    1.21 -    if (!refCF) {
    1.22 -        /* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
    1.23 -        refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
    1.24 +    if ((!refCF) || (!CFStringGetCString(refCF, product_string, sizeof(product_string), kCFStringEncodingUTF8))) {
    1.25 +        SDL_strlcpy(product_string, "Unidentified joystick", sizeof(product_string));
    1.26      }
    1.27 -    if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
    1.28 -        SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
    1.29 +    if (SDL_strncasecmp(manufacturer_string, product_string, SDL_strlen(manufacturer_string)) == 0) {
    1.30 +        SDL_strlcpy(pDevice->product, product_string, sizeof(pDevice->product));
    1.31 +    } else {
    1.32 +        SDL_snprintf(pDevice->product, sizeof(pDevice->product), "%s %s", manufacturer_string, product_string);
    1.33      }
    1.34  
    1.35      refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));