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);
+32 -5
View File
@@ -584,14 +584,41 @@ drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w,
Cur *
drw_cur_create(Drw *drw, int shape)
{
Cur *cur;
Cur *cur;
Pixmap src, msk;
XColor fg, bg;
static const char src_bits[32] = {
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x00,
0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x7e, 0x00,
0xfe, 0x00, 0x3e, 0x00, 0x36, 0x00, 0x62, 0x00,
0x60, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00
};
static const char msk_bits[32] = {
0x01, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00,
0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00,
0xff, 0x01, 0xff, 0x03, 0x7f, 0x00, 0xf7, 0x00,
0xf3, 0x00, 0xe1, 0x01, 0xe0, 0x01, 0xc0, 0x00
};
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL;
(void)shape;
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL;
cur->cursor = XCreateFontCursor(drw->dpy, shape);
memset(&fg, 0, sizeof(fg));
fg.red = 65535;
fg.green = 65535;
fg.blue = 65535;
fg.flags = DoRed | DoGreen | DoBlue;
memset(&bg, 0, sizeof(bg));
bg.flags = DoRed | DoGreen | DoBlue;
return cur;
src = XCreateBitmapFromData(drw->dpy, drw->root, src_bits, 16, 16);
msk = XCreateBitmapFromData(drw->dpy, drw->root, msk_bits, 16, 16);
cur->cursor = XCreatePixmapCursor(drw->dpy, src, msk, &fg, &bg, 0, 0);
XFreePixmap(drw->dpy, src);
XFreePixmap(drw->dpy, msk);
return cur;
}
void