2024-10-09 09:45:09 +08:00
|
|
|
#include "mouse.h"
|
2026-01-06 09:48:38 +08:00
|
|
|
#include "common/io.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2024-10-09 09:45:09 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) {
|
2024-10-09 09:45:09 +08:00
|
|
|
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/input/");
|
2026-07-10 18:08:04 +08:00
|
|
|
if (dirp == nullptr) {
|
|
|
|
|
return "opendir(\"/sys/class/input/\") == nullptr";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-10-09 09:45:09 +08:00
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/class/input/");
|
|
|
|
|
uint32_t baseLen = path.length;
|
|
|
|
|
|
|
|
|
|
struct dirent* entry;
|
2026-07-10 18:08:04 +08:00
|
|
|
while ((entry = readdir(dirp)) != nullptr) {
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!ffStrStartsWith(entry->d_name, "mouse")) {
|
2024-10-09 09:45:09 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
if (!ffCharIsDigit(entry->d_name[strlen("mouse")])) {
|
2024-10-09 09:45:09 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-10-09 09:45:09 +08:00
|
|
|
|
|
|
|
|
ffStrbufAppendS(&path, entry->d_name);
|
|
|
|
|
ffStrbufAppendS(&path, "/device/name");
|
|
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
|
2026-03-29 09:28:49 +08:00
|
|
|
if (ffAppendFileBuffer(path.chars, &name)) {
|
2024-10-09 09:45:09 +08:00
|
|
|
ffStrbufTrimRightSpace(&name);
|
|
|
|
|
ffStrbufSubstrBefore(&path, path.length - 4);
|
|
|
|
|
|
2026-04-14 10:41:18 +08:00
|
|
|
FFMouseDevice* device = FF_LIST_ADD(FFMouseDevice, *devices);
|
2024-10-09 09:45:09 +08:00
|
|
|
ffStrbufInitMove(&device->name, &name);
|
|
|
|
|
ffStrbufInit(&device->serial);
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(&path, "uniq");
|
2026-03-29 09:28:49 +08:00
|
|
|
if (ffAppendFileBuffer(path.chars, &device->serial)) {
|
2024-10-09 09:45:09 +08:00
|
|
|
ffStrbufTrimRightSpace(&device->serial);
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2024-10-09 09:45:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufSubstrBefore(&path, baseLen);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 18:08:04 +08:00
|
|
|
return nullptr;
|
2024-10-09 09:45:09 +08:00
|
|
|
}
|