Fix 2720 closed-flip call wakeups/preservation, live timezone sync, and Power menu

- Default CPU_RPM_SLEEP=0, CPU_L2_SLEEP=0, and MODEM_DRX_MODE=0 across bananarchy-power-policy.conf, bananarchy-power-policy.sh, bananarchy-display-power-sync, and kernel patch 0010 so closed-flip incoming calls wake APSS promptly via smd-edge without AT port contention.
- Serialize sxmo_modem.sh incoming/finished call checks, expire stale /tmp/sxmo_hangup_requested flags, re-verify live ModemManager call state before ringing/raising callscreen, guard idle/flip-open HANGUP_CLOSE paths in locker.so, callscreen.so, bananarchy-idle-lock.sh, and bananarchy-lid, preserve calls on flip-open (UNGRAB/RAISE), and add closed-flip cover call controls (bananarchy-cover-idle, bananarchy-cover-event.sh, bananarchy-volume-keys).
- Propagate live network/manual timezone updates across statusbar, locker.so, bananarchy-cover-idle, bananarchy-dsds, callscreen.so, and bananarchy-run-aligned without reboot (scripts/test-time-timezone-sync.py), remove non-functional Logout from the Power menu, ignore post-call sxmo_calls markers, add scripts/build-dwm-plugins.sh, and update a1114 (carbonara) hashes and docs.
This commit is contained in:
Luxferre committed 2026-11-14 10:57:29 +02:00
1 parent 786480a08f
commit 8b466ef8ae
110 files changed
+2728 -285

No files matched your search

