Skip to content

Commit e62be5f

Browse files
Todd CopeSiegeLord
authored andcommitted
Make 'al_get_joystick_name()' actually return the name of the joystick on MacOS.
1 parent aaae064 commit e62be5f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/macosx/hidjoy.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
CONFIG_STATE cfg_state;
6464
ALLEGRO_JOYSTICK_STATE state;
6565
IOHIDDeviceRef ident;
66+
char * name;
6667
} ALLEGRO_JOYSTICK_OSX;
6768

6869
static IOHIDManagerRef hidManagerRef;
@@ -757,10 +758,25 @@ static bool reconfigure_joysticks(void)
757758
return ret;
758759
}
759760

760-
// FIXME!
761761
static const char *get_joystick_name(ALLEGRO_JOYSTICK *joy_)
762762
{
763-
(void)joy_;
763+
ALLEGRO_JOYSTICK_OSX *joy = (ALLEGRO_JOYSTICK_OSX *)joy_;
764+
CFStringRef str;
765+
766+
str = IOHIDDeviceGetProperty(joy->ident, CFSTR(kIOHIDProductKey));
767+
if (str) {
768+
CFIndex length = CFStringGetLength(str);
769+
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
770+
if (joy->name) {
771+
free(joy->name);
772+
}
773+
joy->name = (char *)malloc(maxSize);
774+
if (joy->name) {
775+
if (CFStringGetCString(str, joy->name, maxSize, kCFStringEncodingUTF8)) {
776+
return joy->name;
777+
}
778+
}
779+
}
764780
return "Joystick";
765781
}
766782

0 commit comments

Comments
 (0)