3737
3838#define VALVE_USB_VID 0x28DE
3939
40- /* As defined in AppKit.h, but we don't need the entire AppKit for a single constant. */
41- extern const double NSAppKitVersionNumber ;
42-
4340/* Barrier implementation because Mac OSX doesn't have pthread_barrier.
4441 It also doesn't have clock_gettime(). So much for POSIX and SUSv2.
4542 This implementation came from Brent Priddy and was posted on
@@ -134,7 +131,6 @@ struct hid_device_list_node
134131};
135132
136133static IOHIDManagerRef hid_mgr = 0x0 ;
137- static int is_macos_10_10_or_greater = 0 ;
138134static struct hid_device_list_node * device_list = 0x0 ;
139135
140136static hid_device * new_hid_device (void )
@@ -489,7 +485,6 @@ static int init_hid_manager(void)
489485int HID_API_EXPORT hid_init (void )
490486{
491487 if (!hid_mgr ) {
492- is_macos_10_10_or_greater = (NSAppKitVersionNumber >= 1343 ); /* NSAppKitVersionNumber10_10 */
493488 return init_hid_manager ();
494489 }
495490
@@ -1143,10 +1138,8 @@ void HID_API_EXPORT hid_close(hid_device *dev)
11431138 if (!dev )
11441139 return ;
11451140
1146- /* Disconnect the report callback before close.
1147- See comment below.
1148- */
1149- if (is_macos_10_10_or_greater || !dev -> disconnected ) {
1141+ /* Disconnect the report callback before close. */
1142+ if (!dev -> disconnected ) {
11501143 IOHIDDeviceRegisterInputReportCallback (
11511144 dev -> device_handle , dev -> input_report_buf , dev -> max_input_report_len ,
11521145 NULL , dev );
@@ -1169,14 +1162,8 @@ void HID_API_EXPORT hid_close(hid_device *dev)
11691162
11701163 /* Close the OS handle to the device, but only if it's not
11711164 been unplugged. If it's been unplugged, then calling
1172- IOHIDDeviceClose() will crash.
1173-
1174- UPD: The crash part was true in/until some version of macOS.
1175- Starting with macOS 10.15, there is an opposite effect in some environments:
1176- crash happenes if IOHIDDeviceClose() is not called.
1177- Not leaking a resource in all tested environments.
1178- */
1179- if (is_macos_10_10_or_greater || !dev -> disconnected ) {
1165+ IOHIDDeviceClose() will crash. */
1166+ if (!dev -> disconnected ) {
11801167 IOHIDDeviceClose (dev -> device_handle , kIOHIDOptionsTypeNone );
11811168 }
11821169
0 commit comments