Fix instant QMI call hangup, eliminate post-call dialer/callscreen popups and desktop clock flicker

This commit is contained in:
Luxferre committed 2026-11-05 09:51:53 +02:00
1 parent 1d71bc81d8
commit c9c870c3bb
27 files changed
+867 -308

No files matched your search

+2 -2
View File
@@ -547,12 +547,12 @@ int calllog_run_main(int argc, char** argv) {
if (!selNum.empty()) {
mode = ViewMode::Log;
writeSoftkeySuppress(nowMs() + 350);
placePhoneCall(selNum);
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
::unlink(activePidPath.c_str());
visible = false;
placePhoneCall(selNum);
}
break;
}
@@ -1007,8 +1007,8 @@ int calllog_run_main(int argc, char** argv) {
selected < static_cast<int>(filtered.size())) {
std::string num = filtered[selected].number;
writeSoftkeySuppress(nowMs() + 350);
hideWindow(true);
placePhoneCall(num);
hideWindow(false);
} else if (filtered.empty()) {
if (filterTab == 4) {
blockList.load();
+292 -40
View File
@@ -484,6 +484,7 @@ int callscreen_run_main(int argc, char** argv) {
int64_t callStartMs = 0;
int64_t endedAtMs = 0;
int64_t lastHangupMs = 0;
int lastFinalDurationSec = 0;
int64_t lastModemPollMs = 0;
@@ -860,7 +861,9 @@ int callscreen_run_main(int argc, char** argv) {
if (callState == CallState::Incoming) {
writeIntFile("/tmp/sxmo_call_ringing", 1);
writeIntFile("/tmp/sxmo_active_call", 1);
} else if (callState == CallState::Outgoing || callState == CallState::Active) {
} else if (callState == CallState::SelectSim ||
callState == CallState::Outgoing ||
callState == CallState::Active) {
::unlink("/tmp/sxmo_call_ringing");
writeIntFile("/tmp/sxmo_active_call", 2);
} else {
@@ -1422,6 +1425,7 @@ int callscreen_run_main(int argc, char** argv) {
}
endReason = reason.empty() ? "CALL ENDED" : reason;
callState = CallState::Ended;
callId.clear();
endedAtMs = nowMs();
dtmfMode = false;
ringMuted = false;
@@ -1465,7 +1469,168 @@ int callscreen_run_main(int argc, char** argv) {
"sxmo_modemaudio.sh disable_call_audio_mode >/dev/null 2>&1");
};
auto hangupQmiVoiceCallsNow = [&]() {
constexpr int kAfQipcrtr = 42;
constexpr uint32_t kQrtrPortCtrl = 0xfffffffeu;
constexpr uint32_t kQrtrTypeNewServer = 4;
constexpr uint32_t kQrtrTypeNewLookup = 10;
constexpr uint32_t kQmiServiceVoice = 9;
struct SockAddrQrtr {
unsigned short sq_family;
uint32_t sq_node;
uint32_t sq_port;
};
struct QrtrCtrlPkt {
uint32_t cmd;
uint32_t service;
uint32_t instance;
uint32_t node;
uint32_t port;
} __attribute__((packed));
int lfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (lfd < 0) {
return;
}
SockAddrQrtr localSq {};
socklen_t sl = sizeof(localSq);
if (::getsockname(lfd, reinterpret_cast<struct sockaddr*>(&localSq), &sl) < 0) {
::close(lfd);
return;
}
SockAddrQrtr ctrlSq { kAfQipcrtr, localSq.sq_node, kQrtrPortCtrl };
QrtrCtrlPkt lookup { kQrtrTypeNewLookup, kQmiServiceVoice, 0, 0, 0 };
if (::sendto(lfd, &lookup, sizeof(lookup), 0,
reinterpret_cast<const struct sockaddr*>(&ctrlSq),
sizeof(ctrlSq)) < 0) {
::close(lfd);
return;
}
uint32_t vNode = 0, vPort = 0;
bool foundSrv = false;
for (int i = 0; i < 8; ++i) {
struct pollfd pfd { lfd, POLLIN, 0 };
if (::poll(&pfd, 1, 30) <= 0) break;
QrtrCtrlPkt pkt {};
ssize_t n = ::recv(lfd, &pkt, sizeof(pkt), 0);
if (n >= static_cast<ssize_t>(sizeof(pkt)) && pkt.cmd == kQrtrTypeNewServer) {
if (pkt.service == kQmiServiceVoice && pkt.port != 0) {
vNode = pkt.node;
vPort = pkt.port;
foundSrv = true;
break;
}
if (pkt.service == 0 && pkt.node == 0 && pkt.port == 0) break;
}
}
::close(lfd);
if (!foundSrv) {
return;
}
SockAddrQrtr vSq { kAfQipcrtr, vNode, vPort };
for (int sub : {1, 0}) {
int sfd = ::socket(kAfQipcrtr, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sfd < 0) continue;
uint8_t bindReq[11] = {
0x00, 0x01, 0x00, 0x44, 0x00, 0x04, 0x00,
0x01, 0x01, 0x00, static_cast<uint8_t>(sub)
};
::sendto(sfd, bindReq, sizeof(bindReq), 0,
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
struct pollfd pfd { sfd, POLLIN, 0 };
int64_t bindDeadline = nowMs() + 60;
while (nowMs() < bindDeadline) {
int waitMs = static_cast<int>(std::max<int64_t>(2, bindDeadline - nowMs()));
if (::poll(&pfd, 1, waitMs) <= 0) break;
uint8_t tmp[512];
ssize_t rlen = ::recv(sfd, tmp, sizeof(tmp), 0);
if (rlen >= 7 && tmp[0] == 0x02 && tmp[1] == 0x01 && tmp[2] == 0x00 &&
tmp[3] == 0x44 && tmp[4] == 0x00) {
break;
}
}
uint8_t infoReq[7] = { 0x00, 0x02, 0x00, 0x2F, 0x00, 0x00, 0x00 };
::sendto(sfd, infoReq, sizeof(infoReq), 0,
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
std::vector<uint8_t> cidsToHangup;
int64_t infoDeadline = nowMs() + 80;
while (nowMs() < infoDeadline) {
int waitMs = static_cast<int>(std::max<int64_t>(2, infoDeadline - nowMs()));
if (::poll(&pfd, 1, waitMs) <= 0) break;
uint8_t buf[1024];
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) {
const uint8_t* rawCi01 = nullptr;
uint16_t lenCi01 = 0;
const uint8_t* rawCi10 = nullptr;
uint16_t lenCi10 = 0;
size_t pos = 7;
while (pos + 3 <= static_cast<size_t>(rlen)) {
uint8_t tt = buf[pos];
uint16_t tl = static_cast<uint16_t>(buf[pos + 1]) |
(static_cast<uint16_t>(buf[pos + 2]) << 8);
pos += 3;
if (pos + tl > static_cast<size_t>(rlen)) break;
if (tt == 0x01) {
rawCi01 = buf + pos;
lenCi01 = tl;
} else if (tt == 0x10) {
rawCi10 = buf + pos;
lenCi10 = tl;
}
pos += tl;
}
const uint8_t* rawCi = rawCi01 ? rawCi01 : rawCi10;
uint16_t lenCi = rawCi01 ? lenCi01 : lenCi10;
if (rawCi && lenCi >= 1) {
uint8_t cnt = rawCi[0];
size_t off = 1;
for (uint8_t i = 0; i < cnt && off + 7 <= lenCi; ++i, off += 7) {
uint8_t cid = rawCi[off];
uint8_t cstate = rawCi[off + 1];
if (cstate != 8 && cstate != 9 && cid > 0) {
cidsToHangup.push_back(cid);
}
}
}
break;
}
}
if (cidsToHangup.empty()) {
cidsToHangup.push_back(1);
}
uint8_t txn = 3;
for (uint8_t cid : cidsToHangup) {
uint8_t endReq[11] = {
0x00, txn, 0x00, 0x21, 0x00, 0x04, 0x00,
0x01, 0x01, 0x00, cid
};
::sendto(sfd, endReq, sizeof(endReq), 0,
reinterpret_cast<const struct sockaddr*>(&vSq), sizeof(vSq));
int64_t endDeadline = nowMs() + 50;
while (nowMs() < endDeadline) {
int waitMs = static_cast<int>(std::max<int64_t>(2, endDeadline - nowMs()));
if (::poll(&pfd, 1, waitMs) <= 0) break;
uint8_t tmp[512];
ssize_t rlen = ::recv(sfd, tmp, sizeof(tmp), 0);
if (rlen >= 7 && tmp[0] == 0x02 && tmp[1] == txn && tmp[2] == 0x00 &&
tmp[3] == 0x21 && tmp[4] == 0x00) {
break;
}
}
++txn;
}
::close(sfd);
}
};
auto hangupCall = [&](bool closeImmediately = false) {
lastHangupMs = nowMs();
writeIntFile("/tmp/sxmo_hangup_requested", 1);
std::string cid = resolveActiveModemCallId();
bool wasIncoming = (callState == CallState::Incoming);
stopRingingJobs();
@@ -1473,12 +1638,34 @@ int callscreen_run_main(int argc, char** argv) {
sendPluginCommand("sip", "CALL_HANGUP " + cid);
} else if (cid.rfind("tox:", 0) == 0 || activeSimSlot == 4) {
sendPluginCommand("tox", "CALL_HANGUP " + cid);
} else if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str());
} else {
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
sendPluginCommand("sip", "CALL_HANGUP");
sendPluginCommand("tox", "CALL_HANGUP");
hangupQmiVoiceCallsNow();
std::string callsDir = getRuntimeFile("sxmo_calls");
DIR* d = ::opendir(callsDir.c_str());
if (d) {
struct dirent* ent;
while ((ent = ::readdir(d)) != nullptr) {
if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') {
std::string fn(ent->d_name);
if (fn.rfind("sub", 0) == 0 ||
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) {
std::string fpPath = callsDir + "/" + fn;
::unlink(fpPath.c_str());
}
}
}
::closedir(d);
}
if (!cid.empty() && cid != "-" && cid != "sim" && cid != "test") {
runAsyncArgv("sxmo_modemcall.sh", "hangup", cid.c_str());
} else {
runAsyncArgv("sxmo_modemcall.sh", "hangup", "all");
sendPluginCommand("sip", "CALL_HANGUP");
sendPluginCommand("tox", "CALL_HANGUP");
}
}
if (closeImmediately || !visible || callState == CallState::Idle ||
callState == CallState::SelectSim || callState == CallState::Ended) {
@@ -1660,7 +1847,7 @@ int callscreen_run_main(int argc, char** argv) {
else if (cstate == 6) st = "held";
if (!st.empty() && outId.empty()) {
outId = (sub == 1) ? ("sub1_" + std::to_string(cid))
: std::to_string(cid);
: ("sub0_" + std::to_string(cid));
outState = st;
outDir = (cdir == 2) ? "incoming" : "outgoing";
if (rawNum && lenNum >= 1) {
@@ -1693,13 +1880,17 @@ int callscreen_run_main(int argc, char** argv) {
if (callId == "sim" || callId == "test" || isVoipCallId(callId)) {
return;
}
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
::access("/tmp/sxmo_hangup_requested", F_OK) == 0) {
return;
}
std::string foundId;
std::string foundDir;
std::string foundState;
std::string foundNum;
bool sawTerminated = false;
if (callId.rfind("sub", 0) != 0) {
if (callId.rfind("sub1_", 0) != 0) {
FILE* fp = ::popen("mmcli -m any --voice-list-calls -a 2>/dev/null", "r");
if (fp) {
char line[512];
@@ -1891,9 +2082,9 @@ int callscreen_run_main(int argc, char** argv) {
if (line == "ENDED" || line.rfind("ENDED ", 0) == 0) {
std::string reason = (line.size() > 6) ? trimStr(line.substr(6)) : "CALL ENDED";
sipZrtpSas.clear();
if (callState != CallState::Idle) {
if (callState != CallState::Idle && callState != CallState::Ended) {
transitionToEnded(reason);
} else {
} else if (callState == CallState::Idle) {
hideWindow(false);
}
return;
@@ -1904,13 +2095,46 @@ int callscreen_run_main(int argc, char** argv) {
std::string verb, arg1, arg2, arg3;
iss >> verb >> arg1 >> arg2 >> arg3;
if (verb == "PROMPT_SIM") {
if (verb == "DIAL" || verb == "PROMPT_SIM") {
if (callState == CallState::Incoming || callState == CallState::Outgoing ||
callState == CallState::Active) {
showWindow();
return;
}
simInfo = queryDualSimInfo(true);
lastHangupMs = 0;
::unlink("/tmp/sxmo_hangup_requested");
if (!simInfo.slot1Present && !simInfo.slot2Present) {
simInfo = queryDualSimInfo(false);
}
if (verb == "DIAL" && !simInfo.dualSimActive) {
int slot = (simInfo.primaryGwSlot == 2) ? 2 : 1;
std::string simStr = std::to_string(slot);
std::string num = normalizePhone(arg1);
if (!num.empty()) {
callId.clear();
callNumber.clear();
contactName.clear();
updateCallerDetails("-", num);
activeSimSlot = slot;
callState = CallState::Outgoing;
callStartMs = nowMs();
lastModemPollMs = callStartMs;
missingModemPolls = 0;
ringMuted = false;
speakerOn = false;
btAudioOn = hasBtAudioCard();
dtmfMode = false;
dtmfSent.clear();
selectedRow = 0;
setSpeakerRoute(false, btAudioOn);
statusNotice.clear();
statusNoticeUntilMs = 0;
writeActiveStateFiles();
showWindow();
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
}
return;
}
callId = "-";
callNumber.clear();
contactName.clear();
@@ -1920,6 +2144,11 @@ int callscreen_run_main(int argc, char** argv) {
activeSimSlot = 0;
writeActiveStateFiles();
showWindow();
if (simInfo.slot1Operator.empty() && simInfo.slot2Operator.empty()) {
simInfo = queryDualSimInfo(true);
selectedRow = (simInfo.preferredSlot == 2) ? 1 : 0;
render();
}
return;
}
@@ -1968,6 +2197,8 @@ int callscreen_run_main(int argc, char** argv) {
};
if (verb == "INCOMING") {
lastHangupMs = 0;
::unlink("/tmp/sxmo_hangup_requested");
callId.clear();
callNumber.clear();
contactName.clear();
@@ -1989,31 +2220,46 @@ int callscreen_run_main(int argc, char** argv) {
writeActiveStateFiles();
showWindow();
} else if (verb == "OUTGOING") {
callId.clear();
callNumber.clear();
contactName.clear();
recordFileName.clear();
recordFilePath.clear();
lastRecordedSec = 0;
recordedClipCount = 0;
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
::access("/tmp/sxmo_hangup_requested", F_OK) == 0) {
return;
}
lastHangupMs = 0;
bool alreadyOutgoing = (callState == CallState::Outgoing);
if (!alreadyOutgoing) {
callId.clear();
callNumber.clear();
contactName.clear();
recordFileName.clear();
recordFilePath.clear();
lastRecordedSec = 0;
recordedClipCount = 0;
}
updateCallerDetails(arg1, arg2);
parseSimTag(arg1, arg3);
callState = CallState::Outgoing;
callStartMs = nowMs();
lastModemPollMs = callStartMs;
if (!alreadyOutgoing) {
callStartMs = nowMs();
ringMuted = false;
speakerOn = false;
btAudioOn = hasBtAudioCard();
dtmfMode = false;
dtmfSent.clear();
selectedRow = 0;
setSpeakerRoute(false, btAudioOn);
statusNotice.clear();
statusNoticeUntilMs = 0;
}
lastModemPollMs = nowMs();
missingModemPolls = 0;
ringMuted = false;
speakerOn = false;
btAudioOn = hasBtAudioCard();
dtmfMode = false;
dtmfSent.clear();
selectedRow = 0;
setSpeakerRoute(false, btAudioOn);
statusNotice.clear();
statusNoticeUntilMs = 0;
writeActiveStateFiles();
showWindow();
} else if (verb == "ACTIVE") {
if (lastHangupMs > 0 && nowMs() - lastHangupMs < 4000 &&
::access("/tmp/sxmo_hangup_requested", F_OK) == 0) {
return;
}
lastHangupMs = 0;
bool wasActive = (callState == CallState::Active);
bool wasOutgoing = (callState == CallState::Outgoing);
updateCallerDetails(arg1, arg2);
@@ -2044,7 +2290,9 @@ int callscreen_run_main(int argc, char** argv) {
if (callState == CallState::Idle || callState == CallState::Ended) {
syncModemCalls();
}
showWindow();
if (callState != CallState::Idle || !arg1.empty()) {
showWindow();
}
}
};
@@ -2057,6 +2305,8 @@ int callscreen_run_main(int argc, char** argv) {
if (num.empty()) {
return;
}
lastHangupMs = 0;
::unlink("/tmp/sxmo_hangup_requested");
std::string simStr = (chosenSim == 2) ? "2" : "1";
handleFifoCommand("OUTGOING - " + num + " SIM" + simStr);
runAsyncArgv("sxmo_modemdial.sh", "--sim", simStr.c_str(), num.c_str());
@@ -2120,10 +2370,6 @@ int callscreen_run_main(int argc, char** argv) {
writeActiveStateFiles();
}
hideWindow(false);
} else {
XRaiseWindow(dpy, win);
grabPluginKeyboard(dpy, win);
render();
}
} else if (ev.type == KeyRelease) {
KeySym sym = XLookupKeysym(&ev.xkey, 0);
@@ -2374,16 +2620,22 @@ int callscreen_run_main(int argc, char** argv) {
}
}
if (visible && (callState != CallState::Idle || checkRecordingAlive())) {
static int64_t lastTimerRenderMs = 0;
bool hasLiveTimer = (callState == CallState::Outgoing ||
callState == CallState::Active ||
checkRecordingAlive());
if (visible && hasLiveTimer && nowMs() - lastTimerRenderMs >= 250) {
lastTimerRenderMs = nowMs();
render();
}
int timeoutMs = -1;
if (visible || callState != CallState::Idle || checkRecordingAlive()) {
if (softkeyDeadlineMs > 0) {
timeoutMs = static_cast<int>(std::max<int64_t>(5, softkeyDeadlineMs - nowMs()));
} else if (callState == CallState::Ended && endedAtMs > 0) {
timeoutMs = static_cast<int>(std::max<int64_t>(10, 1300 - (nowMs() - endedAtMs)));
} else if (hasLiveTimer || callState == CallState::Incoming) {
timeoutMs = 250;
if (softkeyDeadlineMs > 0) {
timeoutMs = static_cast<int>(std::max<int64_t>(5, softkeyDeadlineMs - nowMs()));
}
}
struct pollfd pfds[2] {};
+6 -3
View File
@@ -1046,8 +1046,8 @@ int runContactsApp(int argc, char** argv) {
switch (actIdx) {
case 0: // Call Contact
writeSoftkeySuppress(nowMs() + 350);
hideWindow(true);
placePhoneCall(c.number);
hideWindow(false);
break;
case 1: // Send SMS
writeSoftkeySuppress(nowMs() + 350);
@@ -1304,8 +1304,8 @@ int runContactsApp(int argc, char** argv) {
if (selected >= 0 && selected < static_cast<int>(filtered.size())) {
std::string target = filtered[selected].number;
writeSoftkeySuppress(nowMs() + 350);
hideWindow(true);
placePhoneCall(target);
hideWindow(false);
}
break;
case XK_Return:
@@ -1323,8 +1323,8 @@ int runContactsApp(int argc, char** argv) {
selected < static_cast<int>(filtered.size())) {
std::string target = filtered[selected].number;
writeSoftkeySuppress(nowMs() + 350);
hideWindow(true);
placePhoneCall(target);
hideWindow(false);
}
break;
}
@@ -1769,6 +1769,9 @@ int contacts_on_idle_key(const DwmHostApi* host, KeySym keysym,
if (!host || !host->is_idle_desktop || !host->is_idle_desktop() || state != 0) {
return 0;
}
if (isCallActiveOrRingingFast() || isAnotherPluginActive("contacts")) {
return 0;
}
if (keysym == XF86XK_Back || keysym == XF86XK_KbdLcdMenu2 || keycode == 166) {
if (host->spawn_plugin) {
host->spawn_plugin("contacts", nullptr);
+9 -2
View File
@@ -571,6 +571,10 @@ int dialer_run_main(int argc, char** argv) {
};
auto showWindow = [&](const std::string& arg) {
if (!visible && (isCallActiveOrRingingFast() ||
isPidFileAlive(getRuntimeFile("xcallscreen.pid")))) {
return;
}
writeIntFile(activePidPath, static_cast<int>(::getpid()));
closeOtherPlugins("dialer");
modal = DialerModal::Inactive;
@@ -939,8 +943,8 @@ int dialer_run_main(int argc, char** argv) {
case XF86XK_Send: {
if (isCallActiveOrRingingFast()) {
writeSoftkeySuppress(nowMs() + 350);
hideWindow(false);
placePhoneCall("");
hideWindow(false);
break;
}
std::string target = selectActiveNumber();
@@ -960,8 +964,8 @@ int dialer_run_main(int argc, char** argv) {
executeUssd(target, false);
} else {
writeSoftkeySuppress(nowMs() + 350);
hideWindow(false);
placePhoneCall(target);
hideWindow(false);
}
}
break;
@@ -1085,6 +1089,9 @@ int dialer_on_idle_key(const DwmHostApi* host, KeySym keysym,
if (!host || !host->is_idle_desktop || !host->is_idle_desktop()) {
return 0;
}
if (isCallActiveOrRingingFast() || isAnotherPluginActive("dialer")) {
return 0;
}
char ch = mapDialKey(keysym, keycode, state);
if (ch == '\0') {
return 0;
+7 -1
View File
@@ -1568,7 +1568,8 @@ inline DualSimInfo queryDualSimInfo(bool forceRefresh = false) {
static DualSimInfo cached;
static int64_t lastQueryMs = 0;
int64_t now = nowMs();
if (!forceRefresh && lastQueryMs > 0 && (now - lastQueryMs) < 3000) {
int64_t ttlMs = (cached.slot1Present || cached.slot2Present) ? 60000 : 3000;
if (!forceRefresh && lastQueryMs > 0 && (now - lastQueryMs) < ttlMs) {
return cached;
}
@@ -1890,7 +1891,12 @@ inline void placePhoneCall(const std::string& rawNumber, int simSlot = 0) {
if (num.empty()) {
return;
}
::unlink("/tmp/sxmo_hangup_requested");
writeIntFile("/tmp/sxmo_active_call", 2);
if (simSlot == 0) {
if (sendPluginCommand("callscreen", "DIAL " + num)) {
return;
}
DualSimInfo dsi = queryDualSimInfo();
if (dsi.dualSimActive) {
if (!sendPluginCommand("callscreen", "PROMPT_SIM " + num)) {
+3 -3
View File
@@ -1137,8 +1137,8 @@ int runSmsApp(int argc, char** argv) {
? filteredThreads[selectedThread].number
: "");
if (!target.empty()) {
hideWindow();
placePhoneCall(target);
hideWindow();
}
} else if (optId == 5) {
std::string target = (prevMode == ViewMode::ThreadView)
@@ -1451,12 +1451,12 @@ int runSmsApp(int argc, char** argv) {
startAsyncSendSms(composeRecipient, composeText);
drawUI();
} else if (mode == ViewMode::ThreadView && !activeNumber.empty()) {
hideWindow();
placePhoneCall(activeNumber);
hideWindow();
} else if (mode == ViewMode::Threads && !filteredThreads.empty()) {
std::string num = filteredThreads[selectedThread].number;
hideWindow();
placePhoneCall(num);
hideWindow();
}
continue;
}
+150 -101
View File
@@ -1080,6 +1080,144 @@ dirtomon(int dir)
return m;
}
static void
drawsoftbar(Monitor *m, int force)
{
static int last_has_sel = -1;
int has_sel;
if (!m || !m->softwin || !drw || !drw->font || is_screen_off())
return;
has_sel = (m->sel != NULL);
if (!force && has_sel == last_has_sel)
return;
last_has_sel = has_sel;
XLowerWindow(dpy, m->softwin);
XClearWindow(dpy, m->softwin);
if (!has_sel) {
XftDraw *d = XftDrawCreate(dpy, m->softwin,
DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
if (d) {
unsigned int ew = 0, eh = 0;
const char *left_txt = "Menu";
const char *right_txt = "Names";
int sh_bar = 26;
drw_font_getexts(drw->font, left_txt, strlen(left_txt), &ew, &eh, False);
int ty = (sh_bar - (int)eh) / 2;
pango_layout_set_text(drw->font->layout, left_txt, strlen(left_txt));
pango_xft_render_layout(d, &scheme[SchemeSel][ColFg],
drw->font->layout, 6 * PANGO_SCALE, ty * PANGO_SCALE);
drw_font_getexts(drw->font, right_txt, strlen(right_txt), &ew, &eh, False);
ty = (sh_bar - (int)eh) / 2;
int rx = m->ww - (int)ew - 6;
pango_layout_set_text(drw->font->layout, right_txt, strlen(right_txt));
pango_xft_render_layout(d, &scheme[SchemeSel][ColFg],
drw->font->layout, rx * PANGO_SCALE, ty * PANGO_SCALE);
XftDrawDestroy(d);
}
}
}
static void
drawclock(Monitor *m, int force)
{
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] = "";
static int last_has_sel = -1;
static char last_tbuf[32] = "";
static char last_dbuf[64] = "";
char tzlink[256], tbuf[32], dbuf[64];
ssize_t tzlen;
time_t now;
struct tm lt;
int has_sel;
if (!m || !m->clockwin || is_screen_off())
return;
has_sel = (m->sel != NULL);
if (has_sel) {
if (!force && last_has_sel == 1)
return;
last_has_sel = 1;
XLowerWindow(dpy, m->clockwin);
XClearWindow(dpy, m->clockwin);
return;
}
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();
force = 1;
}
}
now = time(NULL);
localtime_r(&now, &lt);
strftime(tbuf, sizeof(tbuf), "%H:%M", &lt);
strftime(dbuf, sizeof(dbuf), "%a %d %b %Y", &lt);
if (!force && last_has_sel == 0 &&
strcmp(tbuf, last_tbuf) == 0 && strcmp(dbuf, last_dbuf) == 0)
return;
last_has_sel = 0;
snprintf(last_tbuf, sizeof(last_tbuf), "%s", tbuf);
snprintf(last_dbuf, sizeof(last_dbuf), "%s", dbuf);
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;
}
XLowerWindow(dpy, m->clockwin);
XClearWindow(dpy, m->clockwin);
XftDraw *cd = XftDrawCreate(dpy, m->clockwin,
DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
if (cd) {
XGlyphInfo ext;
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
drawbar(Monitor *m)
{
@@ -1135,105 +1273,8 @@ drawbar(Monitor *m)
drw_text(drw, MAX(x, m->ww - sw), 0, sw, bh, 0, s, 0, True);
}
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
if (m->softwin && drw && drw->font) {
XLowerWindow(dpy, m->softwin);
XClearWindow(dpy, m->softwin);
if (!m->sel) {
XftDraw *d = XftDrawCreate(dpy, m->softwin,
DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
if (d) {
unsigned int ew = 0, eh = 0;
const char *left_txt = "Menu";
const char *right_txt = "Names";
int sh_bar = 26;
drw_font_getexts(drw->font, left_txt, strlen(left_txt), &ew, &eh, False);
int ty = (sh_bar - (int)eh) / 2;
pango_layout_set_text(drw->font->layout, left_txt, strlen(left_txt));
pango_xft_render_layout(d, &scheme[SchemeSel][ColFg],
drw->font->layout, 6 * PANGO_SCALE, ty * PANGO_SCALE);
drw_font_getexts(drw->font, right_txt, strlen(right_txt), &ew, &eh, False);
ty = (sh_bar - (int)eh) / 2;
int rx = m->ww - (int)ew - 6;
pango_layout_set_text(drw->font->layout, right_txt, strlen(right_txt));
pango_xft_render_layout(d, &scheme[SchemeSel][ColFg],
drw->font->layout, rx * PANGO_SCALE, ty * PANGO_SCALE);
XftDrawDestroy(d);
}
}
}
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);
}
}
}
drawsoftbar(m, 0);
drawclock(m, 0);
}
void
@@ -1270,8 +1311,14 @@ expose(XEvent *e)
Monitor *m;
XExposeEvent *ev = &e->xexpose;
if (ev->count == 0 && (m = wintomon(ev->window)))
drawbar(m);
if (ev->count == 0 && (m = wintomon(ev->window))) {
if (ev->window == m->softwin)
drawsoftbar(m, 1);
else if (ev->window == m->clockwin)
drawclock(m, 1);
else
drawbar(m);
}
}
static void
@@ -4336,6 +4383,8 @@ reload_dwm_theme(void)
else
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
}
drawsoftbar(m, 1);
drawclock(m, 1);
}
drawbars();
}