+171 -37
View File
@@ -27,7 +27,9 @@
#include <poll.h>
#include <sstream>
#include <string>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
#include <vector>
@@ -300,26 +302,83 @@ void finalizeWavHeader(const std::string& path) {
::close(fd);
}
void wakeDisplayHardware(Display* dpy) {
bool isFlipDevice() {
int profFd = ::open("/usr/share/bananarchy/lid-profile", O_RDONLY | O_CLOEXEC);
bool isFlip = false;
if (profFd >= 0) {
char profBuf[16] {};
ssize_t pn = ::read(profFd, profBuf, sizeof(profBuf) - 1);
::close(profFd);
isFlip = (pn >= 4 && std::strncmp(profBuf, "flip", 4) == 0 &&
(profBuf[4] == '\0' || profBuf[4] == '\n' || profBuf[4] == '\r'));
if (profFd < 0) {
return false;
}
int lidFd = isFlip ? ::open("/run/bananarchy/lid-state", O_RDONLY | O_CLOEXEC) : -1;
if (lidFd >= 0) {
char lidBuf[32] {};
ssize_t n = ::read(lidFd, lidBuf, sizeof(lidBuf) - 1);
::close(lidFd);
if (n >= 6 && std::strncmp(lidBuf, "closed", 6) == 0) {
runAsyncArgv("/usr/bin/bananarchy-lid-gate.sh", "wake");
return;
char profBuf[16] {};
ssize_t pn = ::read(profFd, profBuf, sizeof(profBuf) - 1);
::close(profFd);
return (pn >= 4 && std::strncmp(profBuf, "flip", 4) == 0 &&
(profBuf[4] == '\0' || profBuf[4] == '\n' || profBuf[4] == '\r'));
}
bool isFlipClosed() {
if (!isFlipDevice()) {
return false;
}
int lidFd = ::open("/run/bananarchy/lid-state", O_RDONLY | O_CLOEXEC);
if (lidFd < 0) {
return false;
}
char lidBuf[32] {};
ssize_t n = ::read(lidFd, lidBuf, sizeof(lidBuf) - 1);
::close(lidFd);
return (n >= 6 && std::strncmp(lidBuf, "closed", 6) == 0);
}
std::string sanitizeCoverField(const std::string& raw) {
std::string out;
out.reserve(raw.size());
for (char c : raw) {
if (c == '|' || c == '\n' || c == '\r' || c == '\t') {
out.push_back(' ');
} else {
out.push_back(c);
}
}
return out;
}
void notifyCoverCall(const char* status, const std::string& number,
const std::string& name, int simSlot) {
if (!isFlipDevice() || !status || !*status) {
return;
}
int fd = ::socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (fd < 0) {
return;
}
struct sockaddr_un addr {};
addr.sun_family = AF_UNIX;
std::snprintf(addr.sun_path, sizeof(addr.sun_path), "%s",
"/run/bananarchy/cover.sock");
std::string safeNum = sanitizeCoverField(number);
std::string safeName = sanitizeCoverField(name);
char simBuf[16] {};
if (simSlot == 1 || simSlot == 2) {
std::snprintf(simBuf, sizeof(simBuf), "SIM%d", simSlot);
}
char msg[384];
int len = std::snprintf(msg, sizeof(msg), "CALL %s|%s|%s|%s\n",
status, safeNum.c_str(), safeName.c_str(), simBuf);
if (len > 0) {
size_t sendLen = static_cast<size_t>(len) < sizeof(msg)
? static_cast<size_t>(len)
: sizeof(msg) - 1;
(void)::sendto(fd, msg, sendLen, MSG_DONTWAIT | MSG_NOSIGNAL,
reinterpret_cast<const struct sockaddr*>(&addr),
sizeof(addr));
}
::close(fd);
}
void wakeDisplayHardware(Display* dpy) {
if (isFlipClosed()) {
runAsyncArgv("/usr/bin/bananarchy-lid-gate.sh", "wake");
return;
}
int saved = readIntFile("/tmp/sxmo_saved_brightness", -1);
if (saved <= 1) {
saved = readIntFile("/sys/class/backlight/backlight/max_brightness", 14);
@@ -504,6 +563,7 @@ int callscreen_run_main(int argc, char** argv) {
int64_t callStartMs = 0;
int64_t endedAtMs = 0;
int64_t lastHangupMs = 0;
std::string lastRejectedCallId;
int lastFinalDurationSec = 0;
int64_t lastModemPollMs = 0;
@@ -796,6 +856,7 @@ int callscreen_run_main(int argc, char** argv) {
return true;
}
std::string dir = getRecordingsDir();
refreshLocalTimezone();
time_t nowSec = ::time(nullptr);
struct tm tmNow {};
localtime_r(&nowSec, &tmNow);
@@ -1289,8 +1350,13 @@ int callscreen_run_main(int argc, char** argv) {
auto showWindow = [&]() {
writeIntFile(activePidPath, static_cast<int>(::getpid()));
closeOtherPlugins("callscreen");
closeOtherPlugins("callscreen", "locker");
if (isFlipClosed()) {
runAsyncArgv("/usr/bin/bananarchy-lid-gate.sh", "wake");
return;
}
wakeDisplayHardware(dpy);
sendPluginCommand("locker", "UNGRAB");
theme.checkAndReload(dpy, screen, visual, cmap, layoutMain, layoutSmall,
layoutIcon, layoutNum, win);
reloadContactsIfNeeded();
@@ -1351,6 +1417,9 @@ int callscreen_run_main(int argc, char** argv) {
if (d) {
struct dirent* ent;
while ((ent = ::readdir(d)) != nullptr) {
if (!isLiveSxmoCallFile(callsDir, ent->d_name)) {
continue;
}
std::string name = ent->d_name;
size_t dot = name.find('.');
if (dot != std::string::npos && dot > 0) {
@@ -1381,10 +1450,9 @@ int callscreen_run_main(int argc, char** argv) {
auto stopRingingJobs = [&]() {
::unlink("/tmp/sxmo_call_ringing");
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
"pkill -TERM -f sxmo_hook_ring.sh >/dev/null 2>&1; "
"pkill -TERM -f 'pw-play.*ring' >/dev/null 2>&1; "
"pkill -TERM -f 'mpv.*ring' >/dev/null 2>&1; "
"pkill -TERM -x sxmo_vibrate >/dev/null 2>&1");
"killall -q -TERM bananarchy-melody pw-play mpv sxmo_vibrate >/dev/null 2>&1; "
"pids=\"$(pgrep -f '[s]xmo_hook_ring\\.sh|[p]w-play.*ring|[m]pv.*ring' 2>/dev/null)\"; "
"[ -n \"$pids\" ] && kill -TERM $pids >/dev/null 2>&1 || true");
};
auto acceptIncomingCall = [&]() {
@@ -1400,6 +1468,7 @@ int callscreen_run_main(int argc, char** argv) {
selectedRow = 0;
writeActiveStateFiles();
stopRingingJobs();
notifyCoverCall("active", callNumber, contactName, activeSimSlot);
setSpeakerRoute(false, hasBtAudioCard());
render();
@@ -1418,6 +1487,7 @@ int callscreen_run_main(int argc, char** argv) {
}
ringMuted = true;
stopRingingJobs();
notifyCoverCall("muted", callNumber, contactName, activeSimSlot);
std::string cid = resolveActiveModemCallId();
if (cid.rfind("sip:", 0) == 0) {
sendPluginCommand("sip", "CALL_MUTE_RING " + cid);
@@ -1432,6 +1502,7 @@ int callscreen_run_main(int argc, char** argv) {
};
auto transitionToEnded = [&](const std::string& reason) {
bool wasIncoming = (callState == CallState::Incoming);
stopRecording();
if (micMuted) {
setMicMuted(false);
@@ -1450,13 +1521,13 @@ int callscreen_run_main(int argc, char** argv) {
ringMuted = false;
writeActiveStateFiles();
stopRingingJobs();
if (wasIncoming && endReason == "CALL ENDED") {
notifyCoverCall("missed", callNumber, contactName, activeSimSlot);
} else {
notifyCoverCall("none", "", "", 0);
}
btAudioOn = false;
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
"pkill -TERM -f sxmo_hook_ring.sh >/dev/null 2>&1; "
"pkill -TERM -f 'pw-play.*ring' >/dev/null 2>&1; "
"pkill -TERM -f 'mpv.*ring' >/dev/null 2>&1; "
"pkill -TERM -x sxmo_vibrate >/dev/null 2>&1; "
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
runAsyncCmd("sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
render();
};
@@ -1468,6 +1539,7 @@ int callscreen_run_main(int argc, char** argv) {
setMicMuted(false);
}
stopRingingJobs();
notifyCoverCall("none", "", "", 0);
btAudioOn = false;
dtmfMode = false;
ringMuted = false;
@@ -1480,12 +1552,7 @@ int callscreen_run_main(int argc, char** argv) {
missingModemPolls = 0;
writeActiveStateFiles();
hideWindow(false);
runAsyncCmd("sxmo_jobs.sh stop ringing >/dev/null 2>&1; "
"pkill -TERM -f sxmo_hook_ring.sh >/dev/null 2>&1; "
"pkill -TERM -f 'pw-play.*ring' >/dev/null 2>&1; "
"pkill -TERM -f 'mpv.*ring' >/dev/null 2>&1; "
"pkill -TERM -x sxmo_vibrate >/dev/null 2>&1; "
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
runAsyncCmd("sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
};
auto hangupQmiVoiceCallsNow = [&]() {
@@ -1575,6 +1642,7 @@ int callscreen_run_main(int argc, char** argv) {
::sendto(sfd, infoReq, sizeof(infoReq), 0,
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
std::vector<uint8_t> cidsToHangup;
bool gotCallInfo = false;
int64_t infoDeadline = nowMs() + 80;
while (nowMs() < infoDeadline) {
int waitMs = static_cast<int>(std::max<int64_t>(2, infoDeadline - nowMs()));
@@ -1583,6 +1651,7 @@ int callscreen_run_main(int argc, char** argv) {
ssize_t rlen = ::recv(sfd, buf, sizeof(buf), 0);
if (rlen >= 7 && buf[0] == 0x02 && buf[1] == 0x02 && buf[2] == 0x00 &&
buf[3] == 0x2F && buf[4] == 0x00) {
gotCallInfo = true;
const uint8_t* rawCi01 = nullptr;
uint16_t lenCi01 = 0;
const uint8_t* rawCi10 = nullptr;
@@ -1619,7 +1688,7 @@ int callscreen_run_main(int argc, char** argv) {
break;
}
}
if (cidsToHangup.empty()) {
if (!gotCallInfo && cidsToHangup.empty()) {
cidsToHangup.push_back(1);
}
uint8_t txn = 3;
@@ -1651,6 +1720,11 @@ int callscreen_run_main(int argc, char** argv) {
lastHangupMs = nowMs();
writeIntFile("/tmp/sxmo_hangup_requested", 1);
std::string cid = resolveActiveModemCallId();
if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
lastRejectedCallId = cid;
} else {
lastRejectedCallId.clear();
}
bool wasIncoming = (callState == CallState::Incoming);
stopRingingJobs();
if (cid.rfind("sip:", 0) == 0 || activeSimSlot == 3) {
@@ -1670,7 +1744,9 @@ int callscreen_run_main(int argc, char** argv) {
fn.find(".ringing-in") != std::string::npos ||
fn.find(".dialing") != std::string::npos ||
fn.find(".ringing-out") != std::string::npos ||
fn.find(".active") != std::string::npos) {
fn.find(".active") != std::string::npos ||
fn.find(".held") != std::string::npos ||
fn.find(".waiting") != std::string::npos) {
std::string fpPath = callsDir + "/" + fn;
::unlink(fpPath.c_str());
}
@@ -1993,6 +2069,7 @@ int callscreen_run_main(int argc, char** argv) {
ringMuted = false;
writeActiveStateFiles();
stopRingingJobs();
notifyCoverCall("active", callNumber, contactName, activeSimSlot);
setSpeakerRoute(speakerOn, btAudioOn);
render();
} else if (foundState == "ringing-in" && callState == CallState::Idle) {
@@ -2000,6 +2077,7 @@ int callscreen_run_main(int argc, char** argv) {
callStartMs = nowMs();
selectedRow = 0;
writeActiveStateFiles();
notifyCoverCall("incoming", callNumber, contactName, activeSimSlot);
render();
} else if ((foundState == "dialing" || foundState == "ringing-out") &&
callState == CallState::Idle) {
@@ -2028,7 +2106,9 @@ int callscreen_run_main(int argc, char** argv) {
fn.find(".ringing-in") != std::string::npos ||
fn.find(".dialing") != std::string::npos ||
fn.find(".ringing-out") != std::string::npos ||
fn.find(".active") != std::string::npos) {
fn.find(".active") != std::string::npos ||
fn.find(".held") != std::string::npos ||
fn.find(".waiting") != std::string::npos) {
std::string fpPath = callsDir + "/" + fn;
::unlink(fpPath.c_str());
}
@@ -2071,6 +2151,10 @@ int callscreen_run_main(int argc, char** argv) {
return;
}
if (line == "HANGUP_CLOSE" || line.rfind("HANGUP_CLOSE ", 0) == 0) {
if (callState == CallState::Idle && !isCallActiveOrRingingFast()) {
hideWindow(false);
return;
}
hangupCall(true);
return;
}
@@ -2216,7 +2300,25 @@ int callscreen_run_main(int argc, char** argv) {
};
if (verb == "INCOMING") {
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
::access("/tmp/sxmo_hangup_requested", F_OK) == 0 &&
!arg1.empty() && arg1 != "-" && arg1 == lastRejectedCallId) {
return;
}
if (callState == CallState::Incoming &&
!arg1.empty() && arg1 != "-" && callId == arg1) {
updateCallerDetails(arg1, arg2);
if (!arg3.empty() || activeSimSlot == 0) {
parseSimTag(arg1, arg3);
}
writeActiveStateFiles();
notifyCoverCall(ringMuted ? "muted" : "incoming",
callNumber, contactName, activeSimSlot);
showWindow();
return;
}
lastHangupMs = 0;
lastRejectedCallId.clear();
::unlink("/tmp/sxmo_hangup_requested");
callId.clear();
callNumber.clear();
@@ -2229,7 +2331,7 @@ int callscreen_run_main(int argc, char** argv) {
parseSimTag(arg1, arg3);
callState = CallState::Incoming;
callStartMs = nowMs();
lastModemPollMs = callStartMs;
lastModemPollMs = callStartMs - 1100;
missingModemPolls = 0;
ringMuted = false;
speakerOn = false;
@@ -2237,6 +2339,7 @@ int callscreen_run_main(int argc, char** argv) {
dtmfSent.clear();
selectedRow = 0;
writeActiveStateFiles();
notifyCoverCall("incoming", callNumber, contactName, activeSimSlot);
showWindow();
} else if (verb == "OUTGOING") {
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
@@ -2301,6 +2404,7 @@ int callscreen_run_main(int argc, char** argv) {
statusNotice.clear();
statusNoticeUntilMs = 0;
writeActiveStateFiles();
notifyCoverCall("active", callNumber, contactName, activeSimSlot);
showWindow();
} else if (verb == "OPEN") {
if (!arg1.empty()) {
@@ -2312,6 +2416,22 @@ int callscreen_run_main(int argc, char** argv) {
if (callState != CallState::Idle || !arg1.empty()) {
showWindow();
}
} else if (verb == "RAISE") {
if (!isFlipClosed() &&
(callState == CallState::Incoming || callState == CallState::Active ||
callState == CallState::Outgoing)) {
if (nowMs() - lastModemPollMs >= 250) {
lastModemPollMs = nowMs();
syncModemCalls();
if (callState == CallState::Incoming && missingModemPolls > 0) {
syncModemCalls();
}
}
if (callState == CallState::Incoming || callState == CallState::Active ||
callState == CallState::Outgoing) {
showWindow();
}
}
}
};
@@ -2379,6 +2499,17 @@ int callscreen_run_main(int argc, char** argv) {
}
} else if (ev.type == VisibilityNotify &&
ev.xvisibility.state != VisibilityUnobscured) {
if (isFlipClosed()) {
continue;
}
if (callState == CallState::Incoming ||
callState == CallState::Outgoing ||
callState == CallState::Active) {
XMapRaised(dpy, win);
grabPluginKeyboard(dpy, win);
render();
continue;
}
if (isAnotherPluginActive("callscreen")) {
if (callState == CallState::SelectSim || callState == CallState::Ended) {
callState = CallState::Idle;
@@ -2400,6 +2531,9 @@ int callscreen_run_main(int argc, char** argv) {
}
}
} else if (ev.type == KeyPress) {
if (isFlipClosed()) {
continue;
}
KeySym sym = XLookupKeysym(&ev.xkey, 0);
unsigned int kc = ev.xkey.keycode;
bool isLeftSoft = (sym == XK_Menu || sym == XF86XK_KbdLcdMenu1 || kc == 135);
+72 -14
View File
@@ -624,8 +624,8 @@ int locker_run_main(int argc, char** argv) {
}
};
auto closeOtherOverlays = [&]() {
closeOtherPlugins("locker");
auto closeOtherOverlays = [&](bool keepCallScreen = false) {
closeOtherPlugins("locker", keepCallScreen ? "callscreen" : nullptr);
sendPluginCommand("dmenu", "CLOSE");
sendPluginCommand("xdrawer", "CLOSE");
::unlink("/tmp/dwm_plugin_dmenu.active");
@@ -676,6 +676,7 @@ int locker_run_main(int argc, char** argv) {
}
// Current time and date
refreshLocalTimezone();
std::time_t t = std::time(nullptr);
struct tm tmNow {};
localtime_r(&t, &tmNow);
@@ -813,16 +814,23 @@ int locker_run_main(int argc, char** argv) {
auto lockPhone = [&](bool blankDisplay) {
bool alreadyVisible = visible;
bool alreadyClosedBlanked =
blankDisplay && isLidClosed() && alreadyVisible && wasScreenBlanked;
bool hadActiveCall = isCallActiveOrRingingFast() || isCallScreenVisible();
bool keepCall = (!blankDisplay || alreadyClosedBlanked) && hadActiveCall;
writeSmallFileStr(kLockFlagPath, "1\n");
writeIntFile(activePidPath, static_cast<int>(::getpid()));
sendPluginCommand("callscreen", "HANGUP_CLOSE");
if (hadActiveCall) {
::unlink("/tmp/sxmo_call_ringing");
::unlink("/tmp/sxmo_active_call");
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
if (blankDisplay && !alreadyClosedBlanked) {
if (hadActiveCall) {
sendPluginCommand("callscreen", "HANGUP_CLOSE");
::unlink("/tmp/sxmo_call_ringing");
::unlink("/tmp/sxmo_active_call");
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
} else if (isCallScreenVisible()) {
sendPluginCommand("callscreen", "CLOSE");
}
}
closeOtherOverlays();
closeOtherOverlays(keepCall);
verifier.refreshIfNeeded();
int64_t now = nowMs();
lastActivityMs = now;
@@ -840,7 +848,16 @@ int locker_run_main(int argc, char** argv) {
XSync(dpy, False);
visible = true;
}
grabLockerInput();
if (keepCall && !isLidClosed()) {
if (grabHeld) {
XUngrabKeyboard(dpy, CurrentTime);
XUngrabPointer(dpy, CurrentTime);
XSync(dpy, False);
grabHeld = false;
}
} else {
grabLockerInput();
}
if (blankDisplay || isLidClosed()) {
setSxmoStateFile("screenoff");
blankScreenBacklight();
@@ -851,6 +868,9 @@ int locker_run_main(int argc, char** argv) {
wasScreenBlanked = false;
refreshStatusCache(true);
render();
if (keepCall) {
sendPluginCommand("callscreen", "RAISE");
}
}
};
@@ -1064,12 +1084,13 @@ int locker_run_main(int argc, char** argv) {
continue;
}
if (::access(kLockFlagPath, F_OK) == 0 || visible) {
bool keepCall = isCallActiveOrRingingFast() || isCallScreenVisible();
if (!visible) {
lockPhone(false);
} else {
bool wasBlank = wasScreenBlanked || isScreenBlanked();
if (wasBlank) {
closeOtherOverlays();
closeOtherOverlays(keepCall);
}
setSxmoStateFile("lock");
wakeScreenBacklight();
@@ -1078,14 +1099,42 @@ int locker_run_main(int argc, char** argv) {
if (wasBlank) {
refreshStatusCache(true);
}
if (!grabHeld) {
if (keepCall) {
if (grabHeld) {
XUngrabKeyboard(dpy, CurrentTime);
XUngrabPointer(dpy, CurrentTime);
XSync(dpy, False);
grabHeld = false;
}
} else if (!grabHeld) {
grabLockerInput();
}
render();
if (keepCall) {
sendPluginCommand("callscreen", "RAISE");
}
}
}
continue;
}
if (cmd == "REFRESH_TIME") {
refreshLocalTimezone();
lastRenderedMin = -1;
if (visible && !isScreenBlanked() && !isLidClosed() && !isCallScreenVisible()) {
render();
XFlush(dpy);
}
continue;
}
if (cmd == "UNGRAB") {
if (grabHeld) {
XUngrabKeyboard(dpy, CurrentTime);
XUngrabPointer(dpy, CurrentTime);
XSync(dpy, False);
grabHeld = false;
}
continue;
}
if (cmd.rfind("KEY ", 0) == 0) {
unsigned int kc = 0;
unsigned int st = 0;
@@ -1204,10 +1253,11 @@ int locker_run_main(int argc, char** argv) {
if (visible && !isScreenBlanked()) {
int64_t now = nowMs();
if (lastActivityMs <= 0) {
bool callActive = isCallScreenVisible() || isCallActiveOrRingingFast();
if (lastActivityMs <= 0 || callActive) {
lastActivityMs = now;
}
if (now - lastActivityMs >= kLockerIdleBlankMs) {
if (!callActive && now - lastActivityMs >= kLockerIdleBlankMs) {
passcode.clear();
statusMsg.clear();
statusIsError = false;
@@ -1216,9 +1266,17 @@ int locker_run_main(int argc, char** argv) {
blankScreenBacklight();
wasScreenBlanked = true;
} else {
if (!isCallScreenVisible() && !grabHeld) {
if (callActive) {
if (grabHeld) {
XUngrabKeyboard(dpy, CurrentTime);
XUngrabPointer(dpy, CurrentTime);
XSync(dpy, False);
grabHeld = false;
}
} else if (!grabHeld) {
grabLockerInput();
}
refreshLocalTimezone();
std::time_t t = std::time(nullptr);
struct tm tmNow {};
localtime_r(&t, &tmNow);
+142 -3
View File
@@ -269,6 +269,40 @@ inline bool isCallRingingFast() {
return false;
}
inline bool isLiveSxmoCallFile(const std::string& callsDir, const char* name) {
if (!name || name[0] == '\0' || name[0] == '.') {
return false;
}
const char* dot = std::strrchr(name, '.');
if (!dot || dot == name || dot[1] == '\0') {
return false;
}
const char* ext = dot + 1;
static const char* const kLiveExts[] = {
"pickedupcall", "initiatedcall", "ringing-in", "dialing",
"ringing-out", "active", "held", "waiting",
};
for (const char* live : kLiveExts) {
if (std::strcmp(ext, live) == 0) {
return true;
}
}
if (std::strcmp(ext, "monitoredcall") == 0) {
std::string base(name, static_cast<size_t>(dot - name));
static const char* const kTermExts[] = {
"discardedcall", "hangedupcall", "terminated", "blockedcall",
};
for (const char* term : kTermExts) {
std::string p = callsDir + "/" + base + "." + term;
if (::access(p.c_str(), F_OK) == 0) {
return false;
}
}
return true;
}
return false;
}
inline bool isCallActiveOrRingingFast() {
if (isCallRingingFast()) {
return true;
@@ -284,7 +318,7 @@ inline bool isCallActiveOrRingingFast() {
bool found = false;
struct dirent* ent;
while ((ent = ::readdir(d)) != nullptr) {
if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') {
if (isLiveSxmoCallFile(callsDir, ent->d_name)) {
found = true;
break;
}
@@ -1914,7 +1948,109 @@ inline void placePhoneCall(const std::string& rawNumber, int simSlot = 0) {
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
}
inline void closeOtherPlugins(const char* selfPluginName) {
/* Force musl/glibc to reload timezone rules when /etc/localtime or /etc/timezone changes. */
inline void refreshLocalTimezone() {
const char* ltEnv = ::getenv("BANANARCHY_TZ_LOCALTIME");
const char* tfEnv = ::getenv("BANANARCHY_TZ_FILE");
const char* ltPath = (ltEnv && *ltEnv) ? ltEnv : "/etc/localtime";
const char* tfPath = (tfEnv && *tfEnv) ? tfEnv : "/etc/timezone";
struct stat st {};
struct stat lst {};
struct stat tfSt {};
char linkBuf[512];
char tfBuf[128];
linkBuf[0] = '\0';
tfBuf[0] = '\0';
bool haveLt = (::stat(ltPath, &st) == 0);
bool haveLst = (::lstat(ltPath, &lst) == 0);
ssize_t linkLen = ::readlink(ltPath, linkBuf, sizeof(linkBuf) - 1);
if (linkLen >= 0) {
linkBuf[linkLen] = '\0';
} else {
linkBuf[0] = '\0';
}
bool haveTf = (::stat(tfPath, &tfSt) == 0);
bool tfIsTzif = false;
if (haveTf) {
int fd = ::open(tfPath, O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
ssize_t n = ::read(fd, tfBuf, sizeof(tfBuf) - 1);
::close(fd);
if (n >= 4 && std::memcmp(tfBuf, "TZif", 4) == 0) {
tfIsTzif = true;
tfBuf[0] = '\0';
} else if (n > 0) {
size_t len = static_cast<size_t>(n);
tfBuf[len] = '\0';
while (len > 0 && (tfBuf[len - 1] == '\n' || tfBuf[len - 1] == '\r' ||
tfBuf[len - 1] == ' ' || tfBuf[len - 1] == '\t')) {
tfBuf[--len] = '\0';
}
}
}
}
static char lastSig[1024] = {};
static int tzToggle = 0;
if (!haveLt && !haveTf && lastSig[0] != '\0') {
return;
}
char sig[1024];
std::snprintf(
sig, sizeof(sig),
"%d|%d|%s|%llu|%lld|%ld|%llu|%llu|%lld|%ld|%llu|%d|%d|%s|%lld|%ld|%llu",
haveLt ? 1 : 0, haveLst ? 1 : 0, linkBuf,
static_cast<unsigned long long>(st.st_ino),
static_cast<long long>(st.st_mtime),
static_cast<long>(st.st_mtim.tv_nsec),
static_cast<unsigned long long>(st.st_size),
static_cast<unsigned long long>(lst.st_ino),
static_cast<long long>(lst.st_mtime),
static_cast<long>(lst.st_mtim.tv_nsec),
static_cast<unsigned long long>(tfSt.st_size),
haveTf ? 1 : 0, tfIsTzif ? 1 : 0, tfBuf,
static_cast<long long>(tfSt.st_mtime),
static_cast<long>(tfSt.st_mtim.tv_nsec),
static_cast<unsigned long long>(tfSt.st_ino));
if (std::strcmp(sig, lastSig) == 0) {
return;
}
std::snprintf(lastSig, sizeof(lastSig), "%s", sig);
tzToggle ^= 1;
if ((!ltEnv || !*ltEnv) && tfEnv && *tfEnv && haveTf) {
char tzVal[600];
if (tfIsTzif) {
std::snprintf(tzVal, sizeof(tzVal), "%s%s",
tfPath[0] == '/' ? (tzToggle ? ":" : ":/.")
: (tzToggle ? ":" : ":./"),
tfPath);
::setenv("TZ", tzVal, 1);
} else if (tfBuf[0]) {
::setenv("TZ", tfBuf, 1);
}
::tzset();
return;
}
if (haveLt) {
char tzVal[600];
std::snprintf(tzVal, sizeof(tzVal), "%s%s",
ltPath[0] == '/' ? (tzToggle ? ":" : ":/.")
: (tzToggle ? ":" : ":./"),
ltPath);
::setenv("TZ", tzVal, 1);
} else if (tfBuf[0]) {
::setenv("TZ", tfBuf, 1);
}
::tzset();
}
inline void closeOtherPlugins(const char* selfPluginName,
const char* keepPluginName = nullptr) {
struct PluginRef {
const char* pidFile;
const char* name;
@@ -1946,7 +2082,8 @@ inline void closeOtherPlugins(const char* selfPluginName) {
{"xprivacy.pid", "privacy"},
};
for (const auto& p : kAllPlugins) {
if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) {
if ((selfPluginName && std::strcmp(p.name, selfPluginName) == 0) ||
(keepPluginName && std::strcmp(p.name, keepPluginName) == 0)) {
continue;
}
if (isPidFileAlive(getRuntimeFile(p.pidFile))) {
@@ -1954,6 +2091,7 @@ inline void closeOtherPlugins(const char* selfPluginName) {
}
}
if ((!selfPluginName || std::strcmp(selfPluginName, "dmenu") != 0) &&
(!keepPluginName || std::strcmp(keepPluginName, "dmenu") != 0) &&
::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) {
sendPluginCommand("dmenu", "CLOSE");
}
@@ -2802,6 +2940,7 @@ inline std::string sendModemUssd(const std::string& input,
ContactBook::ensureParentDir(logPath);
std::ofstream logOut(logPath, std::ios::app);
if (logOut.is_open()) {
refreshLocalTimezone();
std::time_t now = std::time(nullptr);
struct tm tmNow {};
localtime_r(&now, &tmNow);