bluetooth: fix BLE/HID keyboard & mouse pairing, auto-bypass T9 on external keyboard, and show mouse cursor
This commit is contained in:
1 parent
b9e7c6847b
commit
02ce3ab1f4
67 files changed
+1227
-293
No files matched your search
+88
-5
@@ -232,6 +232,59 @@ bool isExternalOverlayOrLockActive(const std::string& appName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int mapHardwareKey(KeySym sym, unsigned int keycode, unsigned int state) {
|
||||
if (keycode == 135 || sym == XK_Super_L || sym == XK_Menu ||
|
||||
static_cast<uint32_t>(sym) == _EVDEVK(0x8b)) {
|
||||
@@ -260,7 +313,7 @@ int mapHardwareKey(KeySym sym, unsigned int keycode, unsigned int state) {
|
||||
sym == XK_F4 || static_cast<uint32_t>(sym) == _EVDEVK(0x6b)) {
|
||||
return NEO_KEY_END;
|
||||
}
|
||||
if (!(state & (ControlMask | Mod1Mask | Mod4Mask))) {
|
||||
if (!(state & (ShiftMask | ControlMask | Mod1Mask | Mod4Mask))) {
|
||||
if (keycode == 63 || keycode == 530 || sym == XK_asterisk ||
|
||||
sym == XK_KP_Multiply || static_cast<uint32_t>(sym) == 0x1008ffaa) {
|
||||
return NEO_KEY_STAR;
|
||||
@@ -2932,7 +2985,12 @@ int neoui_poll_event(int timeout_ms) {
|
||||
ctx->grabYielded = true;
|
||||
continue;
|
||||
}
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
char strBuf[8] = {};
|
||||
KeySym sym = NoSymbol;
|
||||
XLookupString(&ev.xkey, strBuf, sizeof(strBuf) - 1, &sym, nullptr);
|
||||
if (sym == NoSymbol) {
|
||||
sym = XLookupKeysym(&ev.xkey, (ev.xkey.state & ShiftMask) ? 1 : 0);
|
||||
}
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
int nkey = bananarchy::mapHardwareKey(sym, kc, ev.xkey.state);
|
||||
ctx->lastEventKey = nkey;
|
||||
@@ -3153,6 +3211,9 @@ int neoui_input_cycle_mode(void) {
|
||||
}
|
||||
|
||||
const char* neoui_input_mode_badge(void) {
|
||||
if (bananarchy::isExternalKeyboardActive()) {
|
||||
return "[KBD]";
|
||||
}
|
||||
int mode = gCtx ? gCtx->inputMode : NEO_INPUT_ABC_TITLE;
|
||||
switch (mode) {
|
||||
case NEO_INPUT_ABC_TITLE: return "[Abc]";
|
||||
@@ -3201,16 +3262,38 @@ int neoui_input_feed_key(int neo_key) {
|
||||
ctx->tapCycleIdx = 0;
|
||||
}
|
||||
|
||||
if (neo_key == NEO_KEY_BACK) {
|
||||
return neoui_input_backspace();
|
||||
}
|
||||
|
||||
if (bananarchy::isExternalKeyboardActive()) {
|
||||
ctx->tapActive = false;
|
||||
ctx->lastTapKey = -1;
|
||||
if (ctx->lastEventKeysym >= 0x20 && ctx->lastEventKeysym <= 0x7e) {
|
||||
ctx->inputText.push_back(static_cast<char>(ctx->lastEventKeysym));
|
||||
return 1;
|
||||
}
|
||||
if (neo_key >= 0x20 && neo_key <= 0x7e) {
|
||||
ctx->inputText.push_back(static_cast<char>(neo_key));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (neo_key == NEO_KEY_HASH) {
|
||||
neoui_input_cycle_mode();
|
||||
return 1;
|
||||
}
|
||||
if (neo_key == NEO_KEY_BACK) {
|
||||
return neoui_input_backspace();
|
||||
}
|
||||
if (neo_key == NEO_KEY_RIGHT && ctx->tapActive) {
|
||||
return neoui_input_commit_tap();
|
||||
}
|
||||
if (neo_key == NEO_KEY_NONE &&
|
||||
ctx->lastEventKeysym >= 0x20 && ctx->lastEventKeysym <= 0x7e) {
|
||||
ctx->tapActive = false;
|
||||
ctx->lastTapKey = -1;
|
||||
ctx->inputText.push_back(static_cast<char>(ctx->lastEventKeysym));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ctx->inputMode == NEO_INPUT_123) {
|
||||
if ((neo_key >= '0' && neo_key <= '9') || neo_key == '*' ||
|
||||
|
||||
Reference in new issue
Block a user