@@ -108,8 +108,21 @@ struct input_report {
108
108
struct input_report * next ;
109
109
};
110
110
111
+ static struct hid_api_version api_version = {
112
+ .major = HID_API_VERSION_MAJOR ,
113
+ .minor = HID_API_VERSION_MINOR ,
114
+ .patch = HID_API_VERSION_PATCH
115
+ };
116
+
117
+ /* - Run context - */
118
+ static IOHIDManagerRef hid_mgr = 0x0 ;
119
+ static int is_macos_10_10_or_greater = 0 ;
120
+ static IOOptionBits device_open_options = 0 ;
121
+ /* --- */
122
+
111
123
struct hid_device_ {
112
124
IOHIDDeviceRef device_handle ;
125
+ IOOptionBits open_options ;
113
126
int blocking ;
114
127
int uses_numbered_reports ;
115
128
int disconnected ;
@@ -132,6 +145,7 @@ static hid_device *new_hid_device(void)
132
145
{
133
146
hid_device * dev = (hid_device * ) calloc (1 , sizeof (hid_device ));
134
147
dev -> device_handle = NULL ;
148
+ dev -> open_options = device_open_options ;
135
149
dev -> blocking = 1 ;
136
150
dev -> uses_numbered_reports = 0 ;
137
151
dev -> disconnected = 0 ;
@@ -184,23 +198,6 @@ static void free_hid_device(hid_device *dev)
184
198
free (dev );
185
199
}
186
200
187
- static struct hid_api_version api_version = {
188
- .major = HID_API_VERSION_MAJOR ,
189
- .minor = HID_API_VERSION_MINOR ,
190
- .patch = HID_API_VERSION_PATCH
191
- };
192
-
193
- static IOHIDManagerRef hid_mgr = 0x0 ;
194
- static int is_macos_10_10_or_greater = 0 ;
195
-
196
-
197
- #if 0
198
- static void register_error (hid_device * dev , const char * op )
199
- {
200
-
201
- }
202
- #endif
203
-
204
201
static CFArrayRef get_array_property (IOHIDDeviceRef device , CFStringRef key )
205
202
{
206
203
CFTypeRef ref = IOHIDDeviceGetProperty (device , key );
@@ -345,6 +342,7 @@ int HID_API_EXPORT hid_init(void)
345
342
{
346
343
if (!hid_mgr ) {
347
344
is_macos_10_10_or_greater = (NSAppKitVersionNumber >= 1343 ); /* NSAppKitVersionNumber10_10 */
345
+ hid_darwin_set_open_exclusive (1 ); /* Backward compatibility */
348
346
return init_hid_manager ();
349
347
}
350
348
@@ -830,7 +828,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
830
828
}
831
829
832
830
/* Open the IOHIDDevice */
833
- ret = IOHIDDeviceOpen (dev -> device_handle , kIOHIDOptionsTypeSeizeDevice );
831
+ ret = IOHIDDeviceOpen (dev -> device_handle , dev -> open_options );
834
832
if (ret == kIOReturnSuccess ) {
835
833
char str [32 ];
836
834
@@ -1147,7 +1145,7 @@ void HID_API_EXPORT hid_close(hid_device *dev)
1147
1145
Not leaking a resource in all tested environments.
1148
1146
*/
1149
1147
if (is_macos_10_10_or_greater || !dev -> disconnected ) {
1150
- IOHIDDeviceClose (dev -> device_handle , kIOHIDOptionsTypeSeizeDevice );
1148
+ IOHIDDeviceClose (dev -> device_handle , dev -> open_options );
1151
1149
}
1152
1150
1153
1151
/* Clear out the queue of received reports. */
@@ -1199,6 +1197,23 @@ int HID_API_EXPORT_CALL hid_darwin_get_location_id(hid_device *dev, uint32_t *lo
1199
1197
}
1200
1198
}
1201
1199
1200
+ void HID_API_EXPORT_CALL hid_darwin_set_open_exclusive (int open_exclusive )
1201
+ {
1202
+ device_open_options = (open_exclusive == 0 ) ? kIOHIDOptionsTypeNone : kIOHIDOptionsTypeSeizeDevice ;
1203
+ }
1204
+
1205
+ int HID_API_EXPORT_CALL hid_darwin_get_open_exclusive (void )
1206
+ {
1207
+ return (device_open_options == kIOHIDOptionsTypeSeizeDevice ) ? 1 : 0 ;
1208
+ }
1209
+
1210
+ int HID_API_EXPORT_CALL hid_darwin_is_device_open_exclusive (hid_device * dev )
1211
+ {
1212
+ if (!dev )
1213
+ return -1 ;
1214
+
1215
+ return (dev -> open_options == kIOHIDOptionsTypeSeizeDevice ) ? 1 : 0 ;
1216
+ }
1202
1217
1203
1218
HID_API_EXPORT const wchar_t * HID_API_CALL hid_error (hid_device * dev )
1204
1219
{
0 commit comments