Commit 79859cb3 authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

dinput: OS/X joystick: Sort buttons based on usage as some controllers report…

dinput: OS/X joystick: Sort buttons based on usage as some controllers report the buttons out of order. Makes the xbox 360 controller button mapping more logical.
parent 4da865f3
...@@ -284,6 +284,27 @@ static int get_osx_device_name(int id, char *name, int length) ...@@ -284,6 +284,27 @@ static int get_osx_device_name(int id, char *name, int length)
return 0; return 0;
} }
static void insert_sort_button(int header, IOHIDElementRef tIOHIDElementRef,
CFMutableArrayRef elementCFArrayRef, int index,
int target)
{
IOHIDElementRef targetElement;
int usage;
CFArraySetValueAtIndex(elementCFArrayRef, header+index, NULL);
targetElement = ( IOHIDElementRef ) CFArrayGetValueAtIndex( elementCFArrayRef, header+target);
if (targetElement == NULL)
{
CFArraySetValueAtIndex(elementCFArrayRef, header+target,tIOHIDElementRef);
return;
}
usage = IOHIDElementGetUsage( targetElement );
usage --; /* usage 1 based index */
insert_sort_button(header, targetElement, elementCFArrayRef, target, usage);
CFArraySetValueAtIndex(elementCFArrayRef, header+target,tIOHIDElementRef);
}
static void get_osx_device_elements(JoystickImpl *device, int axis_map[8]) static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
{ {
IOHIDDeviceRef tIOHIDDeviceRef; IOHIDDeviceRef tIOHIDDeviceRef;
...@@ -382,6 +403,18 @@ static void get_osx_device_elements(JoystickImpl *device, int axis_map[8]) ...@@ -382,6 +403,18 @@ static void get_osx_device_elements(JoystickImpl *device, int axis_map[8])
device->generic.devcaps.dwAxes = axes; device->generic.devcaps.dwAxes = axes;
device->generic.devcaps.dwButtons = buttons; device->generic.devcaps.dwButtons = buttons;
device->generic.devcaps.dwPOVs = povs; device->generic.devcaps.dwPOVs = povs;
/* Sort buttons into correct order */
for (buttons = 0; buttons < device->generic.devcaps.dwButtons; buttons++)
{
IOHIDElementRef tIOHIDElementRef = ( IOHIDElementRef ) CFArrayGetValueAtIndex( device->elementCFArrayRef, axes+povs+buttons);
uint32_t usage = IOHIDElementGetUsage( tIOHIDElementRef );
usage --; /* usage is 1 indexed we need 0 indexed */
if (usage == buttons)
continue;
insert_sort_button(axes+povs, tIOHIDElementRef, device->elementCFArrayRef,buttons,usage);
}
} }
static void get_osx_device_elements_props(JoystickImpl *device) static void get_osx_device_elements_props(JoystickImpl *device)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment