mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
set hid device registration deterministic (sorting by ascending location_id), this solve the issue where game with same vid and pid where sometime swapped by the OS
This commit is contained in:
parent
3fe6ecbce7
commit
82e2cc7c73
@ -474,6 +474,12 @@ static uint16_t iohidmanager_hid_device_get_product_id(IOHIDDeviceRef device)
|
|||||||
CFSTR(kIOHIDProductIDKey));
|
CFSTR(kIOHIDProductIDKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t iohidmanager_hid_device_get_location_id(IOHIDDeviceRef device)
|
||||||
|
{
|
||||||
|
return iohidmanager_hid_device_get_int_property(device,
|
||||||
|
CFSTR(kIOHIDLocationIDKey));
|
||||||
|
}
|
||||||
|
|
||||||
static void iohidmanager_hid_device_get_product_string(
|
static void iohidmanager_hid_device_get_product_string(
|
||||||
IOHIDDeviceRef device, char *buf, size_t len)
|
IOHIDDeviceRef device, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
@ -501,8 +507,8 @@ static void iohidmanager_hid_device_add_autodetect(unsigned idx,
|
|||||||
RARCH_LOG("Port %d: %s.\n", idx, device_name);
|
RARCH_LOG("Port %d: %s.\n", idx, device_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
static void iohidmanager_hid_device_add(IOHIDDeviceRef device, iohidmanager_hid_t* hid)
|
||||||
void* sender, IOHIDDeviceRef device)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
IOReturn ret;
|
IOReturn ret;
|
||||||
@ -516,8 +522,6 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
|
|||||||
apple_input_rec_t *tmp = NULL;
|
apple_input_rec_t *tmp = NULL;
|
||||||
apple_input_rec_t *tmpButtons = NULL;
|
apple_input_rec_t *tmpButtons = NULL;
|
||||||
apple_input_rec_t *tmpAxes = NULL;
|
apple_input_rec_t *tmpAxes = NULL;
|
||||||
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)
|
|
||||||
hid_driver_get_data();
|
|
||||||
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)
|
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)
|
||||||
calloc(1, sizeof(*adapter));
|
calloc(1, sizeof(*adapter));
|
||||||
|
|
||||||
@ -832,24 +836,73 @@ static int iohidmanager_hid_manager_free(iohidmanager_hid_t *hid)
|
|||||||
static int iohidmanager_hid_manager_set_device_matching(
|
static int iohidmanager_hid_manager_set_device_matching(
|
||||||
iohidmanager_hid_t *hid)
|
iohidmanager_hid_t *hid)
|
||||||
{
|
{
|
||||||
CFMutableArrayRef matcher = CFArrayCreateMutable(kCFAllocatorDefault, 0,
|
CFSetRef set = IOHIDManagerCopyDevices(hid->ptr);
|
||||||
&kCFTypeArrayCallBacks);
|
CFIndex num_devices = CFSetGetCount(set);
|
||||||
|
IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
|
||||||
|
CFSetGetValues(set, (const void **) device_array);
|
||||||
|
|
||||||
if (!matcher)
|
/* re order device by location id */
|
||||||
return -1;
|
typedef struct hid_list
|
||||||
|
{
|
||||||
|
IOHIDDeviceRef device;
|
||||||
|
uint32_t lid;
|
||||||
|
struct hid_list *next;
|
||||||
|
} hid_list_t;
|
||||||
|
|
||||||
|
hid_list_t* devList = NULL;
|
||||||
|
for (long i=0; i<num_devices;i++)
|
||||||
|
{
|
||||||
|
IOHIDDeviceRef dev = device_array[i];
|
||||||
|
/* filter gamepad/joystick devices */
|
||||||
|
if ( IOHIDDeviceConformsTo(dev, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick)
|
||||||
|
|| IOHIDDeviceConformsTo(dev, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if ( devList == NULL )
|
||||||
|
{
|
||||||
|
devList = (hid_list_t *)malloc(sizeof(hid_list_t));
|
||||||
|
devList->device = dev;
|
||||||
|
devList->lid = iohidmanager_hid_device_get_location_id(dev);
|
||||||
|
//printf("%d\n",devList->lid);
|
||||||
|
devList->next = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hid_list_t * new = (hid_list_t *)malloc(sizeof(hid_list_t));
|
||||||
|
new->device = dev;
|
||||||
|
new->lid = iohidmanager_hid_device_get_location_id(dev);
|
||||||
|
//printf("%d\n",new->lid);
|
||||||
|
new->next = NULL;
|
||||||
|
|
||||||
iohidmanager_hid_append_matching_dictionary(matcher,
|
hid_list_t * ptr = devList;
|
||||||
kHIDPage_GenericDesktop,
|
if ( new->lid < ptr->lid )
|
||||||
kHIDUsage_GD_Joystick);
|
{
|
||||||
iohidmanager_hid_append_matching_dictionary(matcher,
|
new->next = ptr;
|
||||||
kHIDPage_GenericDesktop,
|
devList = new;
|
||||||
kHIDUsage_GD_GamePad);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ( ( ptr->lid < new->lid ) && (ptr->next != NULL) )
|
||||||
|
{
|
||||||
|
ptr = ptr->next;
|
||||||
|
}
|
||||||
|
new->next = ptr->next;
|
||||||
|
ptr->next = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IOHIDManagerSetDeviceMatchingMultiple(hid->ptr, matcher);
|
/* register devices */
|
||||||
IOHIDManagerRegisterDeviceMatchingCallback(hid->ptr,
|
hid_list_t * ptr = devList;
|
||||||
iohidmanager_hid_device_add, 0);
|
while (ptr != NULL)
|
||||||
|
{
|
||||||
CFRelease(matcher);
|
iohidmanager_hid_device_add(ptr->device, hid);
|
||||||
|
//printf("%d\n",ptr->lid);
|
||||||
|
ptr = ptr->next;
|
||||||
|
free(devList);
|
||||||
|
devList = ptr;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user