Skip to content

Commit

Permalink
Make 'al_get_joystick_name()' actually return the name of the joystic…
Browse files Browse the repository at this point in the history
…k on MacOS.
  • Loading branch information
Todd Cope authored and SiegeLord committed Aug 6, 2023
1 parent aaae064 commit e62be5f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/macosx/hidjoy.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
CONFIG_STATE cfg_state;
ALLEGRO_JOYSTICK_STATE state;
IOHIDDeviceRef ident;
char * name;
} ALLEGRO_JOYSTICK_OSX;

static IOHIDManagerRef hidManagerRef;
Expand Down Expand Up @@ -757,10 +758,25 @@ static bool reconfigure_joysticks(void)
return ret;
}

// FIXME!
static const char *get_joystick_name(ALLEGRO_JOYSTICK *joy_)
{
(void)joy_;
ALLEGRO_JOYSTICK_OSX *joy = (ALLEGRO_JOYSTICK_OSX *)joy_;
CFStringRef str;

str = IOHIDDeviceGetProperty(joy->ident, CFSTR(kIOHIDProductKey));
if (str) {
CFIndex length = CFStringGetLength(str);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
if (joy->name) {
free(joy->name);
}
joy->name = (char *)malloc(maxSize);
if (joy->name) {
if (CFStringGetCString(str, joy->name, maxSize, kCFStringEncodingUTF8)) {
return joy->name;
}
}
}
return "Joystick";
}

Expand Down

0 comments on commit e62be5f

Please sign in to comment.