Make sure HID devices can be opened before making them available to the application

This prevents a number of issues where devices are enumerated but not actually able to be opened, like https://github.com/libsdl-org/SDL/issues/5781.

We currently leave the devices open, allowing us to more easily do controller feature detection, protocol negotiation, detect dropped Bluetooth connections, etc. with the expectation that the application is likely to open the controllers shortly.
This commit is contained in:
Sam Lantinga
2022-09-22 18:22:17 -07:00
parent 2857e3c748
commit aa2e2f4843
17 changed files with 811 additions and 1072 deletions

View File

@@ -130,7 +130,6 @@ struct hid_device_list_node
static IOHIDManagerRef hid_mgr = 0x0;
static struct hid_device_list_node *device_list = 0x0;
static int hid_input_monitoring_denied = 0;
static hid_device *new_hid_device(void)
{
@@ -522,11 +521,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Set up the HID Manager if it hasn't been done */
if (hid_init() < 0)
return NULL;
/* If we don't have permission to open devices, don't enumerate them */
if (hid_input_monitoring_denied)
return NULL;
/* give the IOHIDManager a chance to update itself */
process_pending_events();
@@ -867,11 +862,6 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
return dev;
}
else if (ret == kIOReturnNotPermitted) {
/* This application doesn't have input monitoring permissions */
hid_input_monitoring_denied = 1;
goto return_error;
}
else {
goto return_error;
}