bluetooth: fix BLE/HID keyboard & mouse pairing, auto-bypass T9 on external keyboard, and show mouse cursor

This commit is contained in:
Luxferre committed 2026-11-03 20:24:54 +02:00
1 parent b9e7c6847b
commit 02ce3ab1f4
67 files changed
+1227 -293

No files matched your search

+54 -1
View File
@@ -469,8 +469,61 @@ inline void runAsyncArgv(const char* prog,
}
}
inline bool isExternalKeyboardActive() {
static time_t lastDirSec = -1;
static long lastDirNsec = -1;
static bool cachedActive = false;
struct stat st {};
if (::stat("/dev/input", &st) == 0) {
if (st.st_mtim.tv_sec == lastDirSec && st.st_mtim.tv_nsec == lastDirNsec) {
return cachedActive;
}
lastDirSec = st.st_mtim.tv_sec;
lastDirNsec = st.st_mtim.tv_nsec;
}
FILE* fp = std::fopen("/proc/bus/input/devices", "r");
if (!fp) {
cachedActive = false;
return false;
}
bool extBus = false;
bool found = false;
char line[512];
while (std::fgets(line, sizeof(line), fp)) {
if (line[0] == '\n' || line[0] == '\r' || line[0] == '\0') {
extBus = false;
continue;
}
if (std::strncmp(line, "I: Bus=0005", 11) == 0 ||
std::strncmp(line, "I: Bus=0003", 11) == 0) {
extBus = true;
} else if (extBus && std::strncmp(line, "B: KEY=", 7) == 0) {
const char* p = line + 7;
const char* lastToken = nullptr;
while (*p) {
while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') ++p;
if (!*p) break;
lastToken = p;
while (*p && *p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') ++p;
}
if (lastToken) {
unsigned long long mask = std::strtoull(lastToken, nullptr, 16);
if ((mask & 0x03ff0000ULL) == 0x03ff0000ULL) {
found = true;
break;
}
}
}
}
std::fclose(fp);
cachedActive = found;
return cachedActive;
}
inline char mapDialKey(KeySym sym, unsigned int keycode, unsigned int state) {
if (state & (ControlMask | Mod1Mask | Mod4Mask)) {
if (state & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask)) {
return '\0';
}
// Keypad star (*)