mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Gamepad (FreeBSD): add support
This commit is contained in:
parent
0685c7afd6
commit
592354b449
@ -447,7 +447,7 @@ elseif(BSD)
|
||||
src/detection/host/host_bsd.c
|
||||
src/detection/icons/icons_linux.c
|
||||
src/detection/localip/localip_linux.c
|
||||
src/detection/gamepad/gamepad_nosupport.c
|
||||
src/detection/gamepad/gamepad_bsd.c
|
||||
src/detection/media/media_linux.c
|
||||
src/detection/memory/memory_bsd.c
|
||||
src/detection/opengl/opengl_linux.c
|
||||
@ -752,6 +752,10 @@ elseif(WIN32)
|
||||
PRIVATE "wtsapi32"
|
||||
PRIVATE "powrprof"
|
||||
)
|
||||
elseif(BSD)
|
||||
target_link_libraries(libfastfetch
|
||||
PRIVATE "usbhid"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(libfastfetch
|
||||
|
54
src/detection/gamepad/gamepad_bsd.c
Normal file
54
src/detection/gamepad/gamepad_bsd.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include "gamepad.h"
|
||||
#include "common/io/io.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <usbhid.h>
|
||||
#include <dev/usb/usb_ioctl.h>
|
||||
|
||||
#define MAX_UHID_JOYS 64
|
||||
|
||||
const char* ffDetectGamepad(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* devices /* List of FFGamepadDevice */)
|
||||
{
|
||||
char path[16];
|
||||
for (int i = 0; i < MAX_UHID_JOYS; i++)
|
||||
{
|
||||
snprintf(path, sizeof(path), "/dev/uhid%d", i);
|
||||
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) continue;
|
||||
|
||||
report_desc_t repDesc = hid_get_report_desc(fd);
|
||||
if (!repDesc) continue;
|
||||
|
||||
int repId = hid_get_report_id(fd);
|
||||
|
||||
struct hid_data* hData = hid_start_parse(repDesc, 0, repId);
|
||||
if (hData)
|
||||
{
|
||||
struct hid_item hItem;
|
||||
while (hid_get_item(hData, &hItem) > 0)
|
||||
{
|
||||
switch (HID_PAGE(hItem.usage))
|
||||
{
|
||||
case 1: // FreeBSD returns 1 for my Pro Controller for some reason
|
||||
case 5:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
struct usb_device_info di;
|
||||
if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1)
|
||||
{
|
||||
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
|
||||
ffStrbufInitS(&device->identifier, di.udi_serial);
|
||||
ffStrbufInitF(&device->name, "%s %s", di.udi_vendor, di.udi_product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hid_dispose_report_desc(repDesc);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user