Fix lid wake blanking, passcode lag, idle drain, zero-log privacy default, and replace Conky with native dwm clock

This commit is contained in:
Luxferre committed 2026-11-05 08:07:10 +02:00
1 parent 11ec778c2f
commit 1d71bc81d8
42 files changed
+732 -267

No files matched your search

+20 -4
View File
@@ -75,6 +75,7 @@ struct EngStatus {
int cpuMaxMhz = 1094;
bool diagActive = false;
std::string usbPid = "18d1:d001";
bool extLogging = false;
};
// Calculate 15th Luhn check digit from the first 14 digits (Wallace calcIMEIChecksum)
@@ -254,6 +255,7 @@ EngStatus queryEngStatus() {
else if (k == "CPU_MAX_MHZ") st.cpuMaxMhz = std::atoi(v.c_str());
else if (k == "DIAG_ACTIVE") st.diagActive = (v == "1");
else if (k == "USB_PID") st.usbPid = v;
else if (k == "EXT_LOGGING") st.extLogging = (v == "1");
}
if (st.imei1.empty() || st.imei2.empty()) {
DeviceImeis devIm = queryDeviceImeis();
@@ -410,6 +412,14 @@ int engmenu_run_main(int argc, char** argv) {
rows.push_back({"7", "7: Edit Bluetooth MAC", bmacSub,
isRfnv ? "persist" : "NV 447", 2});
// 8. [8] Extended logging (privacy)
std::string logSub = status.extLogging
? "RAM logs active in /tmp"
: "Disabled (zero idle logs)";
rows.push_back({"8", "8: Extended Logging", logSub,
status.extLogging ? "ON" : "OFF",
status.extLogging ? 2 : 1});
return rows;
};
@@ -478,6 +488,12 @@ int engmenu_run_main(int argc, char** argv) {
editBuf = generateRandomMac();
lastHexKey = -1;
modal = EngModal::EditBtMac;
} else if (idx == 7) {
// 8: Extended Logging
std::string res = runEngCtlCapture({"logging", "toggle"});
refreshStatus();
showToast(status.extLogging ? "Extended logging enabled (/tmp)"
: "Extended logging disabled & purged");
}
};
@@ -716,7 +732,7 @@ int engmenu_run_main(int argc, char** argv) {
std::string lskLabel = "Select";
if (selIdx == 0 || selIdx == 1 || selIdx == 2 || selIdx == 5 || selIdx == 6) {
lskLabel = "Edit";
} else if (selIdx == 3 || selIdx == 4) {
} else if (selIdx == 3 || selIdx == 4 || selIdx == 7) {
lskLabel = "Toggle";
}
neo.drawSoftbar(lskLabel, "Run", "Close", &theme.colYellow);
@@ -1000,7 +1016,7 @@ int engmenu_run_main(int argc, char** argv) {
continue;
}
constexpr int kNumItems = 7;
constexpr int kNumItems = 8;
if (sym == XK_Up || sym == XK_KP_Up) {
selIdx = (selIdx > 0) ? (selIdx - 1) : (kNumItems - 1);
render();
@@ -1019,8 +1035,8 @@ int engmenu_run_main(int argc, char** argv) {
continue;
}
// Direct hotkeys 1..7
if (dch >= '1' && dch <= '7') {
// Direct hotkeys 1..8
if (dch >= '1' && dch <= '8') {
selIdx = dch - '1';
triggerRowAction(selIdx);
render();
+331 -121
View File
@@ -178,12 +178,38 @@ enum class VerifyResult {
class PasscodeVerifier {
public:
PasscodeVerifier() {
struct timespec ts {};
clock_gettime(CLOCK_MONOTONIC, &ts);
sessionSalt_ = (static_cast<uint64_t>(ts.tv_sec) << 32) ^
static_cast<uint64_t>(ts.tv_nsec) ^
(static_cast<uint64_t>(::getpid()) * 0x9e3779b97f4a7c15ULL);
int ufd = ::open("/dev/urandom", O_RDONLY | O_CLOEXEC);
if (ufd >= 0) {
uint64_t rnd = 0;
if (::read(ufd, &rnd, sizeof(rnd)) == static_cast<ssize_t>(sizeof(rnd))) {
sessionSalt_ ^= rnd;
}
::close(ufd);
}
}
void clearSessionCache() {
hasVerifiedNormal_ = false;
verifiedNormalLen_ = 0;
verifiedNormalDigest_ = 0;
hasVerifiedDuress_ = false;
verifiedDuressLen_ = 0;
verifiedDuressDigest_ = 0;
}
void forceRefresh() {
shadowMtime_ = 0;
shadowSize_ = 0;
duressMtime_ = -1;
cachedHash_.clear();
cachedDuressHash_.clear();
clearSessionCache();
refreshIfNeeded();
}
@@ -202,6 +228,7 @@ class PasscodeVerifier {
shadowSize_ = st.st_size;
duressMtime_ = curDuressMtime;
}
clearSessionCache();
int pipefd[2];
if (::pipe(pipefd) != 0) {
return;
@@ -258,19 +285,57 @@ class PasscodeVerifier {
}
}
VerifyResult verify(const std::string& candidate) {
VerifyResult verifyFast(const std::string& candidate) {
if (candidate.empty()) {
return VerifyResult::Invalid;
}
refreshIfNeeded();
uint64_t dig = computeSessionDigest(candidate);
if (hasVerifiedNormal_ && candidate.size() == verifiedNormalLen_ &&
dig == verifiedNormalDigest_) {
return VerifyResult::NormalUser;
}
if (hasVerifiedDuress_ && candidate.size() == verifiedDuressLen_ &&
dig == verifiedDuressDigest_) {
return VerifyResult::DuressUser;
}
return VerifyResult::Invalid;
}
bool canSkipAutoVerifyLength(size_t len) const {
if (hasVerifiedNormal_ && cachedDuressHash_.empty()) {
return len != verifiedNormalLen_;
}
if (hasVerifiedNormal_ && hasVerifiedDuress_) {
return len != verifiedNormalLen_ && len != verifiedDuressLen_;
}
return false;
}
VerifyResult verify(const std::string& candidate) {
if (candidate.empty()) {
return VerifyResult::Invalid;
}
VerifyResult fast = verifyFast(candidate);
if (fast != VerifyResult::Invalid) {
return fast;
}
writeSysfsStr("/sys/devices/system/cpu/cpufreq/policy0/scaling_governor",
"schedutil");
if (!cachedHash_.empty()) {
char* res = ::crypt(candidate.c_str(), cachedHash_.c_str());
if (res && constantTimeEq(res, cachedHash_)) {
hasVerifiedNormal_ = true;
verifiedNormalLen_ = candidate.size();
verifiedNormalDigest_ = computeSessionDigest(candidate);
return VerifyResult::NormalUser;
}
if (!cachedDuressHash_.empty()) {
char* dres = ::crypt(candidate.c_str(), cachedDuressHash_.c_str());
if (dres && constantTimeEq(dres, cachedDuressHash_)) {
hasVerifiedDuress_ = true;
verifiedDuressLen_ = candidate.size();
verifiedDuressDigest_ = computeSessionDigest(candidate);
return VerifyResult::DuressUser;
}
}
@@ -309,9 +374,15 @@ class PasscodeVerifier {
if (pid > 0 && ::waitpid(pid, &status, 0) > 0 && WIFEXITED(status)) {
int code = WEXITSTATUS(status);
if (code == 0) {
hasVerifiedNormal_ = true;
verifiedNormalLen_ = candidate.size();
verifiedNormalDigest_ = computeSessionDigest(candidate);
return VerifyResult::NormalUser;
}
if (code == 10) {
hasVerifiedDuress_ = true;
verifiedDuressLen_ = candidate.size();
verifiedDuressDigest_ = computeSessionDigest(candidate);
return VerifyResult::DuressUser;
}
}
@@ -319,11 +390,31 @@ class PasscodeVerifier {
}
private:
uint64_t computeSessionDigest(const std::string& s) const {
uint64_t h = 0xcbf29ce484222325ULL ^ sessionSalt_;
for (unsigned char c : s) {
h ^= static_cast<uint64_t>(c);
h *= 0x100000001b3ULL;
h ^= (h >> 32);
}
h ^= static_cast<uint64_t>(s.size()) * 0x9e3779b97f4a7c15ULL;
h = (h ^ (h >> 30)) * 0xbf58476d1ce4e5b9ULL;
h = (h ^ (h >> 27)) * 0x94d049bb133111ebULL;
return h ^ (h >> 31);
}
std::string cachedHash_;
std::string cachedDuressHash_;
time_t shadowMtime_ = 0;
off_t shadowSize_ = 0;
time_t duressMtime_ = -1;
uint64_t sessionSalt_ = 0;
bool hasVerifiedNormal_ = false;
size_t verifiedNormalLen_ = 0;
uint64_t verifiedNormalDigest_ = 0;
bool hasVerifiedDuress_ = false;
size_t verifiedDuressLen_ = 0;
uint64_t verifiedDuressDigest_ = 0;
};
int countNotifFiles() {
@@ -436,6 +527,7 @@ int locker_run_main(int argc, char** argv) {
constexpr int64_t kLockerIdleBlankMs = 30000;
bool visible = false;
bool grabHeld = false;
bool wasScreenBlanked = isScreenBlanked();
std::string passcode;
std::string statusMsg;
bool statusIsError = false;
@@ -444,8 +536,37 @@ int locker_run_main(int argc, char** argv) {
int64_t statusClearAtMs = 0;
int64_t lockActivatedMs = 0;
int64_t lastActivityMs = 0;
int64_t autoVerifyAtMs = 0;
int lastRenderedMin = -1;
int cachedPctVal = -1;
bool cachedIsCharging = false;
int cachedNotifCount = 0;
int64_t lastStatusPollMs = 0;
auto refreshStatusCache = [&](bool force) {
int64_t now = nowMs();
if (!force && lastStatusPollMs > 0 && (now - lastStatusPollMs) < 10000) {
return;
}
lastStatusPollMs = now;
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/capacity");
if (cap.empty()) {
cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
}
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/status");
if (batStatus.empty()) {
batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
}
std::string chgrOnline = readSmallFileTrimmed("/sys/class/power_supply/pm8916-lbc-chgr/online");
cachedPctVal = cap.empty() ? -1 : std::clamp(std::atoi(cap.c_str()), 0, 100);
cachedIsCharging = (batStatus == "Charging" || batStatus == "Full" || chgrOnline == "1");
if (chgrOnline == "0") {
cachedIsCharging = false;
}
cachedNotifCount = countNotifFiles();
};
auto isCallScreenVisible = [&]() -> bool {
return isPidFileAlive(getRuntimeFile("xcallscreen.pid"));
};
@@ -458,13 +579,13 @@ int locker_run_main(int argc, char** argv) {
XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
XFlush(dpy);
grabHeld = false;
for (int attempt = 0; attempt < 15; ++attempt) {
for (int attempt = 0; attempt < 3; ++attempt) {
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabSuccess) {
grabHeld = true;
break;
}
::usleep(10000);
::usleep(3000);
}
XGrabPointer(dpy, win, True, ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
@@ -499,6 +620,8 @@ int locker_run_main(int argc, char** argv) {
statusClearAtMs = 0;
}
refreshStatusCache(false);
// Background fill
XSetForeground(dpy, gc, theme.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, 0, kScreenWidth, kScreenHeight);
@@ -512,20 +635,8 @@ int locker_run_main(int argc, char** argv) {
neo.drawPango(layoutIcon, &theme.colYellow, 8, 0, 24, kIconLock);
neo.drawPango(layoutSmall, &theme.colLight, 26, 0, 24, "Locked");
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/capacity");
if (cap.empty()) {
cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
}
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/pm8916-bms-vm/status");
if (batStatus.empty()) {
batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
}
std::string chgrOnline = readSmallFileTrimmed("/sys/class/power_supply/pm8916-lbc-chgr/online");
int pctVal = cap.empty() ? -1 : std::clamp(std::atoi(cap.c_str()), 0, 100);
bool isCharging = (batStatus == "Charging" || batStatus == "Full" || chgrOnline == "1");
if (chgrOnline == "0") {
isCharging = false;
}
int pctVal = cachedPctVal;
bool isCharging = cachedIsCharging;
if (pctVal >= 0) {
std::string batText = std::string(pickBatteryIcon(pctVal, isCharging)) +
" " + std::to_string(pctVal) + "%";
@@ -557,7 +668,7 @@ int locker_run_main(int argc, char** argv) {
kScreenWidth, 1);
// Notification badge (count only, no private content exposed on lockscreen)
int notifCount = countNotifFiles();
int notifCount = cachedNotifCount;
if (notifCount > 0) {
std::string nstr = std::string(kIconBell) + " " +
std::to_string(notifCount) +
@@ -642,9 +753,6 @@ int locker_run_main(int argc, char** argv) {
passcode.empty() ? "Sleep" : "Clear",
&theme.colYellow);
if (!grabHeld && !isCallScreenVisible()) {
grabLockerInput();
}
neo.present();
};
@@ -664,6 +772,7 @@ int locker_run_main(int argc, char** argv) {
statusIsError = false;
failedAttempts = 0;
cooldownUntilMs = 0;
autoVerifyAtMs = 0;
::unlink(kLockFlagPath);
::unlink(activePidPath.c_str());
releaseLockerGrab();
@@ -675,6 +784,7 @@ int locker_run_main(int argc, char** argv) {
writeSoftkeySuppress(nowMs() + 350);
setSxmoStateFile("unlock");
wakeScreenBacklight();
wasScreenBlanked = false;
runAsyncCmd("sxmo_hook_unlock.sh >/dev/null 2>&1");
};
@@ -693,6 +803,7 @@ int locker_run_main(int argc, char** argv) {
verifier.refreshIfNeeded();
int64_t now = nowMs();
lastActivityMs = now;
autoVerifyAtMs = 0;
if (!alreadyVisible || blankDisplay) {
passcode.clear();
statusMsg.clear();
@@ -709,14 +820,18 @@ int locker_run_main(int argc, char** argv) {
if (blankDisplay) {
setSxmoStateFile("screenoff");
blankScreenBacklight();
wasScreenBlanked = true;
} else {
setSxmoStateFile("lock");
wakeScreenBacklight();
wasScreenBlanked = false;
refreshStatusCache(true);
render();
}
};
auto submitPasscode = [&](bool explicitSubmit) {
autoVerifyAtMs = 0;
int64_t now = nowMs();
if (cooldownUntilMs > now) {
render();
@@ -757,6 +872,119 @@ int locker_run_main(int argc, char** argv) {
}
};
auto handleKeyInput = [&](unsigned int kc, unsigned int state, KeySym sym) {
if (!visible) {
return;
}
int64_t now = nowMs();
lastActivityMs = now;
if (isScreenBlanked()) {
setSxmoStateFile("lock");
wakeScreenBacklight();
wasScreenBlanked = false;
lockActivatedMs = now;
refreshStatusCache(true);
render();
return;
}
if (now - lockActivatedMs < 80) {
return;
}
// Power / End Call / Sleep button blanks the screen while remaining locked
if (kc == 124 || sym == XF86XK_PowerOff || sym == XF86XK_Sleep ||
sym == XF86XK_Standby || sym == XF86XK_Suspend ||
sym == XF86XK_HangupPhone || sym == XK_Cancel ||
sym == _EVDEVK(0x74) || sym == _EVDEVK(0x8e) ||
sym == XK_Escape) {
if (isCallActiveOrRingingFast() || isCallScreenVisible()) {
sendPluginCommand("callscreen", "HANGUP_CLOSE");
::unlink("/tmp/sxmo_call_ringing");
::unlink("/tmp/sxmo_active_call");
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
}
passcode.clear();
statusMsg.clear();
statusIsError = false;
autoVerifyAtMs = 0;
setSxmoStateFile("screenoff");
blankScreenBacklight();
wasScreenBlanked = true;
return;
}
// Left softkey: explicit Unlock attempt
if (isLeftSoftkey(sym, kc)) {
submitPasscode(true);
return;
}
// Right softkey: Clear last digit, or blank screen if empty
if (isRightSoftkey(sym, kc)) {
autoVerifyAtMs = 0;
if (!passcode.empty()) {
passcode.pop_back();
render();
} else {
setSxmoStateFile("screenoff");
blankScreenBacklight();
wasScreenBlanked = true;
}
return;
}
// Backspace / Left arrow: delete last digit
if (sym == XK_BackSpace || sym == XK_Delete ||
sym == XK_Left || sym == XK_KP_Left) {
autoVerifyAtMs = 0;
if (!passcode.empty()) {
passcode.pop_back();
render();
}
return;
}
// Enter / Center OK / Call / Pound (#): explicit Unlock attempt
if (sym == XK_Return || sym == XK_KP_Enter ||
sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
sym == XF86XK_Send || isPoundKey(sym, kc)) {
submitPasscode(true);
return;
}
// Numeric digits 0-9
char ch = mapDialKey(sym, kc, state);
if (ch >= '0' && ch <= '9') {
if (cooldownUntilMs > now) {
render();
return;
}
if (passcode.size() < 32) {
passcode.push_back(ch);
statusMsg.clear();
statusIsError = false;
render();
if (passcode.size() >= 4) {
VerifyResult fastRes = verifier.verifyFast(passcode);
if (fastRes == VerifyResult::NormalUser ||
fastRes == VerifyResult::DuressUser) {
autoVerifyAtMs = 0;
unlockPhone(fastRes == VerifyResult::DuressUser);
return;
}
if (!verifier.canSkipAutoVerifyLength(passcode.size())) {
autoVerifyAtMs = nowMs() + 220;
} else {
autoVerifyAtMs = 0;
}
} else {
autoVerifyAtMs = 0;
}
}
return;
}
};
if (!isPreload) {
lockPhone(initCmd == "LOCK_BLANK");
} else if (::access(kLockFlagPath, F_OK) == 0) {
@@ -767,6 +995,16 @@ int locker_run_main(int argc, char** argv) {
bool callWasActive = false;
while (gRunning) {
bool blankNow = isScreenBlanked();
if (wasScreenBlanked && !blankNow) {
wasScreenBlanked = false;
int64_t now = nowMs();
lastActivityMs = now;
refreshStatusCache(true);
} else if (blankNow) {
wasScreenBlanked = true;
}
if (fifoFd >= 0) {
for (const std::string& cmd : readFifoLines(fifoFd)) {
if (cmd == "NOP") {
@@ -801,16 +1039,37 @@ int locker_run_main(int argc, char** argv) {
if (!visible) {
lockPhone(false);
} else {
closeOtherOverlays();
bool wasBlank = wasScreenBlanked || isScreenBlanked();
if (wasBlank) {
closeOtherOverlays();
}
setSxmoStateFile("lock");
wakeScreenBacklight();
wasScreenBlanked = false;
lastActivityMs = nowMs();
grabLockerInput();
if (wasBlank) {
refreshStatusCache(true);
}
if (!grabHeld) {
grabLockerInput();
}
render();
}
}
continue;
}
if (cmd.rfind("KEY ", 0) == 0) {
unsigned int kc = 0;
unsigned int st = 0;
if (std::sscanf(cmd.c_str() + 4, "%u %u", &kc, &st) >= 1 && kc > 0) {
if (!grabHeld && visible && !isCallScreenVisible()) {
grabLockerInput();
}
KeySym sym = XKeycodeToKeysym(dpy, static_cast<KeyCode>(kc), 0);
handleKeyInput(kc, st, sym);
}
continue;
}
if (cmd.rfind("VERIFY ", 0) == 0) {
std::string code = trimStr(cmd.substr(7));
VerifyResult vres =
@@ -852,7 +1111,7 @@ int locker_run_main(int argc, char** argv) {
} else if (!callNow && callWasActive) {
grabLockerInput();
render();
} else if (!callNow && !grabHeld) {
} else if (!callNow && !grabHeld && !isScreenBlanked()) {
grabLockerInput();
}
callWasActive = callNow;
@@ -862,112 +1121,46 @@ int locker_run_main(int argc, char** argv) {
XEvent ev;
XNextEvent(dpy, &ev);
if (ev.type == Expose) {
if (visible && ev.xexpose.count == 0) {
if (visible && ev.xexpose.count == 0 && !isScreenBlanked()) {
render();
}
} else if (ev.type == VisibilityNotify || ev.type == FocusOut ||
ev.type == UnmapNotify) {
} else if (ev.type == UnmapNotify) {
if (visible && ::access(kLockFlagPath, F_OK) == 0 &&
!isCallScreenVisible()) {
if (ev.type == UnmapNotify) {
XMapRaised(dpy, win);
}
XMapRaised(dpy, win);
grabLockerInput();
if (!isScreenBlanked()) {
render();
}
}
} else if (ev.type == VisibilityNotify) {
if (visible && ev.xvisibility.state != VisibilityUnobscured &&
::access(kLockFlagPath, F_OK) == 0 && !isCallScreenVisible() &&
!isScreenBlanked()) {
XRaiseWindow(dpy, win);
if (!grabHeld) {
grabLockerInput();
}
render();
}
} else if (ev.type == FocusOut) {
if (visible && ::access(kLockFlagPath, F_OK) == 0 &&
!isCallScreenVisible() && !isScreenBlanked() &&
ev.xfocus.mode == NotifyNormal) {
grabLockerInput();
}
} else if (ev.type == KeyPress) {
if (!visible) {
continue;
}
int64_t now = nowMs();
lastActivityMs = now;
if (isScreenBlanked()) {
setSxmoStateFile("lock");
wakeScreenBacklight();
lockActivatedMs = now;
render();
continue;
}
if (now - lockActivatedMs < 180) {
continue;
}
unsigned int kc = ev.xkey.keycode;
KeySym sym = XLookupKeysym(&ev.xkey, 0);
handleKeyInput(ev.xkey.keycode, ev.xkey.state, sym);
}
}
// Power / End Call / Sleep button blanks the screen while remaining locked
if (kc == 124 || sym == XF86XK_PowerOff || sym == XF86XK_Sleep ||
sym == XF86XK_Standby || sym == XF86XK_Suspend ||
sym == XF86XK_HangupPhone || sym == XK_Cancel ||
sym == _EVDEVK(0x74) || sym == _EVDEVK(0x8e) ||
sym == XK_Escape) {
if (isCallActiveOrRingingFast() || isCallScreenVisible()) {
sendPluginCommand("callscreen", "HANGUP_CLOSE");
::unlink("/tmp/sxmo_call_ringing");
::unlink("/tmp/sxmo_active_call");
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
}
passcode.clear();
statusMsg.clear();
statusIsError = false;
setSxmoStateFile("screenoff");
blankScreenBacklight();
continue;
}
// Left softkey: explicit Unlock attempt
if (isLeftSoftkey(sym, kc)) {
submitPasscode(true);
continue;
}
// Right softkey: Clear last digit, or blank screen if empty
if (isRightSoftkey(sym, kc)) {
if (!passcode.empty()) {
passcode.pop_back();
render();
} else {
setSxmoStateFile("screenoff");
blankScreenBacklight();
}
continue;
}
// Backspace / Left arrow: delete last digit
if (sym == XK_BackSpace || sym == XK_Delete ||
sym == XK_Left || sym == XK_KP_Left) {
if (!passcode.empty()) {
passcode.pop_back();
render();
}
continue;
}
// Enter / Center OK / Call / Pound (#): explicit Unlock attempt
if (sym == XK_Return || sym == XK_KP_Enter ||
sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
sym == XF86XK_Send || isPoundKey(sym, kc)) {
submitPasscode(true);
continue;
}
// Numeric digits 0-9
char ch = mapDialKey(sym, kc, ev.xkey.state);
if (ch >= '0' && ch <= '9') {
if (cooldownUntilMs > now) {
render();
continue;
}
if (passcode.size() < 32) {
passcode.push_back(ch);
statusMsg.clear();
statusIsError = false;
render();
if (passcode.size() >= 4) {
submitPasscode(false);
}
}
continue;
if (visible && autoVerifyAtMs > 0 && !isScreenBlanked()) {
int64_t now = nowMs();
if (now >= autoVerifyAtMs) {
autoVerifyAtMs = 0;
if (passcode.size() >= 4) {
submitPasscode(false);
}
}
}
@@ -981,8 +1174,10 @@ int locker_run_main(int argc, char** argv) {
passcode.clear();
statusMsg.clear();
statusIsError = false;
autoVerifyAtMs = 0;
setSxmoStateFile("screenoff");
blankScreenBacklight();
wasScreenBlanked = true;
} else {
if (!isCallScreenVisible() && !grabHeld) {
grabLockerInput();
@@ -993,6 +1188,9 @@ int locker_run_main(int argc, char** argv) {
int curMin = tmNow.tm_hour * 60 + tmNow.tm_min;
if (curMin != lastRenderedMin || cooldownUntilMs > now ||
(statusClearAtMs > 0 && now >= statusClearAtMs)) {
if (curMin != lastRenderedMin) {
refreshStatusCache(true);
}
render();
}
}
@@ -1019,6 +1217,12 @@ int locker_run_main(int argc, char** argv) {
if (idleRemMs < timeoutMs) {
timeoutMs = static_cast<int>(idleRemMs);
}
if (autoVerifyAtMs > 0) {
int64_t autoRem = std::max<int64_t>(10, autoVerifyAtMs - now);
if (autoRem < timeoutMs) {
timeoutMs = static_cast<int>(autoRem);
}
}
}
struct pollfd pfds[2] {};
@@ -1026,7 +1230,13 @@ int locker_run_main(int argc, char** argv) {
pfds[0].events = POLLIN;
pfds[1].fd = fifoFd;
pfds[1].events = POLLIN;
::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs);
int pr = ::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs);
if (pr < 0 && errno != EINTR) {
break;
}
if (pfds[0].revents & (POLLHUP | POLLERR | POLLNVAL)) {
break;
}
}
g_object_unref(layoutClock);
+12 -3
View File
@@ -1267,6 +1267,9 @@ handle_builtin_toggle(const char *toggle_name)
close(fd);
}
spawn_detached_sh("sxmo_hook_statusbar.sh audio");
} else if (strcmp(toggle_name, "ext_logging") == 0) {
int rc = system("doas -n /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1 || /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1");
(void)rc;
} else if (strcmp(toggle_name, "notif_clear_all") == 0) {
clear_all_notifications_now();
}
@@ -2888,11 +2891,17 @@ open_builtin_menu(const char *menu_name, int keep_idx)
add_menu_item(label, "@menu:timezone", 1);
if (!duress) {
int ext_log_on = (access("/tmp/bananarchy_ext_logging", F_OK) == 0 ||
access("/etc/bananarchy/ext_logging", F_OK) == 0);
snprintf(label, sizeof(label), "%s Extended Logging %s", ICON_INF,
ext_log_on ? ICON_TON : ICON_TOF);
add_menu_item(label, "@toggle:ext_logging", 1);
snprintf(label, sizeof(label), "%s Hooks", ICON_TRM);
add_menu_item(label, "sxmo_hookmenu.sh", 0);
snprintf(label, sizeof(label), "%s Log", ICON_INF);
snprintf(cmd, sizeof(cmd), "sxmo_terminal.sh tail -n 100 -f %s/sxmo.log", home);
add_menu_item(label, cmd, 0);
if (ext_log_on) {
snprintf(label, sizeof(label), "%s Log", ICON_INF);
add_menu_item(label, "sxmo_terminal.sh tail -n 100 -f /tmp/sxmo.log", 0);
}
snprintf(label, sizeof(label), "%s Version", ICON_INF);
add_menu_item(label, "sxmo_terminal.sh sxmo_version.sh --block", 0);
}
+163 -11
View File
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <linux/input.h>
#include <sys/ioctl.h>
@@ -150,6 +151,7 @@ struct Monitor {
Monitor *next;
Window barwin;
Window softwin;
Window clockwin;
const Layout *lt[2];
};
@@ -341,6 +343,9 @@ static int starpound_pending = 0;
static long long starpound_deadline_ms = 0;
static KeySym starpound_keysym = NoSymbol;
static unsigned int starpound_keycode = 0;
static int lid_close_pending = 0;
static long long lid_close_deadline_ms = 0;
static int lid_close_fd = -1;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -805,6 +810,10 @@ cleanupmon(Monitor *mon)
XUnmapWindow(dpy, mon->softwin);
XDestroyWindow(dpy, mon->softwin);
}
if (mon->clockwin) {
XUnmapWindow(dpy, mon->clockwin);
XDestroyWindow(dpy, mon->clockwin);
}
free(mon);
}
@@ -853,7 +862,8 @@ clientmessage(XEvent *e)
}
} else if (argval != 0 && (Window)argval != root &&
(!selmon || ((Window)argval != selmon->barwin &&
(Window)argval != selmon->softwin))) {
(Window)argval != selmon->softwin &&
(Window)argval != selmon->clockwin))) {
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll);
@@ -1154,6 +1164,76 @@ drawbar(Monitor *m)
}
}
}
if (m->clockwin) {
XLowerWindow(dpy, m->clockwin);
XClearWindow(dpy, m->clockwin);
if (!m->sel) {
static XftFont *clk_font_big = NULL;
static XftFont *clk_font_small = NULL;
static XftColor clk_fg, clk_sh;
static int clk_colors_init = 0;
static char last_tzlink[256] = "";
char tzlink[256];
ssize_t tzlen;
if (!clk_font_big)
clk_font_big = XftFontOpenName(dpy, screen, "Fira Code:size=32:style=Regular");
if (!clk_font_small)
clk_font_small = XftFontOpenName(dpy, screen, "Fira Code:size=14:style=Regular");
if (!clk_colors_init) {
XRenderColor rfg = { 0xffff, 0xffff, 0xffff, 0xffff };
XRenderColor rsh = { 0x0000, 0x0000, 0x0000, 0xffff };
XftColorAllocValue(dpy, DefaultVisual(dpy, screen),
DefaultColormap(dpy, screen), &rfg, &clk_fg);
XftColorAllocValue(dpy, DefaultVisual(dpy, screen),
DefaultColormap(dpy, screen), &rsh, &clk_sh);
clk_colors_init = 1;
}
tzlen = readlink("/etc/localtime", tzlink, sizeof(tzlink) - 1);
if (tzlen > 0) {
tzlink[tzlen] = '\0';
if (strcmp(tzlink, last_tzlink) != 0) {
snprintf(last_tzlink, sizeof(last_tzlink), "%s", tzlink);
setenv("TZ", tzlink, 1);
tzset();
}
}
XftDraw *cd = XftDrawCreate(dpy, m->clockwin,
DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
if (cd) {
time_t now = time(NULL);
struct tm lt;
char tbuf[32], dbuf[64];
XGlyphInfo ext;
localtime_r(&now, &lt);
strftime(tbuf, sizeof(tbuf), "%H:%M", &lt);
strftime(dbuf, sizeof(dbuf), "%a %d %b %Y", &lt);
if (clk_font_big) {
size_t tlen = strlen(tbuf);
XftTextExtentsUtf8(dpy, clk_font_big, (const FcChar8 *)tbuf, tlen, &ext);
int tx = (m->ww - ext.xOff) / 2;
int ty = 45;
XftDrawStringUtf8(cd, &clk_sh, clk_font_big, tx + 1, ty + 1,
(const FcChar8 *)tbuf, tlen);
XftDrawStringUtf8(cd, &clk_fg, clk_font_big, tx, ty,
(const FcChar8 *)tbuf, tlen);
}
if (clk_font_small) {
size_t dlen = strlen(dbuf);
XftTextExtentsUtf8(dpy, clk_font_small, (const FcChar8 *)dbuf, dlen, &ext);
int dx = (m->ww - ext.xOff) / 2;
int dy = 73;
XftDrawStringUtf8(cd, &clk_sh, clk_font_small, dx + 1, dy + 1,
(const FcChar8 *)dbuf, dlen);
XftDrawStringUtf8(cd, &clk_fg, clk_font_small, dx, dy,
(const FcChar8 *)dbuf, dlen);
}
XftDrawDestroy(cd);
}
}
}
}
void
@@ -1403,9 +1483,11 @@ focus(Client *c)
attachstack(c);
grabbuttons(c, 1);
XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
setfocus(c);
if (!is_passcode_locked())
setfocus(c);
} else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
if (!is_passcode_locked())
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
}
selmon->sel = c;
@@ -1419,6 +1501,8 @@ focusin(XEvent *e)
{
XFocusChangeEvent *ev = &e->xfocus;
if (is_passcode_locked())
return;
if (selmon->sel && ev->window != selmon->sel->win)
setfocus(selmon->sel);
}
@@ -2122,6 +2206,7 @@ dwm_rescan_input_fds(int force)
close(input_fds[i]);
}
num_input_fds = 0;
lid_close_fd = -1;
for (i = 0; i < MAX_INPUT_FDS; i++) {
char evpath[64], evname[128] = "";
int evfd;
@@ -2301,11 +2386,30 @@ flush_pending_starpound(void)
(void)dispatch_plugin_idle_key(ks, kc, 0);
}
static void
forward_key_to_locker(unsigned int keycode, unsigned int state)
{
if (is_plugin_daemon_alive("locker")) {
int fd = open("/tmp/dwm_plugin_locker.fifo", O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (fd >= 0) {
char msg[64];
int len = snprintf(msg, sizeof(msg), "KEY %u %u\n", keycode, state);
if (write(fd, msg, len) == len) {
close(fd);
return;
}
close(fd);
}
}
host_spawn_plugin("locker", "wake");
}
static void
lock_phone_screenoff(void)
{
const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff");
int lfd, cfd;
lid_close_pending = 0;
lid_close_deadline_ms = 0;
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
@@ -2316,6 +2420,8 @@ lock_phone_screenoff(void)
star_down = 0;
pound_down = 0;
write_softkey_state(0, 0);
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
cfd = open("/tmp/dwm_plugin_callscreen.fifo", O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (cfd >= 0) {
(void)write(cfd, "HANGUP_CLOSE\n", 13);
@@ -2333,7 +2439,6 @@ lock_phone_screenoff(void)
host_spawn_plugin("locker", "screenoff");
set_sxmo_state_str("screenoff");
set_hw_backlight(0);
spawn(&offcmd);
}
static void
@@ -2342,6 +2447,8 @@ wake_phone(void)
const Arg oncmd = SHCMD("sxmo_state.sh set unlock");
long long now = dwm_now_ms();
lid_close_pending = 0;
lid_close_deadline_ms = 0;
last_wake_ms = now;
softkey_pending = 0;
softkey_first_ms = 0;
@@ -2354,14 +2461,15 @@ wake_phone(void)
pound_down = 0;
write_softkey_state(0, 0);
write_softkey_suppress(now + SOFTKEY_SUPPRESS_MS);
set_hw_backlight(1);
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
if (is_passcode_locked()) {
set_sxmo_state_str("lock");
host_spawn_plugin("locker", "wake");
set_hw_backlight(1);
return;
}
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
set_hw_backlight(1);
set_sxmo_state_str("unlock");
spawn(&oncmd);
}
@@ -2384,13 +2492,15 @@ keypress(XEvent *e)
return;
}
if (is_passcode_locked()) {
XUngrabKeyboard(dpy, CurrentTime);
XFlush(dpy);
if (CLEANMASK(ev->state) == 0 &&
(keysym == XF86XK_PowerOff || ev->keycode == 124 ||
keysym == XF86XK_Phone || keysym == XF86XK_PickupPhone || ev->keycode == 177)) {
if (dispatch_plugin_global_key(keysym, ev->keycode, CLEANMASK(ev->state), 1))
return;
}
host_spawn_plugin("locker", "wake");
forward_key_to_locker(ev->keycode, CLEANMASK(ev->state));
return;
}
if (is_phone_locked()) {
@@ -3021,6 +3131,25 @@ run(void)
timeout_ms = (int)rem;
}
}
if (lid_close_pending && lid_close_deadline_ms > 0) {
long long now = dwm_now_ms();
long long rem = lid_close_deadline_ms - now;
if (rem <= 0) {
unsigned long swbits[(SW_MAX + 8 * sizeof(unsigned long)) / (8 * sizeof(unsigned long))] = {0};
int still_closed = 1;
if (lid_close_fd >= 0 && ioctl(lid_close_fd, EVIOCGSW(sizeof(swbits)), swbits) >= 0) {
still_closed = (swbits[SW_LID / (8 * sizeof(unsigned long))] >> (SW_LID % (8 * sizeof(unsigned long)))) & 1;
}
lid_close_pending = 0;
lid_close_deadline_ms = 0;
if (still_closed) {
lock_phone_screenoff();
}
continue;
} else if (timeout_ms < 0 || rem < timeout_ms) {
timeout_ms = (int)rem;
}
}
if (poll(fds, nfds, timeout_ms) < 0) {
if (errno == EINTR)
continue;
@@ -3037,10 +3166,19 @@ run(void)
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();
lid_close_pending = 1;
lid_close_fd = input_fds[i];
lid_close_deadline_ms = dwm_now_ms() + 60;
} else if (ie.value == 0) {
lid_close_pending = 0;
lid_close_deadline_ms = 0;
wake_phone();
}
} else if (ie.type == EV_SW && ie.code == 10 && ie.value == 1) {
lid_close_pending = 0;
lid_close_deadline_ms = 0;
if (is_screen_off())
wake_phone();
} else if (ie.type == EV_REL && ie.value != 0) {
dwm_cursor_set_visible(1);
} else if (ie.type == EV_KEY) {
@@ -3612,6 +3750,20 @@ updatebars(void)
XLowerWindow(dpy, m->softwin);
XSetClassHint(dpy, m->softwin, &ch);
}
if (!m->clockwin) {
XSetWindowAttributes clockwa = {
.override_redirect = True,
.background_pixmap = ParentRelative,
.event_mask = ExposureMask
};
m->clockwin = XCreateWindow(dpy, root, m->wx, m->my + 29, m->ww, 92, 0,
DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect|CWBackPixmap|CWEventMask, &clockwa);
XDefineCursor(dpy, m->clockwin, cursor[CurNormal]->cursor);
XMapWindow(dpy, m->clockwin);
XLowerWindow(dpy, m->clockwin);
XSetClassHint(dpy, m->clockwin, &ch);
}
if (m->barwin)
continue;
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
@@ -3977,7 +4129,7 @@ wintomon(Window w)
if (w == root && getrootptr(&x, &y))
return recttomon(x, y, 1, 1);
for (m = mons; m; m = m->next)
if (w == m->barwin || w == m->softwin)
if (w == m->barwin || w == m->softwin || w == m->clockwin)
return m;
if ((c = wintoclient(w)))
return c->mon;