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
@@ -458,7 +458,11 @@ int runContactsApp(int argc, char** argv) {
|
||||
|
||||
const char* modeNames[4] = {"[Abc]", "[ABC]", "[abc]", "[123]"};
|
||||
std::string modeBadge =
|
||||
(editField == 0) ? modeNames[static_cast<int>(caseMode)] : "[+0-9]";
|
||||
(editField == 0)
|
||||
? (isExternalKeyboardActive()
|
||||
? "[KBD]"
|
||||
: modeNames[static_cast<int>(caseMode)])
|
||||
: "[+0-9]";
|
||||
int mw = pangoWidth(layoutSmall, modeBadge);
|
||||
drawPango(layoutSmall, &colYellow, kWinWidth - mw - 6, 0, kHeaderH,
|
||||
modeBadge);
|
||||
@@ -1208,7 +1212,7 @@ int runContactsApp(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
} else if (ev.type == KeyPress) {
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, (ev.xkey.state & ShiftMask) ? 1 : 0);
|
||||
bool isLeftSoft = (sym == XK_Menu || sym == XF86XK_KbdLcdMenu1 ||
|
||||
ev.xkey.keycode == 135);
|
||||
bool isRightSoft = (sym == XF86XK_Back || sym == XF86XK_KbdLcdMenu2 ||
|
||||
@@ -1389,36 +1393,29 @@ int runContactsApp(int argc, char** argv) {
|
||||
} else if (mode == ViewMode::Edit) {
|
||||
char dialCh = mapDialKey(sym, ev.xkey.keycode, ev.xkey.state);
|
||||
if (editField == 0) {
|
||||
if (dialCh == '#') {
|
||||
caseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(caseMode) + 1) % 4);
|
||||
lastTapDigit = -1;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (dialCh == '*') {
|
||||
editName.push_back(' ');
|
||||
lastTapDigit = -1;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (dialCh >= '0' && dialCh <= '9') {
|
||||
handleMultiTapNameChar(dialCh - '0');
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (sym >= XK_a && sym <= XK_z) {
|
||||
char c = static_cast<char>('a' + (sym - XK_a));
|
||||
if (ev.xkey.state & ShiftMask) {
|
||||
c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
if (!isExternalKeyboardActive()) {
|
||||
if (dialCh == '#') {
|
||||
caseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(caseMode) + 1) % 4);
|
||||
lastTapDigit = -1;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (dialCh == '*') {
|
||||
editName.push_back(' ');
|
||||
lastTapDigit = -1;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (dialCh >= '0' && dialCh <= '9') {
|
||||
handleMultiTapNameChar(dialCh - '0');
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
editName.push_back(c);
|
||||
lastTapDigit = -1;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (sym == XK_space) {
|
||||
editName.push_back(' ');
|
||||
if (sym >= 0x20 && sym <= 0x7e &&
|
||||
!(ev.xkey.state & (ControlMask | Mod1Mask))) {
|
||||
editName.push_back(static_cast<char>(sym));
|
||||
lastTapDigit = -1;
|
||||
render();
|
||||
continue;
|
||||
|
||||
@@ -50,7 +50,7 @@ std::vector<BtSendTarget> queryBtSendTargets(bool scanFirst = false) {
|
||||
runCaptureCmd("SXMO_OS=alpine doas -n sxmo_bluetoothtoggle.sh on >/dev/null 2>&1");
|
||||
}
|
||||
if (scanFirst) {
|
||||
runCaptureCmd("timeout 5 bluetoothctl --timeout 4 scan on >/dev/null 2>&1");
|
||||
runCaptureCmd("timeout 16 bluetoothctl --timeout 15 scan on >/dev/null 2>&1");
|
||||
}
|
||||
std::unordered_set<std::string> pairedMacs;
|
||||
std::unordered_set<std::string> connectedMacs;
|
||||
@@ -1450,7 +1450,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
drawPango(layoutMain, &colWhite, 28, 0, 36, inputTitle, 145);
|
||||
|
||||
const char* mBadge = "[abc]";
|
||||
if (caseMode == TextCaseMode::Title) mBadge = "[Abc]";
|
||||
if (isExternalKeyboardActive()) mBadge = "[KBD]";
|
||||
else if (caseMode == TextCaseMode::Title) mBadge = "[Abc]";
|
||||
else if (caseMode == TextCaseMode::Upper) mBadge = "[ABC]";
|
||||
else if (caseMode == TextCaseMode::Num) mBadge = "[123]";
|
||||
drawPango(layoutSmall, &colYellow, kWinWidth - 46, 0, 36, mBadge);
|
||||
@@ -1516,7 +1517,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
drawPango(layoutMain, &colWhite, 25, 0, 32, titleDisp, 114);
|
||||
|
||||
const char* mBadge = "[abc]";
|
||||
if (editCaseMode == TextCaseMode::Title) mBadge = "[Abc]";
|
||||
if (isExternalKeyboardActive()) mBadge = "[KBD]";
|
||||
else if (editCaseMode == TextCaseMode::Title) mBadge = "[Abc]";
|
||||
else if (editCaseMode == TextCaseMode::Upper) mBadge = "[ABC]";
|
||||
else if (editCaseMode == TextCaseMode::Num) mBadge = "[123]";
|
||||
else if (editCaseMode == TextCaseMode::Sym) mBadge = "[Sym]";
|
||||
@@ -2405,8 +2407,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
} else if (mode == ViewMode::BtSendModal) {
|
||||
if (isLeft) {
|
||||
if (btTargets.empty()) {
|
||||
statusBanner = "Scanning Bluetooth...";
|
||||
statusBannerUntilMs = nowMs() + 2500;
|
||||
statusBanner = "Scanning Bluetooth (15s)...";
|
||||
statusBannerUntilMs = nowMs() + 16000;
|
||||
drawUI();
|
||||
btTargets = queryBtSendTargets(true);
|
||||
btTargetSel = 0;
|
||||
@@ -2475,7 +2477,7 @@ int runFilesApp(int argc, char** argv) {
|
||||
} else if (ev.type == KeyPress) {
|
||||
int64_t tNow = nowMs();
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, (ev.xkey.state & ShiftMask) ? 1 : 0);
|
||||
|
||||
bool isLeftSk =
|
||||
(kc == 135 || sym == XK_Menu || sym == XF86XK_KbdLcdMenu1 ||
|
||||
@@ -2686,17 +2688,28 @@ int runFilesApp(int argc, char** argv) {
|
||||
insertEditorNewline();
|
||||
drawUI();
|
||||
} else {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (d == '#') {
|
||||
if (!isExternalKeyboardActive()) {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (d == '#') {
|
||||
editLastTapDigit = -1;
|
||||
editCaseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(editCaseMode) + 1) % 5);
|
||||
drawUI();
|
||||
continue;
|
||||
} else if (d == '*') {
|
||||
commitEditorTap(10);
|
||||
drawUI();
|
||||
continue;
|
||||
} else if (d >= '0' && d <= '9') {
|
||||
commitEditorTap(d - '0');
|
||||
drawUI();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (sym >= 0x20 && sym <= 0x7e &&
|
||||
!(ev.xkey.state & (ControlMask | Mod1Mask))) {
|
||||
editLastTapDigit = -1;
|
||||
editCaseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(editCaseMode) + 1) % 5);
|
||||
drawUI();
|
||||
} else if (d == '*') {
|
||||
commitEditorTap(10);
|
||||
drawUI();
|
||||
} else if (d >= '0' && d <= '9') {
|
||||
commitEditorTap(d - '0');
|
||||
insertEditorStr(std::string(1, static_cast<char>(sym)));
|
||||
drawUI();
|
||||
}
|
||||
}
|
||||
@@ -2757,17 +2770,28 @@ int runFilesApp(int argc, char** argv) {
|
||||
lastTapDigit = -1;
|
||||
drawUI();
|
||||
} else {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (d == '#') {
|
||||
if (!isExternalKeyboardActive()) {
|
||||
char d = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (d == '#') {
|
||||
lastTapDigit = -1;
|
||||
caseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(caseMode) + 1) % 4);
|
||||
drawUI();
|
||||
continue;
|
||||
} else if (d == '*') {
|
||||
commitModalTap(1);
|
||||
drawUI();
|
||||
continue;
|
||||
} else if (d >= '0' && d <= '9') {
|
||||
commitModalTap(d - '0');
|
||||
drawUI();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (sym >= 0x20 && sym <= 0x7e &&
|
||||
!(ev.xkey.state & (ControlMask | Mod1Mask))) {
|
||||
lastTapDigit = -1;
|
||||
caseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(caseMode) + 1) % 4);
|
||||
drawUI();
|
||||
} else if (d == '*') {
|
||||
commitModalTap(1);
|
||||
drawUI();
|
||||
} else if (d >= '0' && d <= '9') {
|
||||
commitModalTap(d - '0');
|
||||
inputValue.push_back(static_cast<char>(sym));
|
||||
drawUI();
|
||||
}
|
||||
}
|
||||
@@ -2795,8 +2819,8 @@ int runFilesApp(int argc, char** argv) {
|
||||
drawUI();
|
||||
}
|
||||
} else if (d == '*') {
|
||||
statusBanner = "Scanning Bluetooth...";
|
||||
statusBannerUntilMs = nowMs() + 2500;
|
||||
statusBanner = "Scanning Bluetooth (15s)...";
|
||||
statusBannerUntilMs = nowMs() + 16000;
|
||||
drawUI();
|
||||
btTargets = queryBtSendTargets(true);
|
||||
btTargetSel = 0;
|
||||
|
||||
@@ -459,7 +459,26 @@ std::vector<BtDeviceEntry> queryBtDevices() {
|
||||
d.paired = (pairedMacs.count(d.mac) > 0);
|
||||
d.connected = (connectedMacs.count(d.mac) > 0);
|
||||
out.push_back(d);
|
||||
if ((d.connected || d.paired) && infoCount < 12) {
|
||||
}
|
||||
|
||||
auto isRawMacName = [](const BtDeviceEntry& e) {
|
||||
if (e.name == e.mac) return true;
|
||||
if (e.name.size() == 17 && e.name[2] == '-' && e.name[5] == '-') return true;
|
||||
return false;
|
||||
};
|
||||
std::sort(out.begin(), out.end(),
|
||||
[&](const BtDeviceEntry& a, const BtDeviceEntry& b) {
|
||||
if (a.connected != b.connected) return a.connected > b.connected;
|
||||
if (a.paired != b.paired) return a.paired > b.paired;
|
||||
bool aRaw = isRawMacName(a);
|
||||
bool bRaw = isRawMacName(b);
|
||||
if (aRaw != bRaw) return aRaw < bRaw;
|
||||
return a.name < b.name;
|
||||
});
|
||||
|
||||
for (const auto& d : out) {
|
||||
if (infoCount >= 12) break;
|
||||
if (d.connected || d.paired || !isRawMacName(d)) {
|
||||
infoCmd += "printf '===BTDEV %s===\\n' " + shellQuote(d.mac) +
|
||||
"; timeout 1 bluetoothctl info " + shellQuote(d.mac) +
|
||||
" 2>/dev/null; ";
|
||||
@@ -571,9 +590,12 @@ std::vector<BtDeviceEntry> queryBtDevices() {
|
||||
}
|
||||
|
||||
std::sort(out.begin(), out.end(),
|
||||
[](const BtDeviceEntry& a, const BtDeviceEntry& b) {
|
||||
[&](const BtDeviceEntry& a, const BtDeviceEntry& b) {
|
||||
if (a.connected != b.connected) return a.connected > b.connected;
|
||||
if (a.paired != b.paired) return a.paired > b.paired;
|
||||
bool aRaw = isRawMacName(a);
|
||||
bool bRaw = isRawMacName(b);
|
||||
if (aRaw != bRaw) return aRaw < bRaw;
|
||||
return a.name < b.name;
|
||||
});
|
||||
return out;
|
||||
@@ -757,12 +779,13 @@ int runNetworksApp(int argc, char** argv) {
|
||||
} else if (activeTab == NetTab::Bluetooth) {
|
||||
btOn = isBtEnabledFast();
|
||||
if (btOn) {
|
||||
if (::access("/tmp/bananarchy_bt_obex.pid", F_OK) != 0) {
|
||||
int obexPid = readIntFile("/tmp/bananarchy_bt_obex.pid");
|
||||
if (obexPid <= 0 || ::kill(obexPid, 0) != 0) {
|
||||
runAsyncCmd("/usr/bin/bananarchy-bt-obex start >/dev/null 2>&1");
|
||||
}
|
||||
btRx = readBtRxStatus();
|
||||
if (forceScan) {
|
||||
runCaptureCmd("timeout 6 bluetoothctl --timeout 5 scan on >/dev/null 2>&1");
|
||||
runCaptureCmd("timeout 16 bluetoothctl --timeout 15 scan on >/dev/null 2>&1");
|
||||
}
|
||||
btList = queryBtDevices();
|
||||
} else {
|
||||
@@ -788,6 +811,7 @@ int runNetworksApp(int argc, char** argv) {
|
||||
};
|
||||
|
||||
auto textModeLabel = [&]() -> const char* {
|
||||
if (isExternalKeyboardActive()) return "KBD";
|
||||
switch (textMode) {
|
||||
case TextMode::Lower: return "abc";
|
||||
case TextMode::Title: return "Abc";
|
||||
@@ -800,43 +824,45 @@ int runNetworksApp(int argc, char** argv) {
|
||||
|
||||
auto handleMultiTapKey = [&](std::string& targetStr, KeySym sym,
|
||||
unsigned int kc, unsigned int state) -> bool {
|
||||
char dch = mapDialKey(sym, kc, state);
|
||||
if (dch == '#') {
|
||||
textMode = static_cast<TextMode>((static_cast<int>(textMode) + 1) % 5);
|
||||
lastTapDigit = -1;
|
||||
return true;
|
||||
}
|
||||
if (dch >= '0' && dch <= '9') {
|
||||
int digit = dch - '0';
|
||||
int64_t now = nowMs();
|
||||
if (textMode == TextMode::Num) {
|
||||
targetStr.push_back(dch);
|
||||
if (!isExternalKeyboardActive()) {
|
||||
char dch = mapDialKey(sym, kc, state);
|
||||
if (dch == '#') {
|
||||
textMode = static_cast<TextMode>((static_cast<int>(textMode) + 1) % 5);
|
||||
lastTapDigit = -1;
|
||||
return true;
|
||||
}
|
||||
const char* seq = (textMode == TextMode::Sym)
|
||||
? kSymTapMap[digit]
|
||||
: kMultiTapMap[digit];
|
||||
int seqLen = static_cast<int>(std::strlen(seq));
|
||||
if (seqLen <= 0) return false;
|
||||
if (dch >= '0' && dch <= '9') {
|
||||
int digit = dch - '0';
|
||||
int64_t now = nowMs();
|
||||
if (textMode == TextMode::Num) {
|
||||
targetStr.push_back(dch);
|
||||
lastTapDigit = -1;
|
||||
return true;
|
||||
}
|
||||
const char* seq = (textMode == TextMode::Sym)
|
||||
? kSymTapMap[digit]
|
||||
: kMultiTapMap[digit];
|
||||
int seqLen = static_cast<int>(std::strlen(seq));
|
||||
if (seqLen <= 0) return false;
|
||||
|
||||
if (digit == lastTapDigit && (now - lastTapMs) <= 850 && !targetStr.empty()) {
|
||||
popUtf8Char(targetStr);
|
||||
lastTapCycle = (lastTapCycle + 1) % seqLen;
|
||||
} else {
|
||||
lastTapDigit = digit;
|
||||
lastTapCycle = 0;
|
||||
}
|
||||
lastTapMs = now;
|
||||
if (digit == lastTapDigit && (now - lastTapMs) <= 850 && !targetStr.empty()) {
|
||||
popUtf8Char(targetStr);
|
||||
lastTapCycle = (lastTapCycle + 1) % seqLen;
|
||||
} else {
|
||||
lastTapDigit = digit;
|
||||
lastTapCycle = 0;
|
||||
}
|
||||
lastTapMs = now;
|
||||
|
||||
char outCh = seq[lastTapCycle];
|
||||
if (textMode == TextMode::Upper) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
} else if (textMode == TextMode::Title && targetStr.empty()) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
char outCh = seq[lastTapCycle];
|
||||
if (textMode == TextMode::Upper) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
} else if (textMode == TextMode::Title && targetStr.empty()) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
}
|
||||
targetStr.push_back(outCh);
|
||||
return true;
|
||||
}
|
||||
targetStr.push_back(outCh);
|
||||
return true;
|
||||
}
|
||||
if (sym == XK_BackSpace || sym == XK_Delete) {
|
||||
if (!targetStr.empty()) {
|
||||
@@ -1499,13 +1525,21 @@ int runNetworksApp(int argc, char** argv) {
|
||||
if (act == 0) {
|
||||
setBanner("Connecting " + targetBt.name + "...");
|
||||
render();
|
||||
runCaptureCmd("timeout 8 bluetoothctl connect " + shellQuote(targetBt.mac) +
|
||||
" >/dev/null 2>&1", &rc);
|
||||
runCaptureCmd("/usr/bin/bananarchy-bt-obex connect " +
|
||||
shellQuote(targetBt.mac) + " " +
|
||||
shellQuote(targetBt.name) + " >/dev/null 2>&1", &rc);
|
||||
refreshCurrentTab(false);
|
||||
if (rc == 0 && targetBt.kind == BtDevKind::Audio) {
|
||||
bool isConn = (rc == 0);
|
||||
for (const auto& d : btList) {
|
||||
if ((d.mac == targetBt.mac || d.name == targetBt.name) && d.connected) {
|
||||
isConn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isConn && targetBt.kind == BtDevKind::Audio) {
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
setBanner(rc == 0 ? ("Connected: " + targetBt.name) : "Connect failed");
|
||||
setBanner(isConn ? ("Connected: " + targetBt.name) : "Connect failed");
|
||||
} else if (act == 1) {
|
||||
setBanner("Disconnecting " + targetBt.name + "...");
|
||||
render();
|
||||
@@ -1516,14 +1550,23 @@ int runNetworksApp(int argc, char** argv) {
|
||||
} else if (act == 2) {
|
||||
setBanner("Pairing " + targetBt.name + "...");
|
||||
render();
|
||||
runCaptureCmd("timeout 10 bluetoothctl --timeout 8 pair " +
|
||||
shellQuote(targetBt.mac) +
|
||||
" >/dev/null 2>&1; timeout 2 bluetoothctl trust " +
|
||||
shellQuote(targetBt.mac) + " >/dev/null 2>&1; "
|
||||
"timeout 6 bluetoothctl connect " + shellQuote(targetBt.mac) +
|
||||
" >/dev/null 2>&1", &rc);
|
||||
runCaptureCmd("/usr/bin/bananarchy-bt-obex pair " +
|
||||
shellQuote(targetBt.mac) + " " +
|
||||
shellQuote(targetBt.name) + " >/dev/null 2>&1", &rc);
|
||||
refreshCurrentTab(false);
|
||||
setBanner("Paired & trusted " + targetBt.name);
|
||||
bool isPairedOrConn = (rc == 0);
|
||||
for (const auto& d : btList) {
|
||||
if ((d.mac == targetBt.mac || d.name == targetBt.name) &&
|
||||
(d.connected || d.paired)) {
|
||||
isPairedOrConn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isPairedOrConn && targetBt.kind == BtDevKind::Audio) {
|
||||
runAsyncCmd("sxmo_audio.sh device set Bluetooth >/dev/null 2>&1");
|
||||
}
|
||||
setBanner(isPairedOrConn ? ("Paired & connected: " + targetBt.name)
|
||||
: ("Pairing failed: " + targetBt.name));
|
||||
} else if (act == 3) {
|
||||
std::string macU = targetBt.mac;
|
||||
for (char& c : macU) {
|
||||
@@ -1678,7 +1721,7 @@ int runNetworksApp(int argc, char** argv) {
|
||||
lastTapDigit = -1;
|
||||
modal = NetModal::BtNameEditor;
|
||||
} else if (btRowSel == 3 && btOn) {
|
||||
setBanner("Scanning Bluetooth devices (5s)...");
|
||||
setBanner("Scanning Bluetooth devices (15s)...", 16000);
|
||||
render();
|
||||
refreshCurrentTab(true);
|
||||
setBanner("Found " + std::to_string(btList.size()) + " device(s)");
|
||||
@@ -1728,7 +1771,7 @@ int runNetworksApp(int argc, char** argv) {
|
||||
runCaptureCmd("SXMO_OS=alpine doas -n sxmo_bluetoothtoggle.sh on >/dev/null 2>&1");
|
||||
refreshCurrentTab(false);
|
||||
} else {
|
||||
setBanner("Scanning Bluetooth (5s)...");
|
||||
setBanner("Scanning Bluetooth (15s)...", 16000);
|
||||
render();
|
||||
refreshCurrentTab(true);
|
||||
setBanner("Found " + std::to_string(btList.size()) + " device(s)");
|
||||
@@ -1772,7 +1815,7 @@ int runNetworksApp(int argc, char** argv) {
|
||||
int64_t now = nowMs();
|
||||
if (now < startupIgnoreUntilMs) continue;
|
||||
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, (ev.xkey.state & ShiftMask) ? 1 : 0);
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
|
||||
bool isLSK = (kc == 135 || sym == XK_F1 || sym == XK_Menu ||
|
||||
@@ -1999,6 +2042,9 @@ int runNetworksApp(int argc, char** argv) {
|
||||
if (visible) render();
|
||||
} else if (cmd == "REFRESH_BT") {
|
||||
btRx = readBtRxStatus();
|
||||
if (visible && activeTab == NetTab::Bluetooth) {
|
||||
refreshCurrentTab(false);
|
||||
}
|
||||
if (visible) render();
|
||||
} else if (cmd == "TOGGLE") {
|
||||
if (visible) hideWindow();
|
||||
|
||||
@@ -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 (*)
|
||||
|
||||
@@ -470,6 +470,7 @@ int privacy_run_main(int argc, char** argv) {
|
||||
};
|
||||
|
||||
auto textModeBadge = [&]() -> const char* {
|
||||
if (isExternalKeyboardActive()) return "[KBD]";
|
||||
switch (textMode) {
|
||||
case TextMode::Lower: return "[abc]";
|
||||
case TextMode::Title: return "[Abc]";
|
||||
@@ -508,50 +509,52 @@ int privacy_run_main(int argc, char** argv) {
|
||||
|
||||
auto handleMultiTapKey = [&](std::string& targetStr, KeySym sym,
|
||||
unsigned int kc, unsigned int state) -> bool {
|
||||
char dch = mapDialKey(sym, kc, state);
|
||||
if (dch == '#') {
|
||||
textMode = static_cast<TextMode>((static_cast<int>(textMode) + 1) % 5);
|
||||
lastTapDigit = -1;
|
||||
return true;
|
||||
}
|
||||
if (dch == '*') {
|
||||
if (!targetStr.empty()) {
|
||||
popUtf8Char(targetStr);
|
||||
lastTapDigit = -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (dch >= '0' && dch <= '9') {
|
||||
int digit = dch - '0';
|
||||
int64_t now = nowMs();
|
||||
if (textMode == TextMode::Num) {
|
||||
targetStr.push_back(dch);
|
||||
if (!isExternalKeyboardActive()) {
|
||||
char dch = mapDialKey(sym, kc, state);
|
||||
if (dch == '#') {
|
||||
textMode = static_cast<TextMode>((static_cast<int>(textMode) + 1) % 5);
|
||||
lastTapDigit = -1;
|
||||
return true;
|
||||
}
|
||||
const char* seq = (textMode == TextMode::Sym)
|
||||
? kSymTapMap[digit]
|
||||
: kMultiTapMap[digit];
|
||||
int seqLen = static_cast<int>(std::strlen(seq));
|
||||
if (seqLen <= 0) return false;
|
||||
|
||||
if (digit == lastTapDigit && (now - lastTapMs) <= 850 && !targetStr.empty()) {
|
||||
popUtf8Char(targetStr);
|
||||
lastTapCycle = (lastTapCycle + 1) % seqLen;
|
||||
} else {
|
||||
lastTapDigit = digit;
|
||||
lastTapCycle = 0;
|
||||
if (dch == '*') {
|
||||
if (!targetStr.empty()) {
|
||||
popUtf8Char(targetStr);
|
||||
lastTapDigit = -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
lastTapMs = now;
|
||||
if (dch >= '0' && dch <= '9') {
|
||||
int digit = dch - '0';
|
||||
int64_t now = nowMs();
|
||||
if (textMode == TextMode::Num) {
|
||||
targetStr.push_back(dch);
|
||||
lastTapDigit = -1;
|
||||
return true;
|
||||
}
|
||||
const char* seq = (textMode == TextMode::Sym)
|
||||
? kSymTapMap[digit]
|
||||
: kMultiTapMap[digit];
|
||||
int seqLen = static_cast<int>(std::strlen(seq));
|
||||
if (seqLen <= 0) return false;
|
||||
|
||||
char outCh = seq[lastTapCycle];
|
||||
if (textMode == TextMode::Upper) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
} else if (textMode == TextMode::Title && targetStr.empty()) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
if (digit == lastTapDigit && (now - lastTapMs) <= 850 && !targetStr.empty()) {
|
||||
popUtf8Char(targetStr);
|
||||
lastTapCycle = (lastTapCycle + 1) % seqLen;
|
||||
} else {
|
||||
lastTapDigit = digit;
|
||||
lastTapCycle = 0;
|
||||
}
|
||||
lastTapMs = now;
|
||||
|
||||
char outCh = seq[lastTapCycle];
|
||||
if (textMode == TextMode::Upper) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
} else if (textMode == TextMode::Title && targetStr.empty()) {
|
||||
outCh = static_cast<char>(std::toupper(static_cast<unsigned char>(outCh)));
|
||||
}
|
||||
targetStr.push_back(outCh);
|
||||
return true;
|
||||
}
|
||||
targetStr.push_back(outCh);
|
||||
return true;
|
||||
}
|
||||
if (sym == XK_BackSpace || sym == XK_Delete) {
|
||||
if (!targetStr.empty()) {
|
||||
@@ -1147,7 +1150,7 @@ int privacy_run_main(int argc, char** argv) {
|
||||
if (!visible) continue;
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
unsigned int st = ev.xkey.state;
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, (st & ShiftMask) ? 1 : 0);
|
||||
|
||||
if (querySoftkeysDown(dpy) == 3) {
|
||||
writeSoftkeySuppress(nowMs() + 400);
|
||||
|
||||
@@ -706,6 +706,8 @@ int runSmsApp(int argc, char** argv) {
|
||||
const char* modeBadge = "[Abc]";
|
||||
if (composeField == 0) {
|
||||
modeBadge = "[123]";
|
||||
} else if (isExternalKeyboardActive()) {
|
||||
modeBadge = "[KBD]";
|
||||
} else if (caseMode == TextCaseMode::Upper) {
|
||||
modeBadge = "[ABC]";
|
||||
} else if (caseMode == TextCaseMode::Lower) {
|
||||
@@ -1393,7 +1395,7 @@ int runSmsApp(int argc, char** argv) {
|
||||
} else if (ev.type == KeyPress) {
|
||||
int64_t tNow = nowMs();
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, (ev.xkey.state & ShiftMask) ? 1 : 0);
|
||||
|
||||
bool isLeftSk =
|
||||
(kc == 135 || sym == XK_Menu || sym == XF86XK_KbdLcdMenu1 ||
|
||||
@@ -1576,19 +1578,26 @@ int runSmsApp(int argc, char** argv) {
|
||||
drawUI();
|
||||
}
|
||||
} else if (composeField == 1) {
|
||||
if (d == '#') {
|
||||
lastTapDigit = -1;
|
||||
caseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(caseMode) + 1) % 4);
|
||||
drawUI();
|
||||
} else if (d == '*') {
|
||||
commitMultiTapChar(1);
|
||||
drawUI();
|
||||
} else if (d >= '0' && d <= '9') {
|
||||
commitMultiTapChar(d - '0');
|
||||
drawUI();
|
||||
} else if (sym == XK_space) {
|
||||
composeText.push_back(' ');
|
||||
if (!isExternalKeyboardActive()) {
|
||||
if (d == '#') {
|
||||
lastTapDigit = -1;
|
||||
caseMode = static_cast<TextCaseMode>(
|
||||
(static_cast<int>(caseMode) + 1) % 4);
|
||||
drawUI();
|
||||
continue;
|
||||
} else if (d == '*') {
|
||||
commitMultiTapChar(1);
|
||||
drawUI();
|
||||
continue;
|
||||
} else if (d >= '0' && d <= '9') {
|
||||
commitMultiTapChar(d - '0');
|
||||
drawUI();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (sym >= 0x20 && sym <= 0x7e &&
|
||||
!(ev.xkey.state & (ControlMask | Mod1Mask))) {
|
||||
composeText.push_back(static_cast<char>(sym));
|
||||
lastTapDigit = -1;
|
||||
drawUI();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
+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 == '*' ||
|
||||
|
||||
+66
-1
@@ -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
@@ -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
|
||||
|
||||
+32
-12
@@ -270,21 +270,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;
|
||||
Pixmap blank;
|
||||
XColor dummy;
|
||||
static const char data[1] = {0};
|
||||
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
|
||||
};
|
||||
|
||||
(void)shape;
|
||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
||||
return NULL;
|
||||
(void)shape;
|
||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
||||
return NULL;
|
||||
|
||||
memset(&dummy, 0, sizeof(dummy));
|
||||
blank = XCreateBitmapFromData(drw->dpy, drw->root, data, 1, 1);
|
||||
cur->cursor = XCreatePixmapCursor(drw->dpy, blank, blank, &dummy, &dummy, 0, 0);
|
||||
XFreePixmap(drw->dpy, blank);
|
||||
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
|
||||
|
||||
+169
-31
@@ -330,7 +330,7 @@ static xcb_connection_t *xcon;
|
||||
|
||||
static struct HoldKey *holdkeyroot = NULL;
|
||||
|
||||
#define MAX_INPUT_FDS 8
|
||||
#define MAX_INPUT_FDS 16
|
||||
static int input_fds[MAX_INPUT_FDS];
|
||||
static int num_input_fds = 0;
|
||||
static long long last_wake_ms = 0;
|
||||
@@ -2089,6 +2089,115 @@ flush_pending_softkey(void)
|
||||
|
||||
static long long last_mouse_ms = 0;
|
||||
static int cursor_hidden = 0;
|
||||
static int prev_ext_mouse = 0;
|
||||
static time_t last_mouse_dev_sec = 0;
|
||||
static long last_mouse_dev_nsec = 0;
|
||||
|
||||
static void
|
||||
dwm_rescan_input_fds(int force)
|
||||
{
|
||||
static time_t last_scan_sec = 0;
|
||||
static long last_scan_nsec = 0;
|
||||
struct stat st;
|
||||
int i;
|
||||
|
||||
if (!force && stat("/dev/input", &st) == 0) {
|
||||
if (st.st_mtim.tv_sec == last_scan_sec &&
|
||||
st.st_mtim.tv_nsec == last_scan_nsec) {
|
||||
return;
|
||||
}
|
||||
last_scan_sec = st.st_mtim.tv_sec;
|
||||
last_scan_nsec = st.st_mtim.tv_nsec;
|
||||
} else if (stat("/dev/input", &st) == 0) {
|
||||
last_scan_sec = st.st_mtim.tv_sec;
|
||||
last_scan_nsec = st.st_mtim.tv_nsec;
|
||||
}
|
||||
if (force) {
|
||||
last_mouse_dev_sec = 0;
|
||||
last_mouse_dev_nsec = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_input_fds; i++) {
|
||||
if (input_fds[i] >= 0)
|
||||
close(input_fds[i]);
|
||||
}
|
||||
num_input_fds = 0;
|
||||
for (i = 0; i < MAX_INPUT_FDS; i++) {
|
||||
char evpath[64], evname[128] = "";
|
||||
int evfd;
|
||||
snprintf(evpath, sizeof(evpath), "/dev/input/event%d", i);
|
||||
evfd = open(evpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (evfd < 0)
|
||||
continue;
|
||||
if (ioctl(evfd, EVIOCGNAME(sizeof(evname)), evname) >= 0 &&
|
||||
strstr(evname, "Jack") != NULL) {
|
||||
close(evfd);
|
||||
continue;
|
||||
}
|
||||
input_fds[num_input_fds++] = evfd;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
dwm_has_external_mouse(void)
|
||||
{
|
||||
static int cached = 0;
|
||||
struct stat st;
|
||||
if (stat("/dev/input", &st) == 0) {
|
||||
if (st.st_mtim.tv_sec == last_mouse_dev_sec &&
|
||||
st.st_mtim.tv_nsec == last_mouse_dev_nsec) {
|
||||
return cached;
|
||||
}
|
||||
last_mouse_dev_sec = st.st_mtim.tv_sec;
|
||||
last_mouse_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_mouse_handler = 0;
|
||||
int has_rel_xy = 0;
|
||||
int found = 0;
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
if (line[0] == '\n' || line[0] == '\r') {
|
||||
if (is_ext_bus && (has_mouse_handler || has_rel_xy)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
is_ext_bus = 0;
|
||||
has_mouse_handler = 0;
|
||||
has_rel_xy = 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, "mouse"))
|
||||
has_mouse_handler = 1;
|
||||
} else if (is_ext_bus && strncmp(line, "B: REL=", 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 & 0x3ULL) == 0x3ULL)
|
||||
has_rel_xy = 1;
|
||||
}
|
||||
}
|
||||
if (!found && is_ext_bus && (has_mouse_handler || has_rel_xy))
|
||||
found = 1;
|
||||
fclose(fp);
|
||||
cached = found;
|
||||
return cached;
|
||||
}
|
||||
|
||||
static void
|
||||
dwm_cursor_set_visible(int show)
|
||||
@@ -2108,19 +2217,37 @@ dwm_cursor_set_visible(int show)
|
||||
fn_show = (xfixes_cursor_fn)dlsym(h, "XFixesShowCursor");
|
||||
}
|
||||
}
|
||||
if (show) {
|
||||
last_mouse_ms = dwm_now_ms();
|
||||
if (cursor_hidden && fn_show) {
|
||||
fn_show(dpy, root);
|
||||
cursor_hidden = 0;
|
||||
XFlush(dpy);
|
||||
}
|
||||
} else {
|
||||
if (!cursor_hidden && fn_hide) {
|
||||
fn_hide(dpy, root);
|
||||
cursor_hidden = 1;
|
||||
XFlush(dpy);
|
||||
if (show) {
|
||||
last_mouse_ms = dwm_now_ms();
|
||||
if (cursor_hidden && fn_show) {
|
||||
fn_show(dpy, root);
|
||||
cursor_hidden = 0;
|
||||
}
|
||||
if (cursor[CurNormal])
|
||||
XDefineCursor(dpy, root, cursor[CurNormal]->cursor);
|
||||
XFlush(dpy);
|
||||
} else {
|
||||
if (!cursor_hidden && fn_hide) {
|
||||
fn_hide(dpy, root);
|
||||
cursor_hidden = 1;
|
||||
XFlush(dpy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dwm_sync_mouse_cursor(void)
|
||||
{
|
||||
int ext_mouse = dwm_has_external_mouse();
|
||||
if (ext_mouse) {
|
||||
if (!prev_ext_mouse && dpy && root) {
|
||||
XWarpPointer(dpy, None, root, 0, 0, 0, 0, sw / 2, sh / 2);
|
||||
}
|
||||
prev_ext_mouse = 1;
|
||||
dwm_cursor_set_visible(1);
|
||||
} else if (prev_ext_mouse) {
|
||||
prev_ext_mouse = 0;
|
||||
dwm_cursor_set_visible(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2241,7 +2368,8 @@ keypress(XEvent *e)
|
||||
|
||||
ev = &e->xkey;
|
||||
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
|
||||
if (cursor_hidden == 0 && (dwm_now_ms() - last_mouse_ms) > 4000)
|
||||
dwm_sync_mouse_cursor();
|
||||
if (!dwm_has_external_mouse() && cursor_hidden == 0 && (dwm_now_ms() - last_mouse_ms) > 4000)
|
||||
dwm_cursor_set_visible(0);
|
||||
|
||||
if (is_screen_off()) {
|
||||
@@ -2386,7 +2514,8 @@ keyrelease(XEvent *e)
|
||||
|
||||
ev = &e->xkey;
|
||||
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
|
||||
if (cursor_hidden == 0 && (dwm_now_ms() - last_mouse_ms) > 4000)
|
||||
dwm_sync_mouse_cursor();
|
||||
if (!dwm_has_external_mouse() && cursor_hidden == 0 && (dwm_now_ms() - last_mouse_ms) > 4000)
|
||||
dwm_cursor_set_visible(0);
|
||||
|
||||
markreleased(keysym);
|
||||
@@ -2642,6 +2771,7 @@ propertynotify(XEvent *e)
|
||||
XPropertyEvent *ev = &e->xproperty;
|
||||
|
||||
if (ev->window == root) {
|
||||
dwm_sync_mouse_cursor();
|
||||
if (ev->atom == XA_WM_NAME)
|
||||
updatestatus();
|
||||
else if (ev->atom == XA_RESOURCE_MANAGER)
|
||||
@@ -2835,6 +2965,8 @@ run(void)
|
||||
}
|
||||
if (!running)
|
||||
break;
|
||||
dwm_rescan_input_fds(0);
|
||||
dwm_sync_mouse_cursor();
|
||||
fds[0].fd = xfd;
|
||||
fds[0].events = POLLIN;
|
||||
fds[0].revents = 0;
|
||||
@@ -2882,14 +3014,22 @@ run(void)
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < num_input_fds; i++) {
|
||||
if (fds[1 + i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
|
||||
dwm_rescan_input_fds(1);
|
||||
dwm_sync_mouse_cursor();
|
||||
break;
|
||||
}
|
||||
if (fds[1 + i].revents & POLLIN) {
|
||||
while (read(input_fds[i], &ie, sizeof(ie)) == (ssize_t)sizeof(ie)) {
|
||||
ssize_t nread;
|
||||
while ((nread = read(input_fds[i], &ie, sizeof(ie))) == (ssize_t)sizeof(ie)) {
|
||||
if (ie.type == EV_SW && ie.code == SW_LID) {
|
||||
if (ie.value == 1) {
|
||||
lock_phone_screenoff();
|
||||
} else if (ie.value == 0) {
|
||||
wake_phone();
|
||||
}
|
||||
} else if (ie.type == EV_REL && ie.value != 0) {
|
||||
dwm_cursor_set_visible(1);
|
||||
} else if (ie.type == EV_KEY) {
|
||||
if (ie.code == 522 || ie.code == 55)
|
||||
star_down = (ie.value != 0);
|
||||
@@ -2912,6 +3052,11 @@ run(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nread < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
|
||||
dwm_rescan_input_fds(1);
|
||||
dwm_sync_mouse_cursor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fds[0].revents & (POLLIN | POLLHUP | POLLERR)) {
|
||||
@@ -3147,20 +3292,7 @@ setup(void)
|
||||
|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|KeyPressMask|KeyReleaseMask;
|
||||
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
|
||||
XSelectInput(dpy, root, wa.event_mask);
|
||||
num_input_fds = 0;
|
||||
for (i = 0; i < MAX_INPUT_FDS; i++) {
|
||||
char evpath[64], evname[128] = "";
|
||||
int evfd;
|
||||
snprintf(evpath, sizeof(evpath), "/dev/input/event%d", i);
|
||||
evfd = open(evpath, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (evfd < 0)
|
||||
continue;
|
||||
if (ioctl(evfd, EVIOCGNAME(sizeof(evname)), evname) >= 0 && strstr(evname, "Jack") != NULL) {
|
||||
close(evfd);
|
||||
continue;
|
||||
}
|
||||
input_fds[num_input_fds++] = evfd;
|
||||
}
|
||||
dwm_rescan_input_fds(1);
|
||||
unlink("/tmp/sxmo_softkey_suppress");
|
||||
unlink("/tmp/sxmo_softkey_state");
|
||||
{
|
||||
@@ -3173,7 +3305,13 @@ setup(void)
|
||||
load_plugins();
|
||||
grabkeys();
|
||||
focus(NULL);
|
||||
dwm_cursor_set_visible(0);
|
||||
if (dwm_has_external_mouse()) {
|
||||
prev_ext_mouse = 1;
|
||||
XWarpPointer(dpy, None, root, 0, 0, 0, 0, sw / 2, sh / 2);
|
||||
dwm_cursor_set_visible(1);
|
||||
} else {
|
||||
dwm_cursor_set_visible(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1158,10 +1158,8 @@ void
|
||||
xinit(int cols, int rows)
|
||||
{
|
||||
XGCValues gcvalues;
|
||||
Cursor cursor;
|
||||
Window parent;
|
||||
pid_t thispid = getpid();
|
||||
XColor xmousefg, xmousebg;
|
||||
|
||||
xw.scr = XDefaultScreen(xw.dpy);
|
||||
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
|
||||
@@ -1222,18 +1220,6 @@ xinit(int cols, int rows)
|
||||
ximinstantiate, NULL);
|
||||
}
|
||||
|
||||
/* invisible 1x1 cursor for keypad-only hardware */
|
||||
{
|
||||
Pixmap blank;
|
||||
static const char blankdata[1] = {0};
|
||||
memset(&xmousefg, 0, sizeof(xmousefg));
|
||||
memset(&xmousebg, 0, sizeof(xmousebg));
|
||||
blank = XCreateBitmapFromData(xw.dpy, xw.win, blankdata, 1, 1);
|
||||
cursor = XCreatePixmapCursor(xw.dpy, blank, blank, &xmousefg, &xmousebg, 0, 0);
|
||||
XFreePixmap(xw.dpy, blank);
|
||||
XDefineCursor(xw.dpy, xw.win, cursor);
|
||||
}
|
||||
|
||||
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
|
||||
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
|
||||
xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
|
||||
|
||||
Reference in new issue
Block a user