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
@@ -1140,13 +1135,14 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
11401135
11411136void HID_API_EXPORT hid_close (hid_device * dev )
11421137{
1138+ int disconnected ;
1139+
11431140 if (!dev )
11441141 return ;
11451142
1146- /* Disconnect the report callback before close.
1147- See comment below.
1148- */
1149- if (is_macos_10_10_or_greater || !dev -> disconnected ) {
1143+ /* Disconnect the report callback before close. */
1144+ disconnected = dev -> disconnected ;
1145+ if (!disconnected ) {
11501146 IOHIDDeviceRegisterInputReportCallback (
11511147 dev -> device_handle , dev -> input_report_buf , dev -> max_input_report_len ,
11521148 NULL , dev );
@@ -1169,14 +1165,8 @@ void HID_API_EXPORT hid_close(hid_device *dev)
11691165
11701166 /* Close the OS handle to the device, but only if it's not
11711167 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 ) {
1168+ IOHIDDeviceClose() will crash. */
1169+ if (!disconnected ) {
11801170 IOHIDDeviceClose (dev -> device_handle , kIOHIDOptionsTypeNone );
11811171 }
11821172
0 commit comments