Add the manufacturer to the joystick name on Mac OS X, for consistency with other drivers

This commit is contained in:
Sam Lantinga 2019-12-10 11:46:22 -08:00
parent 2a161e7add
commit a21f6b7a91
1 changed files with 13 additions and 6 deletions

View File

@ -399,6 +399,8 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
Sint32 vendor = 0; Sint32 vendor = 0;
Sint32 product = 0; Sint32 product = 0;
Sint32 version = 0; Sint32 version = 0;
char manufacturer_string[256];
char product_string[256];
CFTypeRef refCF = NULL; CFTypeRef refCF = NULL;
CFArrayRef array = NULL; CFArrayRef array = NULL;
Uint16 *guid16 = (Uint16 *)pDevice->guid.data; Uint16 *guid16 = (Uint16 *)pDevice->guid.data;
@ -426,13 +428,18 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
pDevice->deviceRef = hidDevice; pDevice->deviceRef = hidDevice;
/* get device name */ /* get device name */
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey)); refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
if (!refCF) { if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
/* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */ manufacturer_string[0] = '\0';
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
} }
if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) { refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product)); if ((!refCF) || (!CFStringGetCString(refCF, product_string, sizeof(product_string), kCFStringEncodingUTF8))) {
SDL_strlcpy(product_string, "Unidentified joystick", sizeof(product_string));
}
if (SDL_strncasecmp(manufacturer_string, product_string, SDL_strlen(manufacturer_string)) == 0) {
SDL_strlcpy(pDevice->product, product_string, sizeof(pDevice->product));
} else {
SDL_snprintf(pDevice->product, sizeof(pDevice->product), "%s %s", manufacturer_string, product_string);
} }
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey)); refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));