diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/mouse/mouse_linux.c | |
Add the files
Diffstat (limited to 'src/detection/mouse/mouse_linux.c')
| -rw-r--r-- | src/detection/mouse/mouse_linux.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/detection/mouse/mouse_linux.c b/src/detection/mouse/mouse_linux.c new file mode 100644 index 0000000..939c332 --- /dev/null +++ b/src/detection/mouse/mouse_linux.c @@ -0,0 +1,45 @@ +#include "mouse.h" +#include "common/io.h" +#include "common/strutil.h" + +const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/input/"); + if (dirp == NULL) { + return "opendir(\"/sys/class/input/\") == NULL"; + } + + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/class/input/"); + uint32_t baseLen = path.length; + + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) { + if (!ffStrStartsWith(entry->d_name, "mouse")) { + continue; + } + if (!ffCharIsDigit(entry->d_name[strlen("mouse")])) { + continue; + } + + ffStrbufAppendS(&path, entry->d_name); + ffStrbufAppendS(&path, "/device/name"); + + FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate(); + if (ffAppendFileBuffer(path.chars, &name)) { + ffStrbufTrimRightSpace(&name); + ffStrbufSubstrBefore(&path, path.length - 4); + + FFMouseDevice* device = FF_LIST_ADD(FFMouseDevice, *devices); + ffStrbufInitMove(&device->name, &name); + ffStrbufInit(&device->serial); + + ffStrbufAppendS(&path, "uniq"); + if (ffAppendFileBuffer(path.chars, &device->serial)) { + ffStrbufTrimRightSpace(&device->serial); + } + } + + ffStrbufSubstrBefore(&path, baseLen); + } + + return NULL; +} |