Skip to content

Commit

Permalink
Add the manufacturer to the joystick name on Mac OS X, for consistenc…
Browse files Browse the repository at this point in the history
…y with other drivers
  • Loading branch information
slouken committed Dec 10, 2019
1 parent 2a161e7 commit a21f6b7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -399,6 +399,8 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
Sint32 vendor = 0;
Sint32 product = 0;
Sint32 version = 0;
char manufacturer_string[256];
char product_string[256];
CFTypeRef refCF = NULL;
CFArrayRef array = NULL;
Uint16 *guid16 = (Uint16 *)pDevice->guid.data;
Expand Down Expand Up @@ -426,13 +428,18 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
pDevice->deviceRef = hidDevice;

/* get device name */
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
if ((!refCF) || (!CFStringGetCString(refCF, manufacturer_string, sizeof(manufacturer_string), kCFStringEncodingUTF8))) {
manufacturer_string[0] = '\0';
}
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
if (!refCF) {
/* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
if ((!refCF) || (!CFStringGetCString(refCF, product_string, sizeof(product_string), kCFStringEncodingUTF8))) {
SDL_strlcpy(product_string, "Unidentified joystick", sizeof(product_string));
}
if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
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));
Expand Down

0 comments on commit a21f6b7

Please sign in to comment.