mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Gamepad (Linux): add support
This commit is contained in:
parent
0b8e8ad4f2
commit
b49b583e64
@ -336,7 +336,7 @@ if(LINUX)
|
||||
src/detection/gtk.c
|
||||
src/detection/host/host_linux.c
|
||||
src/detection/localip/localip_linux.c
|
||||
src/detection/gamepad/gamepad_nosupport.c
|
||||
src/detection/gamepad/gamepad_linux.c
|
||||
src/detection/media/media_linux.c
|
||||
src/detection/memory/memory_linux.c
|
||||
src/detection/opengl/opengl_linux.c
|
||||
|
42
src/detection/gamepad/gamepad_linux.c
Normal file
42
src/detection/gamepad/gamepad_linux.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include "gamepad.h"
|
||||
#include "common/io/io.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
const char* ffDetectGamepad(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* devices /* List of FFGamepadDevice */)
|
||||
{
|
||||
DIR* dirp = opendir("/sys/class/input/");
|
||||
if(dirp == NULL)
|
||||
return "opendir(\"/sys/class/input/\") == NULL";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY path;
|
||||
ffStrbufInitS(&path, "/sys/class/input/");
|
||||
uint32_t baseLen = path.length;
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
{
|
||||
if(strncmp(entry->d_name, "js", 2) != 0)
|
||||
continue;
|
||||
if(!isdigit(entry->d_name[2]))
|
||||
continue;
|
||||
|
||||
ffStrbufAppendS(&path, entry->d_name);
|
||||
ffStrbufAppendS(&path, "/device/name");
|
||||
|
||||
if (ffPathExists(path.chars, FF_PATHTYPE_FILE))
|
||||
{
|
||||
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
|
||||
ffStrbufInitS(&device->identifier, entry->d_name);
|
||||
ffStrbufInit(&device->name);
|
||||
ffAppendFileBuffer(path.chars, &device->name);
|
||||
}
|
||||
|
||||
ffStrbufSubstrBefore(&path, baseLen);
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user