Skip to content

Commit 1ce31c3

Browse files
authored
macos: Add Mac-specific API to get device Location ID (signal11#378)
1 parent 2cfd63a commit 1ce31c3

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

mac/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.4.3 FATAL_ERROR)
22

3+
list(APPEND HIDAPI_PUBLIC_HEADERS "hidapi_darwin.h")
4+
35
add_library(hidapi_darwin
46
${HIDAPI_PUBLIC_HEADERS}
57
hid.c

mac/hid.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <unistd.h>
3535
#include <dlfcn.h>
3636

37-
#include "hidapi.h"
37+
#include "hidapi_darwin.h"
3838

3939
/* As defined in AppKit.h, but we don't need the entire AppKit for a single constant. */
4040
extern const double NSAppKitVersionNumber;
@@ -1188,6 +1188,17 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
11881188
return 0;
11891189
}
11901190

1191+
int HID_API_EXPORT_CALL hid_darwin_get_location_id(hid_device *dev, uint32_t *location_id)
1192+
{
1193+
int res = get_int_property(dev->device_handle, CFSTR(kIOHIDLocationIDKey));
1194+
if (res != 0) {
1195+
*location_id = (uint32_t) res;
1196+
return 0;
1197+
} else {
1198+
return -1;
1199+
}
1200+
}
1201+
11911202

11921203
HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
11931204
{

mac/hidapi_darwin.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*******************************************************
2+
HIDAPI - Multi-Platform library for
3+
communication with HID devices.
4+
5+
libusb/hidapi Team
6+
7+
Copyright 2022, All Rights Reserved.
8+
9+
At the discretion of the user of this library,
10+
this software may be licensed under the terms of the
11+
GNU General Public License v3, a BSD-Style license, or the
12+
original HIDAPI license as outlined in the LICENSE.txt,
13+
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
14+
files located at the root of the source distribution.
15+
These files may also be found in the public source
16+
code repository located at:
17+
https://github.com/libusb/hidapi .
18+
********************************************************/
19+
20+
/** @file
21+
* @defgroup API hidapi API
22+
*/
23+
24+
#ifndef HIDAPI_DARWIN_H__
25+
#define HIDAPI_DARWIN_H__
26+
27+
#include <stdint.h>
28+
29+
#include "hidapi.h"
30+
31+
#ifdef __cplusplus
32+
extern "C" {
33+
#endif
34+
35+
/** @brief Get the location ID for a HID device.
36+
37+
@ingroup API
38+
@param dev A device handle returned from hid_open().
39+
@param location_id The device's location ID on return.
40+
41+
@returns
42+
This function returns 0 on success and -1 on error.
43+
*/
44+
int HID_API_EXPORT_CALL hid_darwin_get_location_id(hid_device *dev, uint32_t *location_id);
45+
46+
#ifdef __cplusplus
47+
}
48+
#endif
49+
50+
#endif

0 commit comments

Comments
 (0)