From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/mouse/mouse_bsd.c | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/detection/mouse/mouse_bsd.c (limited to 'src/detection/mouse/mouse_bsd.c') diff --git a/src/detection/mouse/mouse_bsd.c b/src/detection/mouse/mouse_bsd.c new file mode 100644 index 0000000..da7783b --- /dev/null +++ b/src/detection/mouse/mouse_bsd.c @@ -0,0 +1,56 @@ +#include "mouse.h" +#include "common/io.h" + +#include +#include +#include + +#if __has_include() + #include // FreeBSD +#else + #include // DragonFly +#endif + +#define MAX_UHID_MICE 64 + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { + char path[16]; + for (int i = 0; i < MAX_UHID_MICE; i++) { + snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i); + FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd < 0) { + if (errno == ENOENT) { + break; // No more devices + } + continue; // Device not found + } + report_desc_t repDesc = hid_get_report_desc(fd); + if (!repDesc) { + continue; + } + + int reportId = hid_get_report_id(fd); + + struct hid_data* hData = hid_start_parse(repDesc, 0, reportId); + if (hData) { + struct hid_item hItem; + while (hid_get_item(hData, &hItem) > 0) { + if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 2) { + continue; + } + + struct usb_device_info di; + if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1) { + FFMouseDevice* device = FF_LIST_ADD(FFMouseDevice, *devices); + ffStrbufInitS(&device->serial, di.udi_serial); + ffStrbufInitS(&device->name, di.udi_product); + } + } + hid_end_parse(hData); + } + + hid_dispose_report_desc(repDesc); + } + + return NULL; +} -- cgit v1.2.3