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
@@ -195,9 +195,64 @@ bool charToCtrlKey(char ch, fcitx::KeySym* symOut, uint32_t* xkbCodeOut) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// Evdev KEY_Q..KEY_P (16..25): bits 16..25 = 0x03ff0000
|
||||
if ((mask & 0x03ff0000ULL) == 0x03ff0000ULL) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::fclose(fp);
|
||||
cachedActive = found;
|
||||
return cachedActive;
|
||||
}
|
||||
|
||||
int mapHardwareKey(const fcitx::Key& key) {
|
||||
if (key.states().testAny(fcitx::KeyState::Ctrl_Alt) ||
|
||||
key.states().test(fcitx::KeyState::Super)) {
|
||||
key.states().test(fcitx::KeyState::Super) ||
|
||||
key.states().test(fcitx::KeyState::Shift)) {
|
||||
return -1;
|
||||
}
|
||||
uint32_t code = key.code();
|
||||
@@ -336,10 +391,10 @@ T9Engine::T9Engine(fcitx::Instance* instance)
|
||||
FCITX_UNUSED(event);
|
||||
if (sharedMode == T9Mode::Ctrl) {
|
||||
sharedMode = T9Mode::Lower;
|
||||
writeStatusIndicator("[abc]");
|
||||
writeStatusIndicator(isExternalKeyboardActive() ? "[KBD]" : "[abc]");
|
||||
}
|
||||
});
|
||||
writeStatusIndicator("[abc]");
|
||||
writeStatusIndicator(isExternalKeyboardActive() ? "[KBD]" : "[abc]");
|
||||
}
|
||||
|
||||
std::vector<fcitx::InputMethodEntry> T9Engine::listInputMethods() {
|
||||
@@ -391,6 +446,10 @@ void T9Engine::reset(const fcitx::InputMethodEntry& entry,
|
||||
FCITX_ADDON_FACTORY(T9EngineFactory);
|
||||
|
||||
void T9State::updateStatusBar() const {
|
||||
if (isExternalKeyboardActive()) {
|
||||
writeStatusIndicator("[KBD]");
|
||||
return;
|
||||
}
|
||||
writeStatusIndicator("[" + modePrefix() + "]");
|
||||
}
|
||||
|
||||
@@ -662,6 +721,15 @@ void T9State::stepCandidate(int delta) {
|
||||
}
|
||||
|
||||
bool T9State::handleKeyEvent(fcitx::KeyEvent& keyEvent) {
|
||||
if (isExternalKeyboardActive()) {
|
||||
if (!activeItems.empty() || commitTimer || releaseTimer || longPressTimer ||
|
||||
bannerTimer) {
|
||||
reset();
|
||||
} else {
|
||||
updateStatusBar();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
mode = engine->sharedMode;
|
||||
fcitx::Key key = keyEvent.key();
|
||||
uint32_t code = key.code();
|
||||
|
||||
Reference in new issue
Block a user