Harden DWM plugins against X11 stacking/keyboard grab races and speed up QMI status
This commit is contained in:
1 parent
b2216c186f
commit
e77be498bf
44 files changed
+432
-211
No files matched your search
@@ -364,13 +364,26 @@ ModemStatusData queryModemAndSimStatus() {
|
||||
}
|
||||
|
||||
// 3. Query active SIM object if available
|
||||
static std::string cachedSimPath;
|
||||
static std::string cachedSimIccid;
|
||||
static std::string cachedSimOperator;
|
||||
if (!d.simDbusPath.empty()) {
|
||||
std::string simOut = runCaptureCmd(
|
||||
"mmcli -i " + shellQuote(d.simDbusPath) + " -K 2>/dev/null");
|
||||
std::unordered_map<std::string, std::string> simKv;
|
||||
parseKvLines(simOut, simKv, ':');
|
||||
d.simIccid = cleanMmVal(simKv["sim.properties.iccid"]);
|
||||
d.simOperatorName = cleanMmVal(simKv["sim.properties.operator-name"]);
|
||||
if (d.simDbusPath == cachedSimPath && !cachedSimIccid.empty()) {
|
||||
d.simIccid = cachedSimIccid;
|
||||
d.simOperatorName = cachedSimOperator;
|
||||
} else {
|
||||
std::string simOut = runCaptureCmd(
|
||||
"mmcli -i " + shellQuote(d.simDbusPath) + " -K 2>/dev/null");
|
||||
std::unordered_map<std::string, std::string> simKv;
|
||||
parseKvLines(simOut, simKv, ':');
|
||||
d.simIccid = cleanMmVal(simKv["sim.properties.iccid"]);
|
||||
d.simOperatorName = cleanMmVal(simKv["sim.properties.operator-name"]);
|
||||
if (!d.simIccid.empty()) {
|
||||
cachedSimPath = d.simDbusPath;
|
||||
cachedSimIccid = d.simIccid;
|
||||
cachedSimOperator = d.simOperatorName;
|
||||
}
|
||||
}
|
||||
if (d.operatorName.empty() && !d.simOperatorName.empty()) {
|
||||
d.operatorName = d.simOperatorName;
|
||||
}
|
||||
@@ -609,6 +622,10 @@ int runModemApp(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
lastRefreshMs = nowMs();
|
||||
if (visible && !isAnotherPluginActive("modem")) {
|
||||
XRaiseWindow(dpy, win);
|
||||
grabPluginKeyboard(dpy, win);
|
||||
}
|
||||
};
|
||||
|
||||
auto defaultActiveOrPresentSlot = [&]() -> int {
|
||||
@@ -1222,13 +1239,7 @@ int runModemApp(int argc, char** argv) {
|
||||
};
|
||||
|
||||
auto grabKeys = [&]() {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
|
||||
CurrentTime) == GrabSuccess) {
|
||||
break;
|
||||
}
|
||||
usleep(15000);
|
||||
}
|
||||
grabPluginKeyboard(dpy, win);
|
||||
};
|
||||
|
||||
auto showWindow = [&](const std::string& arg = "") {
|
||||
@@ -1236,21 +1247,28 @@ int runModemApp(int argc, char** argv) {
|
||||
if (visible &&
|
||||
(modal == ModalMode::VerifyPin || modal == ModalMode::UnblockPuk) &&
|
||||
(a == "unlock" || a == "pin" || a == "puk")) {
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
XRaiseWindow(dpy, win);
|
||||
grabKeys();
|
||||
render();
|
||||
return;
|
||||
}
|
||||
closeOtherPlugins("modem");
|
||||
refreshData(true);
|
||||
applyOpenArg(arg);
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
if (!visible) {
|
||||
XMapRaised(dpy, win);
|
||||
visible = true;
|
||||
} else {
|
||||
XRaiseWindow(dpy, win);
|
||||
}
|
||||
grabKeys();
|
||||
render();
|
||||
refreshData(true);
|
||||
applyOpenArg(arg);
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("modem");
|
||||
XRaiseWindow(dpy, win);
|
||||
openStartMs = nowMs();
|
||||
startupIgnoreUntilMs = openStartMs + 180;
|
||||
initialSoftkeysReleased = (querySoftkeysDown(dpy) == 0);
|
||||
@@ -1446,6 +1464,10 @@ int runModemApp(int argc, char** argv) {
|
||||
if (ussdWaitingReply) {
|
||||
ussdInput.clear();
|
||||
}
|
||||
if (visible) {
|
||||
XRaiseWindow(dpy, win);
|
||||
grabKeys();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1693,7 +1715,13 @@ int runModemApp(int argc, char** argv) {
|
||||
render();
|
||||
} else if (ev.type == VisibilityNotify && visible &&
|
||||
ev.xvisibility.state != VisibilityUnobscured) {
|
||||
XRaiseWindow(dpy, win);
|
||||
if (isAnotherPluginActive("modem")) {
|
||||
hideWindow();
|
||||
} else {
|
||||
XRaiseWindow(dpy, win);
|
||||
grabKeys();
|
||||
render();
|
||||
}
|
||||
} else if (ev.type == KeyRelease) {
|
||||
if (!initialSoftkeysReleased && querySoftkeysDown(dpy) == 0) {
|
||||
initialSoftkeysReleased = true;
|
||||
@@ -2033,14 +2061,14 @@ int runModemApp(int argc, char** argv) {
|
||||
timeoutMs = static_cast<int>(bRem);
|
||||
}
|
||||
}
|
||||
// Periodic 5-second status refresh while visible on SIM/Radio tabs
|
||||
// Periodic 10-second status refresh while visible on SIM/Radio tabs
|
||||
if (modal == ModalMode::None && activeTab != TabId::ModemLog &&
|
||||
activeTab != TabId::AtConsole) {
|
||||
int64_t rRem = (lastRefreshMs + 5000) - now;
|
||||
int64_t rRem = (lastRefreshMs + 10000) - now;
|
||||
if (rRem <= 0) {
|
||||
refreshData(false);
|
||||
render();
|
||||
rRem = 5000;
|
||||
rRem = 10000;
|
||||
}
|
||||
if (timeoutMs < 0 || rRem < timeoutMs) {
|
||||
timeoutMs = static_cast<int>(rRem);
|
||||
|
||||
Reference in new issue
Block a user