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

+66 -1
View File
@@ -250,9 +250,74 @@ add_menu_item(const char *label, const char *action, int loop)
items[items_count].right = NULL;
}
static int
dmenu_has_external_keyboard(void)
{
static time_t last_dev_sec = 0;
static long last_dev_nsec = 0;
static int cached = 0;
struct stat st;
if (stat("/dev/input", &st) == 0) {
if (st.st_mtim.tv_sec == last_dev_sec &&
st.st_mtim.tv_nsec == last_dev_nsec) {
return cached;
}
last_dev_sec = st.st_mtim.tv_sec;
last_dev_nsec = st.st_mtim.tv_nsec;
}
FILE *fp = fopen("/proc/bus/input/devices", "r");
if (!fp) {
cached = 0;
return 0;
}
char line[512];
int is_ext_bus = 0;
int has_kbd = 0;
int has_qwerty = 0;
int found = 0;
while (fgets(line, sizeof(line), fp)) {
if (line[0] == '\n' || line[0] == '\r') {
if (is_ext_bus && has_kbd && has_qwerty) {
found = 1;
break;
}
is_ext_bus = 0;
has_kbd = 0;
has_qwerty = 0;
continue;
}
if (strncmp(line, "I: ", 3) == 0) {
if (strstr(line, "Bus=0005") || strstr(line, "Bus=0003"))
is_ext_bus = 1;
} else if (is_ext_bus && strncmp(line, "H: Handlers=", 12) == 0) {
if (strstr(line + 12, "kbd"))
has_kbd = 1;
} else if (is_ext_bus && strncmp(line, "B: KEY=", 7) == 0) {
const char *p = line + 7;
const char *last_tok = p;
while (*p) {
while (*p == ' ' || *p == '\t') p++;
if (!*p || *p == '\n' || *p == '\r') break;
last_tok = p;
while (*p && *p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') p++;
}
unsigned long long mask = strtoull(last_tok, NULL, 16);
if ((mask & 0x3ffc0000ULL) == 0x3ffc0000ULL)
has_qwerty = 1;
}
}
if (!found && is_ext_bus && has_kbd && has_qwerty)
found = 1;
fclose(fp);
cached = found;
return cached;
}
static const char *
t9_mode_badge(int mode)
{
if (dmenu_has_external_keyboard())
return "[KBD]";
switch (mode) {
case T9_SHIFT: return "[Abc]";
case T9_UPPER: return "[ABC]";
@@ -1580,7 +1645,7 @@ keypress(XKeyEvent *ev)
KeySym ksym;
Status status;
if (!engage_ime) {
if (!engage_ime && !dmenu_has_external_keyboard()) {
int t9k = map_t9_key(ev);
if (t9k >= 0) {
handle_t9_keypress(t9k);