Add Gambatte GB/GBC emulator, Call/SMS anti-spam blocklist, and Lua/bc/dc/Yabasic

This commit is contained in:
Luxferre committed 2026-10-26 15:17:55 +02:00
1 parent b7f0dc08c9
commit 6db14be799
113 files changed
+20006 -237

No files matched your search

+661 -160
View File
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
// CallLog DWM Plugin - Preloaded resident X11 call log viewer & dialer launcher (240x320)
// CallLog DWM Plugin - Preloaded resident X11 call log viewer, anti-spam blocklist & dialer launcher (240x320)
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
@@ -37,6 +37,20 @@ void handleSignal(int) {
gRunning = 0;
}
enum class ViewMode {
Log = 0,
Options = 1,
Blocklist = 2,
AddBlock = 3,
};
struct OptionEntry {
int id;
std::string icon;
std::string label;
bool danger = false;
};
int calllog_run_main(int argc, char** argv) {
gRunning = 1;
bool isPreload = false;
@@ -116,13 +130,29 @@ int calllog_run_main(int argc, char** argv) {
XftColor& colRed = theme.colRed;
ContactBook book;
BlockList blockList;
std::vector<CallLogItem> allLogs;
std::vector<CallLogItem> blockedLogs;
std::vector<CallLogItem> filtered;
FileStamp contactsStamp;
FileStamp logStamp;
FileStamp blockFileStamp;
FileStamp blockLogStamp;
int filterTab = 0; // 0 = All, 1 = Missed, 2 = In, 3 = Out
constexpr int kNumTabs = 5;
const char* kTabLabels[kNumTabs] = {"All", "Miss", "In", "Out", "Spam"};
ViewMode mode = ViewMode::Log;
int filterTab = 0; // 0 = All, 1 = Missed, 2 = In, 3 = Out, 4 = Spam/Blocked
int selected = 0;
int optionSelected = 0;
int blockSelected = 0;
std::vector<OptionEntry> options;
std::string addBlockInput;
std::string toastMsg;
int64_t toastUntilMs = 0;
bool visible = false;
int64_t openStartMs = 0;
int64_t startupIgnoreUntilMs = 0;
@@ -130,13 +160,32 @@ int calllog_run_main(int argc, char** argv) {
int softkeyPending = 0;
int64_t softkeyDeadlineMs = 0;
auto showToast = [&](const std::string& msg) {
toastMsg = msg;
toastUntilMs = nowMs() + 1800;
};
auto applyFilter = [&]() {
filtered.clear();
for (const auto& item : allLogs) {
if (filterTab == 1 && item.direction != CallDirection::Missed) continue;
if (filterTab == 2 && item.direction != CallDirection::Incoming) continue;
if (filterTab == 3 && item.direction != CallDirection::Outgoing) continue;
filtered.push_back(item);
if (filterTab == 4) {
for (auto item : blockedLogs) {
item.isBlockedNumber = blockList.isBlocked(item.number);
filtered.push_back(item);
}
for (auto item : allLogs) {
if (blockList.isBlocked(item.number)) {
item.isBlockedNumber = true;
filtered.push_back(item);
}
}
} else {
for (auto item : allLogs) {
if (filterTab == 1 && item.direction != CallDirection::Missed) continue;
if (filterTab == 2 && item.direction != CallDirection::Incoming) continue;
if (filterTab == 3 && item.direction != CallDirection::Outgoing) continue;
item.isBlockedNumber = blockList.isBlocked(item.number);
filtered.push_back(item);
}
}
if (selected >= static_cast<int>(filtered.size())) {
selected = std::max(0, static_cast<int>(filtered.size()) - 1);
@@ -144,21 +193,60 @@ int calllog_run_main(int argc, char** argv) {
};
bool logsLoadedOnce = false;
auto reloadLogsIfNeeded = [&]() -> bool {
auto reloadLogsIfNeeded = [&](bool force = false) -> bool {
bool cChanged = contactsStamp.checkAndUpdate(getContactsFilePath());
bool lChanged = logStamp.checkAndUpdate(getModemLogFilePath());
if (cChanged || lChanged || !logsLoadedOnce) {
bool bChanged = blockFileStamp.checkAndUpdate(getBlockFilePath());
bool blChanged = blockLogStamp.checkAndUpdate(getBlockedModemLogFilePath());
if (force || cChanged || lChanged || bChanged || blChanged || !logsLoadedOnce) {
logsLoadedOnce = true;
book.load();
blockList.load();
allLogs = loadCallLog(book);
blockedLogs = loadBlockedCallLog(book);
applyFilter();
if (blockSelected >= static_cast<int>(blockList.entries().size())) {
blockSelected = std::max(0, static_cast<int>(blockList.entries().size()) - 1);
}
return true;
}
return false;
};
reloadLogsIfNeeded();
applyFilter();
reloadLogsIfNeeded(true);
auto buildOptions = [&]() {
options.clear();
bool hasSel = (!filtered.empty() && selected >= 0 &&
selected < static_cast<int>(filtered.size()));
if (hasSel) {
const CallLogItem& item = filtered[selected];
bool isBlk = blockList.isBlocked(item.number);
options.push_back({1, kIconPhone, "Call Number", false});
options.push_back({2, kIconPhoneLog, "Open in Dialer", false});
options.push_back({3, kIconSms, "Send SMS", false});
if (isBlk) {
options.push_back({4, kIconCheck, "Unblock Number", false});
} else {
options.push_back({4, kIconBan, "Block Number (Spam)", true});
}
options.push_back({5, kIconUser, "Contacts", false});
} else {
options.push_back({2, kIconPhoneLog, "Open Dialer", false});
}
std::string blkCount =
"Blocklist (" + std::to_string(blockList.entries().size()) + ")";
options.push_back({6, kIconShield, blkCount, false});
options.push_back({7, kIconPlus, "Block a Number...", false});
if (filterTab == 4) {
if (!blockedLogs.empty()) {
options.push_back({8, kIconTrash, "Clear Spam Log", true});
}
} else if (!allLogs.empty()) {
options.push_back({9, kIconTrash, "Clear Call Log", true});
}
optionSelected = 0;
};
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
@@ -191,8 +279,6 @@ int calllog_run_main(int argc, char** argv) {
constexpr int kListH = kWinHeight - kHeaderH - kSoftbarH;
constexpr int kVisibleRows = 5;
const char* kTabLabels[4] = {"All", "Missed", "In", "Out"};
auto render = [&]() {
XSetForeground(dpy, gc, theme.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kWinHeight);
@@ -200,108 +286,270 @@ int calllog_run_main(int argc, char** argv) {
XSetForeground(dpy, gc, theme.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kHeaderH);
for (int t = 0; t < 4; ++t) {
int tx = (t * kWinWidth) / 4;
int tw = ((t + 1) * kWinWidth) / 4 - tx;
bool active = (t == filterTab);
if (active) {
XSetForeground(dpy, gc, theme.spec.selBg);
XFillRectangle(dpy, pix, gc, tx, 0, tw, kHeaderH - 2);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, tx, kHeaderH - 3, tw, 3);
}
std::string lbl(kTabLabels[t]);
int lw = pangoWidth(layoutSmall, lbl);
drawPango(layoutSmall, active ? &colWhite : &colMuted,
tx + (tw - lw) / 2, 0, kHeaderH - 2, lbl);
}
std::string softLeft = "Options";
std::string softCenter = "CALL";
std::string softRight = "Close";
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
if (filtered.empty()) {
drawPango(layoutIcon, &colMuted, 112, kListY + 60, 24, kIconPhoneLog);
drawPango(layoutMain, &colMuted, 52, kListY + 90, 28, "No call history", 160);
drawPango(layoutSmall, &colMuted, 24, kListY + 120, 20,
"Press 0-9 or Left Softkey to dial", 200);
} else {
int total = static_cast<int>(filtered.size());
int scrollOffset = 0;
if (selected >= kVisibleRows) {
scrollOffset = selected - kVisibleRows + 1;
}
if (scrollOffset > std::max(0, total - kVisibleRows)) {
scrollOffset = std::max(0, total - kVisibleRows);
}
for (int i = 0; i < kVisibleRows; ++i) {
int idx = scrollOffset + i;
if (idx >= total) {
break;
if (mode == ViewMode::Log) {
for (int t = 0; t < kNumTabs; ++t) {
int tx = (t * kWinWidth) / kNumTabs;
int tw = ((t + 1) * kWinWidth) / kNumTabs - tx;
bool active = (t == filterTab);
if (active) {
XSetForeground(dpy, gc, theme.spec.selBg);
XFillRectangle(dpy, pix, gc, tx, 0, tw, kHeaderH - 2);
XSetForeground(dpy, gc, (t == 4) ? theme.spec.danger : theme.spec.accent);
XFillRectangle(dpy, pix, gc, tx, kHeaderH - 3, tw, 3);
}
int ry = kListY + (i * kListH) / kVisibleRows;
int nextRy = kListY + ((i + 1) * kListH) / kVisibleRows;
int rowH = nextRy - ry;
bool isSel = (idx == selected);
std::string lbl(kTabLabels[t]);
int lw = pangoWidth(layoutSmall, lbl);
XftColor* tabCol = active ? ((t == 4) ? &colRed : &colWhite) : &colMuted;
drawPango(layoutSmall, tabCol, tx + (tw - lw) / 2, 0, kHeaderH - 2, lbl);
}
XSetForeground(dpy, gc,
isSel ? theme.spec.selBg : ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
if (filtered.empty()) {
drawPango(layoutIcon, &colMuted, 112, kListY + 54, 24,
(filterTab == 4) ? kIconShield : kIconPhoneLog);
std::string emptyTitle =
(filterTab == 4) ? "No blocked calls" : "No call history";
int etw = pangoWidth(layoutMain, emptyTitle);
drawPango(layoutMain, &colMuted, std::max(8, (kWinWidth - etw) / 2),
kListY + 84, 26, emptyTitle, 224);
std::string emptySub =
(filterTab == 4)
? ("Blocklist: " + std::to_string(blockList.entries().size()) +
" number(s)")
: "Press 0-9 to dial or Options";
int esw = pangoWidth(layoutSmall, emptySub);
drawPango(layoutSmall, &colMuted, std::max(8, (kWinWidth - esw) / 2),
kListY + 114, 20, emptySub, 224);
} else {
int total = static_cast<int>(filtered.size());
int scrollOffset = 0;
if (selected >= kVisibleRows) {
scrollOffset = selected - kVisibleRows + 1;
}
if (scrollOffset > std::max(0, total - kVisibleRows)) {
scrollOffset = std::max(0, total - kVisibleRows);
}
for (int i = 0; i < kVisibleRows; ++i) {
int idx = scrollOffset + i;
if (idx >= total) {
break;
}
int ry = kListY + (i * kListH) / kVisibleRows;
int nextRy = kListY + ((i + 1) * kListH) / kVisibleRows;
int rowH = nextRy - ry;
bool isSel = (idx == selected);
XSetForeground(
dpy, gc,
isSel ? theme.spec.selBg
: ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
if (isSel) {
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
}
const CallLogItem& item = filtered[idx];
const char* dirIcon = kIconInCall;
XftColor* dirCol = &colGreen;
const char* dirName = "In";
if (item.direction == CallDirection::Blocked) {
dirIcon = kIconBan;
dirCol = &colRed;
dirName = "Blocked";
} else if (item.direction == CallDirection::Outgoing) {
dirIcon = kIconOutCall;
dirCol = &colBlue;
dirName = "Out";
} else if (item.direction == CallDirection::Missed) {
dirIcon = kIconMissedCall;
dirCol = &colRed;
dirName = "Missed";
}
drawPango(layoutIcon, dirCol, 8, ry, rowH, dirIcon);
std::string rightBadge = formatDuration(item.durationSec);
XftColor* badgeCol = isSel ? &colYellow : &colGreen;
if (item.isBlockedNumber) {
rightBadge = "BLK";
badgeCol = &colRed;
}
int durW = 0;
if (!rightBadge.empty()) {
durW = pangoWidth(layoutSmall, rightBadge);
drawPango(layoutSmall, badgeCol, kWinWidth - durW - 6, ry + 3, 22,
rightBadge);
}
std::string primary =
item.contactName.empty() ? item.number : item.contactName;
XftColor* priCol =
((item.direction == CallDirection::Missed ||
item.direction == CallDirection::Blocked ||
item.isBlockedNumber) &&
!isSel)
? &colRed
: (isSel ? &colWhite : &colLight);
int priMaxW = (durW > 0) ? (kWinWidth - 36 - durW - 6) : 200;
drawPango(layoutMain, priCol, 30, ry + 3, 22, primary, priMaxW);
int timeW = pangoWidth(layoutSmall, item.displayTime);
drawPango(layoutSmall, isSel ? &colWhite : &colMuted,
kWinWidth - timeW - 6, ry + 24, 19, item.displayTime);
std::string secondary =
!item.contactName.empty() ? item.number : std::string(dirName);
int secMaxW = std::max(60, kWinWidth - 36 - timeW - 8);
drawPango(layoutSmall, isSel ? &colYellow : &colMuted, 30, ry + 24,
19, secondary, secMaxW);
}
if (total > kVisibleRows) {
int sbH = std::max(16, (kListH * kVisibleRows) / total);
int sbY = kListY +
((kListH - sbH) * scrollOffset) / (total - kVisibleRows);
XSetForeground(dpy, gc, theme.spec.divider);
XFillRectangle(dpy, pix, gc, kWinWidth - 3, sbY, 3, sbH);
}
}
} else if (mode == ViewMode::Options) {
drawPango(layoutIcon, &colYellow, 8, 0, kHeaderH, kIconList);
drawPango(layoutMain, &colWhite, 28, 0, kHeaderH, "Call Log Options", 200);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
constexpr int kOptVis = 6;
int total = static_cast<int>(options.size());
int scrollOffset = 0;
if (optionSelected >= kOptVis) {
scrollOffset = optionSelected - kOptVis + 1;
}
int rowH = kListH / kOptVis;
for (int i = 0; i < kOptVis; ++i) {
int idx = scrollOffset + i;
if (idx >= total) break;
int ry = kListY + i * rowH;
bool isSel = (idx == optionSelected);
XSetForeground(
dpy, gc,
isSel ? theme.spec.selBg
: ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
if (isSel) {
XSetForeground(dpy, gc, theme.spec.accent);
XSetForeground(dpy, gc,
options[idx].danger ? theme.spec.danger : theme.spec.accent);
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
}
const CallLogItem& item = filtered[idx];
const char* dirIcon = kIconInCall;
XftColor* dirCol = &colGreen;
const char* dirName = "In";
if (item.direction == CallDirection::Outgoing) {
dirIcon = kIconOutCall;
dirCol = &colBlue;
dirName = "Out";
} else if (item.direction == CallDirection::Missed) {
dirIcon = kIconMissedCall;
dirCol = &colRed;
dirName = "Missed";
}
drawPango(layoutIcon, dirCol, 8, ry, rowH, dirIcon);
std::string dur = formatDuration(item.durationSec);
int durW = 0;
if (!dur.empty()) {
durW = pangoWidth(layoutSmall, dur);
drawPango(layoutSmall, isSel ? &colYellow : &colGreen,
kWinWidth - durW - 6, ry + 3, 22, dur);
}
std::string primary = item.contactName.empty() ? item.number : item.contactName;
XftColor* priCol = (item.direction == CallDirection::Missed && !isSel)
? &colRed
: (isSel ? &colWhite : &colLight);
int priMaxW = (durW > 0) ? (kWinWidth - 36 - durW - 6) : 200;
drawPango(layoutMain, priCol, 30, ry + 3, 22, primary, priMaxW);
int timeW = pangoWidth(layoutSmall, item.displayTime);
drawPango(layoutSmall, isSel ? &colWhite : &colMuted,
kWinWidth - timeW - 6, ry + 24, 19, item.displayTime);
std::string secondary =
!item.contactName.empty() ? item.number : std::string(dirName);
int secMaxW = std::max(60, kWinWidth - 36 - timeW - 8);
drawPango(layoutSmall, isSel ? &colYellow : &colMuted, 30, ry + 24, 19,
secondary, secMaxW);
XftColor* icCol = options[idx].danger
? &colRed
: (isSel ? &colYellow : &colBlue);
XftColor* txCol = options[idx].danger
? &colRed
: (isSel ? &colWhite : &colLight);
drawPango(layoutIcon, icCol, 10, ry, rowH, options[idx].icon);
drawPango(layoutMain, txCol, 34, ry, rowH, options[idx].label,
kWinWidth - 42);
}
softLeft = "Select";
softCenter = "OK";
softRight = "Back";
} else if (mode == ViewMode::Blocklist) {
drawPango(layoutIcon, &colRed, 8, 0, kHeaderH, kIconBan);
std::string hdr =
"Blocklist (" + std::to_string(blockList.entries().size()) + ")";
drawPango(layoutMain, &colWhite, 28, 0, kHeaderH, hdr, 204);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
if (total > kVisibleRows) {
int sbH = std::max(16, (kListH * kVisibleRows) / total);
int sbY = kListY +
((kListH - sbH) * scrollOffset) / (total - kVisibleRows);
XSetForeground(dpy, gc, theme.spec.divider);
XFillRectangle(dpy, pix, gc, kWinWidth - 3, sbY, 3, sbH);
const auto& entries = blockList.entries();
if (entries.empty()) {
drawPango(layoutIcon, &colMuted, 112, kListY + 54, 24, kIconShield);
drawPango(layoutMain, &colMuted, 44, kListY + 84, 26,
"Blocklist is empty", 180);
drawPango(layoutSmall, &colMuted, 22, kListY + 114, 20,
"Left Softkey: Block a Number", 204);
} else {
int total = static_cast<int>(entries.size());
int scrollOffset = 0;
if (blockSelected >= kVisibleRows) {
scrollOffset = blockSelected - kVisibleRows + 1;
}
for (int i = 0; i < kVisibleRows; ++i) {
int idx = scrollOffset + i;
if (idx >= total) break;
int ry = kListY + (i * kListH) / kVisibleRows;
int nextRy = kListY + ((i + 1) * kListH) / kVisibleRows;
int rowH = nextRy - ry;
bool isSel = (idx == blockSelected);
XSetForeground(
dpy, gc,
isSel ? theme.spec.selBg
: ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
if (isSel) {
XSetForeground(dpy, gc, theme.spec.danger);
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
}
const auto& e = entries[idx];
std::string cname = book.resolveName(e.number);
std::string topLine = cname.empty() ? e.number : cname;
std::string subLine =
cname.empty() ? e.label : (e.number + " (" + e.label + ")");
drawPango(layoutIcon, &colRed, 8, ry, rowH, kIconBan);
drawPango(layoutMain, isSel ? &colWhite : &colLight, 30, ry + 3, 22,
topLine, kWinWidth - 38);
drawPango(layoutSmall, isSel ? &colYellow : &colMuted, 30, ry + 24,
19, subLine, kWinWidth - 38);
}
}
softLeft = "Add New";
softCenter = entries.empty() ? "" : "Unblock";
softRight = "Back";
} else if (mode == ViewMode::AddBlock) {
drawPango(layoutIcon, &colRed, 8, 0, kHeaderH, kIconBan);
drawPango(layoutMain, &colWhite, 28, 0, kHeaderH, "Block Phone Number", 204);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
drawPango(layoutSmall, &colMuted, 12, kListY + 18, 20,
"Enter number or prefix (e.g. +1800*):", kWinWidth - 24);
XSetForeground(dpy, gc, theme.spec.bgAltOdd);
XFillRectangle(dpy, pix, gc, 12, kListY + 44, kWinWidth - 24, 34);
XSetForeground(dpy, gc, theme.spec.accent);
XDrawRectangle(dpy, pix, gc, 12, kListY + 44, kWinWidth - 25, 33);
std::string disp = addBlockInput + "_";
drawPango(layoutMain, &colWhite, 18, kListY + 47, 28, disp, kWinWidth - 36);
drawPango(layoutSmall, &colMuted, 12, kListY + 90, 20,
"0-9 / * / #: Digits #: + prefix", kWinWidth - 24);
drawPango(layoutSmall, &colMuted, 12, kListY + 112, 20,
"Left/Down: Backspace", kWinWidth - 24);
softLeft = "Block";
softCenter = "SAVE";
softRight = "Cancel";
}
if (!toastMsg.empty() && nowMs() < toastUntilMs) {
int tw = std::min(kWinWidth - 16, pangoWidth(layoutSmall, toastMsg) + 20);
int tx = (kWinWidth - tw) / 2;
int ty = kWinHeight - kSoftbarH - 28;
XSetForeground(dpy, gc, theme.spec.selBg);
XFillRectangle(dpy, pix, gc, tx, ty, tw, 24);
XSetForeground(dpy, gc, theme.spec.accent);
XDrawRectangle(dpy, pix, gc, tx, ty, tw - 1, 23);
int textW = pangoWidth(layoutSmall, toastMsg);
drawPango(layoutSmall, &colYellow, tx + (tw - textW) / 2, ty + 2, 20,
toastMsg, tw - 8);
}
int sbY = kWinHeight - kSoftbarH;
@@ -310,15 +558,21 @@ int calllog_run_main(int argc, char** argv) {
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, 1);
drawPango(layoutMain, &colLight, 6, sbY + 1, kSoftbarH - 1, "Dialer");
std::string centerLabel = "CALL";
int cw = pangoWidth(layoutMain, centerLabel);
drawPango(layoutMain, filtered.empty() ? &colMuted : &colGreen,
(kWinWidth - cw) / 2, sbY + 1, kSoftbarH - 1, centerLabel);
std::string rightLabel = "Close";
int rw = pangoWidth(layoutMain, rightLabel);
drawPango(layoutMain, &colLight, 6, sbY + 1, kSoftbarH - 1, softLeft);
if (!softCenter.empty()) {
int cw = pangoWidth(layoutMain, softCenter);
XftColor* cCol = &colGreen;
if (mode == ViewMode::Log && filtered.empty()) {
cCol = &colMuted;
} else if (mode == ViewMode::Blocklist) {
cCol = &colRed;
}
drawPango(layoutMain, cCol, (kWinWidth - cw) / 2, sbY + 1, kSoftbarH - 1,
softCenter);
}
int rw = pangoWidth(layoutMain, softRight);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, sbY + 1,
kSoftbarH - 1, rightLabel);
kSoftbarH - 1, softRight);
if (visible) {
XCopyArea(dpy, pix, win, gc, 0, 0, kWinWidth, kWinHeight, 0, 0);
@@ -326,9 +580,124 @@ int calllog_run_main(int argc, char** argv) {
}
};
auto executeOption = [&](int optId) {
bool hasSel = (!filtered.empty() && selected >= 0 &&
selected < static_cast<int>(filtered.size()));
std::string selNum = hasSel ? filtered[selected].number : "";
std::string selName = hasSel ? filtered[selected].contactName : "";
switch (optId) {
case 1: { // Call Number
if (!selNum.empty()) {
mode = ViewMode::Log;
writeSoftkeySuppress(nowMs() + 350);
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
::unlink(activePidPath.c_str());
visible = false;
placePhoneCall(selNum);
}
break;
}
case 2: { // Open in Dialer
mode = ViewMode::Log;
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
::unlink(activePidPath.c_str());
visible = false;
if (!sendPluginCommand("dialer",
selNum.empty() ? "OPEN" : ("OPEN " + selNum))) {
if (selNum.empty()) {
runAsyncArgv("xdialer");
} else {
runAsyncArgv("xdialer", selNum.c_str());
}
}
break;
}
case 3: { // Send SMS
if (!selNum.empty()) {
mode = ViewMode::Log;
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
::unlink(activePidPath.c_str());
visible = false;
if (!sendPluginCommand("sms", "OPEN " + selNum)) {
runAsyncArgv("xsms", selNum.c_str());
}
}
break;
}
case 4: { // Block / Unblock Number
if (!selNum.empty()) {
if (blockList.isBlocked(selNum)) {
blockList.unblockNumber(selNum);
showToast("Unblocked " + selNum);
} else {
blockList.blockNumber(selNum, selName.empty() ? "Call Log" : selName);
showToast("Blocked " + selNum);
}
reloadLogsIfNeeded(true);
}
mode = ViewMode::Log;
render();
break;
}
case 5: { // Contacts
mode = ViewMode::Log;
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XFlush(dpy);
::unlink(activePidPath.c_str());
visible = false;
if (!sendPluginCommand("contacts", "OPEN")) {
runAsyncArgv("xcontacts");
}
break;
}
case 6: { // Manage Blocklist
blockList.load();
blockSelected = 0;
mode = ViewMode::Blocklist;
render();
break;
}
case 7: { // Block a Number...
addBlockInput = selNum;
mode = ViewMode::AddBlock;
render();
break;
}
case 8: { // Clear Spam Log
clearCallLogFile(getBlockedModemLogFilePath());
reloadLogsIfNeeded(true);
showToast("Cleared blocked call log");
mode = ViewMode::Log;
render();
break;
}
case 9: { // Clear Call Log
clearCallLogFile(getModemLogFilePath());
reloadLogsIfNeeded(true);
showToast("Cleared call history");
mode = ViewMode::Log;
render();
break;
}
default:
mode = ViewMode::Log;
render();
break;
}
};
// Pre-warm Pango/FreeType/Xrender glyph caches into offscreen Pixmap at startup
drawPango(layoutIcon, &colGreen, 0, 0, 20,
std::string(kIconInCall) + kIconOutCall + kIconMissedCall + kIconPhoneLog);
std::string(kIconInCall) + kIconOutCall + kIconMissedCall +
kIconPhoneLog + kIconBan + kIconShield);
render();
XSync(dpy, False);
@@ -344,6 +713,7 @@ int calllog_run_main(int argc, char** argv) {
initialSoftkeysReleased = (querySoftkeysDown(dpy) == 0);
softkeyPending = 0;
softkeyDeadlineMs = 0;
mode = ViewMode::Log;
visible = true;
XMapRaised(dpy, win);
if (!themeChanged) {
@@ -392,7 +762,8 @@ int calllog_run_main(int argc, char** argv) {
visible = false;
softkeyPending = 0;
softkeyDeadlineMs = 0;
if (filterTab != 0 || selected != 0) {
if (mode != ViewMode::Log || filterTab != 0 || selected != 0) {
mode = ViewMode::Log;
filterTab = 0;
selected = 0;
applyFilter();
@@ -422,6 +793,11 @@ int calllog_run_main(int argc, char** argv) {
}
}
if (visible && !toastMsg.empty() && nowMs() >= toastUntilMs) {
toastMsg.clear();
render();
}
if (visible && !initialSoftkeysReleased && querySoftkeysDown(dpy) == 0) {
initialSoftkeysReleased = true;
}
@@ -485,6 +861,128 @@ int calllog_run_main(int argc, char** argv) {
continue;
}
if (mode == ViewMode::AddBlock) {
char dialCh = mapDialKey(sym, ev.xkey.keycode, ev.xkey.state);
if (dialCh == '#') {
if (addBlockInput.empty()) {
addBlockInput.push_back('+');
} else {
addBlockInput.push_back('#');
}
render();
continue;
} else if (dialCh != '\0') {
addBlockInput.push_back(dialCh);
render();
continue;
}
if (sym == XK_BackSpace || sym == XK_Left || sym == XK_Down) {
if (!addBlockInput.empty()) {
addBlockInput.pop_back();
render();
}
continue;
} else if (sym == XK_Escape) {
mode = ViewMode::Blocklist;
render();
continue;
} else if (sym == XK_Return || sym == XK_KP_Enter) {
std::string num = trimStr(addBlockInput);
if (!normalizePhone(num).empty()) {
blockList.blockNumber(num, "Manual");
reloadLogsIfNeeded(true);
showToast("Blocked " + num);
}
mode = ViewMode::Blocklist;
render();
continue;
}
continue;
}
if (mode == ViewMode::Options) {
switch (sym) {
case XK_Escape:
case XK_BackSpace:
case XK_Left:
mode = ViewMode::Log;
render();
break;
case XK_Up:
case XK_KP_Up:
case XK_k:
if (!options.empty()) {
optionSelected =
(optionSelected + static_cast<int>(options.size()) - 1) %
static_cast<int>(options.size());
render();
}
break;
case XK_Down:
case XK_KP_Down:
case XK_j:
if (!options.empty()) {
optionSelected =
(optionSelected + 1) % static_cast<int>(options.size());
render();
}
break;
case XK_Return:
case XK_KP_Enter:
if (!options.empty() && optionSelected >= 0 &&
optionSelected < static_cast<int>(options.size())) {
executeOption(options[optionSelected].id);
}
break;
default:
break;
}
continue;
}
if (mode == ViewMode::Blocklist) {
switch (sym) {
case XK_Escape:
case XK_BackSpace:
case XK_Left:
mode = ViewMode::Log;
render();
break;
case XK_Up:
case XK_KP_Up:
case XK_k:
if (!blockList.entries().empty()) {
int n = static_cast<int>(blockList.entries().size());
blockSelected = (blockSelected + n - 1) % n;
render();
}
break;
case XK_Down:
case XK_KP_Down:
case XK_j:
if (!blockList.entries().empty()) {
int n = static_cast<int>(blockList.entries().size());
blockSelected = (blockSelected + 1) % n;
render();
}
break;
case XK_Return:
case XK_KP_Enter:
if (!blockList.entries().empty() && blockSelected >= 0 &&
blockSelected < static_cast<int>(blockList.entries().size())) {
std::string num = blockList.entries()[blockSelected].number;
blockList.unblockNumber(num);
reloadLogsIfNeeded(true);
showToast("Unblocked " + num);
render();
}
break;
default:
break;
}
continue;
}
char dialCh = mapDialKey(sym, ev.xkey.keycode, ev.xkey.state);
if (dialCh != '\0') {
std::string arg(1, dialCh);
@@ -505,7 +1003,7 @@ int calllog_run_main(int argc, char** argv) {
case XK_Left:
case XK_KP_Left:
case XK_h:
filterTab = (filterTab + 3) % 4;
filterTab = (filterTab + kNumTabs - 1) % kNumTabs;
selected = 0;
applyFilter();
render();
@@ -513,7 +1011,7 @@ int calllog_run_main(int argc, char** argv) {
case XK_Right:
case XK_KP_Right:
case XK_l:
filterTab = (filterTab + 1) % 4;
filterTab = (filterTab + 1) % kNumTabs;
selected = 0;
applyFilter();
render();
@@ -549,9 +1047,16 @@ int calllog_run_main(int argc, char** argv) {
hideWindow(true);
placePhoneCall(num);
} else if (filtered.empty()) {
hideWindow(false);
if (!sendPluginCommand("dialer", "OPEN")) {
runAsyncArgv("xdialer");
if (filterTab == 4) {
blockList.load();
blockSelected = 0;
mode = ViewMode::Blocklist;
render();
} else {
hideWindow(false);
if (!sendPluginCommand("dialer", "OPEN")) {
runAsyncArgv("xdialer");
}
}
}
break;
@@ -572,22 +1077,40 @@ int calllog_run_main(int argc, char** argv) {
runAsyncArgv("xdrawer");
}
} else if (comb == 1) {
std::string arg;
if (!filtered.empty() && selected >= 0 &&
selected < static_cast<int>(filtered.size())) {
arg = filtered[selected].number;
}
hideWindow(false);
if (!sendPluginCommand("dialer", arg.empty() ? "OPEN" : ("OPEN " + arg))) {
if (arg.empty()) {
runAsyncArgv("xdialer");
} else {
runAsyncArgv("xdialer", arg.c_str());
if (mode == ViewMode::Log) {
buildOptions();
mode = ViewMode::Options;
render();
} else if (mode == ViewMode::Options) {
if (!options.empty() && optionSelected >= 0 &&
optionSelected < static_cast<int>(options.size())) {
executeOption(options[optionSelected].id);
}
} else if (mode == ViewMode::Blocklist) {
addBlockInput.clear();
mode = ViewMode::AddBlock;
render();
} else if (mode == ViewMode::AddBlock) {
std::string num = trimStr(addBlockInput);
if (!normalizePhone(num).empty()) {
blockList.blockNumber(num, "Manual");
reloadLogsIfNeeded(true);
showToast("Blocked " + num);
}
mode = ViewMode::Blocklist;
render();
}
} else if (comb == 2) {
writeSoftkeySuppress(nowMs() + 350);
hideWindow(true);
if (mode == ViewMode::AddBlock) {
mode = ViewMode::Blocklist;
render();
} else if (mode == ViewMode::Options || mode == ViewMode::Blocklist) {
mode = ViewMode::Log;
render();
} else {
writeSoftkeySuppress(nowMs() + 350);
hideWindow(true);
}
}
}
@@ -653,46 +1176,24 @@ int calllog_on_global_key(const DwmHostApi* host, KeySym keysym,
}
return 1;
}
}
return 0;
}
int calllog_on_idle_key(const DwmHostApi* host, KeySym keysym,
unsigned int keycode, unsigned int state) {
if (!host || !host->is_idle_desktop || !host->is_idle_desktop() || state != 0) {
return 0;
}
if (keysym == XF86XK_Phone || keysym == XF86XK_PickupPhone || keycode == 177) {
if (isCallRingingFast()) {
if (!sendPluginCommand("callscreen", "ACCEPT")) {
runAsyncArgv("xcallscreen", "accept");
}
return 1;
}
if (isCallActiveOrRingingFast()) {
if (!sendPluginCommand("callscreen", "OPEN")) {
runAsyncArgv("xcallscreen");
}
return 1;
}
if (host->spawn_plugin) {
host->spawn_plugin("calllog", nullptr);
if (!sendPluginCommand("calllog", "OPEN")) {
runAsyncArgv("xcalllog");
}
return 1;
}
return 0;
}
} // namespace
} // namespace
extern "C" __attribute__((visibility("default"))) const DwmPlugin dwm_plugin_entry = {
DWM_PLUGIN_API_VERSION,
"calllog",
"Keypad-driven call log viewer & dialer launcher (opens on idle Call key)",
"Preloaded resident X11 call log viewer, anti-spam blocklist & dialer launcher",
calllog_plugin_init,
nullptr,
nullptr,
calllog_on_idle_key,
nullptr,
calllog_on_global_key,
calllog_run_main
};
+13
View File
@@ -118,6 +118,10 @@ bool isMediaExt(const std::string& ext) {
ext == "avi";
}
bool isGameBoyExt(const std::string& ext) {
return ext == "gb" || ext == "gbc";
}
bool isLikelyTextFile(const std::string& path, off_t size) {
if (size == 0) return true;
if (size > 256 * 1024) return false;
@@ -612,6 +616,8 @@ int runFilesApp(int argc, char** argv) {
} else if (isAudioExt(ext)) {
actionsList.push_back({1, kIconMusic, "Play in Music Player"});
actionsList.push_back({15, kIconBell, "Set as Ringtone"});
} else if (isGameBoyExt(ext)) {
actionsList.push_back({1, kIconGamepad, "Play in Game Boy Emulator"});
} else {
actionsList.push_back({1, kIconEye, "Open / View"});
}
@@ -689,6 +695,10 @@ int runFilesApp(int argc, char** argv) {
} else if (isAudioExt(ext)) {
openInMusicPlayer(item.fullPath);
return;
} else if (isGameBoyExt(ext)) {
hideWindow();
runAsyncArgv("gambatte", item.fullPath.c_str());
return;
} else if (isMediaExt(ext)) {
hideWindow();
runAsyncArgv("sxmo_open.sh", item.fullPath.c_str());
@@ -832,6 +842,9 @@ int runFilesApp(int argc, char** argv) {
} else if (isMediaExt(ext)) {
ic = kIconMusic;
icCol = &colBlue;
} else if (isGameBoyExt(ext)) {
ic = kIconGamepad;
icCol = &colYellow;
} else if (it.isExec || ext == "sh") {
ic = kIconTerm;
icCol = &colOrange;
+351 -17
View File
@@ -93,6 +93,9 @@ constexpr const char* kIconToggleOff = "\xef\x88\x84"; // U+F204 toggle off
constexpr const char* kIconKey = "\xef\x82\x84"; // U+F084 key / PIN
constexpr const char* kIconSim = "\xf3\xb0\x99\x95"; // U+F0655 nf-md-sim
constexpr const char* kIconBell = "\xef\x83\xb3"; // U+F0F3 bell / ringtone
constexpr const char* kIconBan = "\xef\x81\x9e"; // U+F05E ban / block
constexpr const char* kIconShield = "\xef\x84\xb2"; // U+F132 shield / anti-spam
constexpr const char* kIconGamepad = "\xef\x84\x9b"; // U+F11B gamepad / emulator
inline int64_t nowMs() {
struct timespec ts {};
@@ -947,10 +950,247 @@ class ContactBook {
std::unordered_map<std::string, std::string> suffixMap_;
};
inline std::string getBlockFilePath() {
const char* env = std::getenv("SXMO_BLOCKFILE");
if (env && env[0]) {
return env;
}
const char* xdg = std::getenv("XDG_CONFIG_HOME");
if (xdg && xdg[0]) {
return std::string(xdg) + "/sxmo/block.tsv";
}
const char* home = std::getenv("HOME");
return std::string(home && home[0] ? home : "/home/user") +
"/.config/sxmo/block.tsv";
}
inline std::string getBlockDirPath() {
const char* env = std::getenv("SXMO_BLOCKDIR");
if (env && env[0]) {
return env;
}
const char* xdg = std::getenv("XDG_DATA_HOME");
if (xdg && xdg[0]) {
return std::string(xdg) + "/sxmo/block";
}
const char* home = std::getenv("HOME");
return std::string(home && home[0] ? home : "/home/user") +
"/.local/share/sxmo/block";
}
inline std::string getBlockedModemLogFilePath() {
return getBlockDirPath() + "/modemlog.tsv";
}
struct BlockEntry {
std::string number;
std::string normNumber;
std::string label;
};
class BlockList {
public:
void load() {
entries_.clear();
exactSet_.clear();
suffixSet_.clear();
std::ifstream bf(getBlockFilePath());
std::string line;
while (std::getline(bf, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (line.empty()) {
continue;
}
size_t tab = line.find('\t');
std::string num = trimStr(tab == std::string::npos ? line : line.substr(0, tab));
std::string lbl = tab == std::string::npos ? "" : trimStr(line.substr(tab + 1));
std::string norm = normalizePhone(num);
if (norm.empty()) {
continue;
}
BlockEntry e;
e.number = num;
e.normNumber = norm;
e.label = lbl.empty() ? "Blocked" : lbl;
entries_.push_back(e);
exactSet_.insert(norm);
std::string sfx = phoneSuffixKey(norm);
if (sfx.size() >= 7) {
suffixSet_.insert(sfx);
}
}
}
bool isBlocked(const std::string& rawNumber) const {
std::string norm = normalizePhone(rawNumber);
if (norm.empty()) {
return false;
}
if (exactSet_.count(norm) > 0) {
return true;
}
std::string sfx = phoneSuffixKey(norm);
if (sfx.size() >= 7 && suffixSet_.count(sfx) > 0) {
return true;
}
for (const auto& e : entries_) {
if (!e.normNumber.empty() && e.normNumber.back() == '*' &&
e.normNumber.size() > 1) {
std::string prefix = e.normNumber.substr(0, e.normNumber.size() - 1);
if (norm.rfind(prefix, 0) == 0) {
return true;
}
}
}
return false;
}
bool blockNumber(const std::string& rawNumber,
const std::string& labelRaw = "") {
std::string num = trimStr(rawNumber);
std::string norm = normalizePhone(num);
if (norm.empty()) {
return false;
}
if (num.find('\t') != std::string::npos ||
num.find('\n') != std::string::npos) {
num = norm;
}
std::string label = trimStr(labelRaw);
for (char& ch : label) {
if (ch == '\t' || ch == '\r' || ch == '\n') {
ch = ' ';
}
}
if (label.empty()) {
label = "Blocked";
}
std::string path = getBlockFilePath();
ContactBook::ensureParentDir(path);
std::vector<std::pair<std::string, std::string>> rows;
{
std::ifstream in(path);
std::string line;
while (std::getline(in, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (line.empty()) continue;
size_t tab = line.find('\t');
std::string rNum = trimStr(tab == std::string::npos ? line : line.substr(0, tab));
std::string rLbl = tab == std::string::npos ? "Blocked" : trimStr(line.substr(tab + 1));
if (!normalizePhone(rNum).empty()) {
rows.push_back({rNum, rLbl.empty() ? "Blocked" : rLbl});
}
}
}
std::string sfx = phoneSuffixKey(norm);
bool updated = false;
for (auto& r : rows) {
std::string rNorm = normalizePhone(r.first);
std::string rSfx = phoneSuffixKey(rNorm);
if (rNorm == norm || (sfx.size() >= 7 && rSfx == sfx)) {
r.first = num;
if (!labelRaw.empty()) {
r.second = label;
}
updated = true;
break;
}
}
if (!updated) {
rows.push_back({num, label});
}
std::ofstream out(path, std::ios::trunc);
if (!out.is_open()) {
return false;
}
for (const auto& r : rows) {
out << r.first << "\t" << r.second << "\n";
}
out.close();
load();
return true;
}
bool unblockNumber(const std::string& rawNumber) {
std::string norm = normalizePhone(rawNumber);
if (norm.empty()) {
return false;
}
std::string sfx = phoneSuffixKey(norm);
std::string path = getBlockFilePath();
std::vector<std::pair<std::string, std::string>> rows;
bool removed = false;
{
std::ifstream in(path);
std::string line;
while (std::getline(in, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (line.empty()) continue;
size_t tab = line.find('\t');
std::string rNum = trimStr(tab == std::string::npos ? line : line.substr(0, tab));
std::string rLbl = tab == std::string::npos ? "Blocked" : trimStr(line.substr(tab + 1));
std::string rNorm = normalizePhone(rNum);
if (rNorm.empty()) continue;
std::string rSfx = phoneSuffixKey(rNorm);
if (rNorm == norm || (sfx.size() >= 7 && rSfx == sfx)) {
removed = true;
continue;
}
rows.push_back({rNum, rLbl.empty() ? "Blocked" : rLbl});
}
}
if (!removed) {
return false;
}
ContactBook::ensureParentDir(path);
std::ofstream out(path, std::ios::trunc);
if (!out.is_open()) {
return false;
}
for (const auto& r : rows) {
out << r.first << "\t" << r.second << "\n";
}
out.close();
load();
return true;
}
bool clearAll() {
std::string path = getBlockFilePath();
ContactBook::ensureParentDir(path);
std::ofstream out(path, std::ios::trunc);
if (!out.is_open()) {
return false;
}
out.close();
load();
return true;
}
const std::vector<BlockEntry>& entries() const { return entries_; }
private:
std::vector<BlockEntry> entries_;
std::unordered_set<std::string> exactSet_;
std::unordered_set<std::string> suffixSet_;
};
enum class CallDirection {
Incoming = 0,
Outgoing = 1,
Missed = 2,
Blocked = 3,
};
struct CallLogItem {
@@ -959,6 +1199,7 @@ struct CallLogItem {
std::string contactName;
std::string displayTime;
int durationSec = 0;
bool isBlockedNumber = false;
};
inline time_t parseIsoTime(const std::string& iso) {
@@ -999,8 +1240,10 @@ inline std::string formatDuration(int sec) {
return buf;
}
inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
std::ifstream lf(getModemLogFilePath());
inline std::vector<CallLogItem> loadCallLogFromFile(const ContactBook& book,
const std::string& logPath,
bool forceBlockedDir = false) {
std::ifstream lf(logPath);
std::string line;
struct ActiveSession {
@@ -1022,7 +1265,7 @@ inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
return;
}
CallLogItem item;
item.direction = cur.dir;
item.direction = forceBlockedDir ? CallDirection::Blocked : cur.dir;
item.number = cur.number;
item.contactName = book.resolveName(cur.number);
item.displayTime = formatShortTime(cur.startTimeStr);
@@ -1053,10 +1296,24 @@ inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
time_t epoch = parseIsoTime(ts);
if (evt == "call_ring") {
if (evt == "call_blocked") {
if (cur.active && normalizePhone(cur.number) == normalizePhone(num)) {
cur.dir = CallDirection::Blocked;
flushSession();
} else {
flushSession();
CallLogItem item;
item.direction = CallDirection::Blocked;
item.number = num;
item.contactName = book.resolveName(num);
item.displayTime = formatShortTime(ts);
item.durationSec = 0;
history.push_back(item);
}
} else if (evt == "call_ring") {
flushSession();
cur.active = true;
cur.dir = CallDirection::Missed;
cur.dir = forceBlockedDir ? CallDirection::Blocked : CallDirection::Missed;
cur.number = num;
cur.startTimeStr = ts;
cur.startEpoch = epoch;
@@ -1088,12 +1345,12 @@ inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
}
} else if (evt == "call_missed") {
if (cur.active && normalizePhone(cur.number) == normalizePhone(num)) {
cur.dir = CallDirection::Missed;
cur.dir = forceBlockedDir ? CallDirection::Blocked : CallDirection::Missed;
flushSession();
} else {
flushSession();
CallLogItem item;
item.direction = CallDirection::Missed;
item.direction = forceBlockedDir ? CallDirection::Blocked : CallDirection::Missed;
item.number = num;
item.contactName = book.resolveName(num);
item.displayTime = formatShortTime(ts);
@@ -1105,10 +1362,10 @@ inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
if (cur.active && normalizePhone(cur.number) == normalizePhone(num)) {
if (evt == "call_discard" && !cur.answered &&
cur.dir != CallDirection::Outgoing) {
cur.dir = CallDirection::Missed;
cur.dir = forceBlockedDir ? CallDirection::Blocked : CallDirection::Missed;
}
CallLogItem item;
item.direction = cur.dir;
item.direction = forceBlockedDir ? CallDirection::Blocked : cur.dir;
item.number = cur.number;
item.contactName = book.resolveName(cur.number);
item.displayTime = formatShortTime(cur.startTimeStr);
@@ -1126,6 +1383,44 @@ inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
return history;
}
inline std::vector<CallLogItem> loadCallLog(const ContactBook& book) {
return loadCallLogFromFile(book, getModemLogFilePath(), false);
}
inline std::vector<CallLogItem> loadBlockedCallLog(const ContactBook& book) {
return loadCallLogFromFile(book, getBlockedModemLogFilePath(), true);
}
inline bool clearCallLogFile(const std::string& logPath) {
std::ifstream in(logPath);
if (!in.is_open()) {
return true;
}
std::vector<std::string> keep;
std::string line;
while (std::getline(in, line)) {
if (line.empty()) continue;
size_t t1 = line.find('\t');
if (t1 == std::string::npos) continue;
size_t t2 = line.find('\t', t1 + 1);
if (t2 == std::string::npos) continue;
std::string evt = trimStr(line.substr(t1 + 1, t2 - t1 - 1));
if (evt.rfind("call_", 0) == 0 || evt == "ring_muted") {
continue;
}
keep.push_back(line);
}
in.close();
std::ofstream out(logPath, std::ios::trunc);
if (!out.is_open()) {
return false;
}
for (const auto& l : keep) {
out << l << "\n";
}
return true;
}
inline void placePhoneCall(const std::string& rawNumber) {
std::string num = normalizePhone(rawNumber);
if (num.empty()) {
@@ -1285,6 +1580,7 @@ struct SmsThread {
time_t lastEpoch = 0;
bool lastIncoming = true;
bool hasDraft = false;
bool isBlocked = false;
int messageCount = 0;
};
@@ -1319,9 +1615,12 @@ inline bool parseSmsHeaderLine(const std::string& line,
return false;
}
inline std::vector<SmsMessage> loadSmsThreadMessages(const std::string& number) {
inline std::vector<SmsMessage> loadSmsThreadMessages(
const std::string& number,
const std::string& customBaseDir = "") {
std::vector<SmsMessage> msgs;
std::string path = getModemLogDirPath() + "/" + number + "/sms.txt";
std::string baseDir = customBaseDir.empty() ? getModemLogDirPath() : customBaseDir;
std::string path = baseDir + "/" + number + "/sms.txt";
std::ifstream in(path);
if (!in.is_open()) {
return msgs;
@@ -1424,11 +1723,13 @@ inline void removeSmsDraft(const std::string& number) {
::unlink(path.c_str());
}
inline bool deleteSmsThread(const std::string& number) {
inline bool deleteSmsThread(const std::string& number,
const std::string& customBaseDir = "") {
if (number.empty()) {
return false;
}
std::string dir = getModemLogDirPath() + "/" + number;
std::string baseDir = customBaseDir.empty() ? getModemLogDirPath() : customBaseDir;
std::string dir = baseDir + "/" + number;
std::string smsPath = dir + "/sms.txt";
std::string draftPath = dir + "/draft.txt";
::unlink(smsPath.c_str());
@@ -1437,9 +1738,42 @@ inline bool deleteSmsThread(const std::string& number) {
return true;
}
inline std::vector<SmsThread> loadSmsThreads(const ContactBook& book) {
inline bool moveSmsThreadBetweenDirs(const std::string& number,
const std::string& fromBaseDir,
const std::string& toBaseDir) {
if (number.empty()) {
return false;
}
std::string srcPath = fromBaseDir + "/" + number + "/sms.txt";
std::ifstream in(srcPath);
if (!in.is_open()) {
return false;
}
std::ostringstream ss;
ss << in.rdbuf();
in.close();
std::string content = ss.str();
if (content.empty()) {
return false;
}
std::string dstPath = toBaseDir + "/" + number + "/sms.txt";
ContactBook::ensureParentDir(dstPath);
std::ofstream out(dstPath, std::ios::app);
if (!out.is_open()) {
return false;
}
out << content;
out.close();
deleteSmsThread(number, fromBaseDir);
return true;
}
inline std::vector<SmsThread> loadSmsThreads(
const ContactBook& book,
const std::string& customBaseDir = "") {
std::vector<SmsThread> threads;
std::string baseDir = getModemLogDirPath();
bool isSpamDir = !customBaseDir.empty();
std::string baseDir = isSpamDir ? customBaseDir : getModemLogDirPath();
DIR* d = ::opendir(baseDir.c_str());
if (!d) {
return threads;
@@ -1459,13 +1793,13 @@ inline std::vector<SmsThread> loadSmsThreads(const ContactBook& book) {
std::string smsPath = subDir + "/sms.txt";
std::string draftPath = subDir + "/draft.txt";
bool hasSms = (::access(smsPath.c_str(), R_OK) == 0);
std::string draft = loadSmsDraft(name);
std::string draft = isSpamDir ? "" : loadSmsDraft(name);
bool hasDraft = !draft.empty();
if (!hasSms && !hasDraft) {
continue;
}
auto msgs = loadSmsThreadMessages(name);
auto msgs = loadSmsThreadMessages(name, baseDir);
if (msgs.empty() && !hasDraft) {
continue;
}
+315 -36
View File
@@ -28,6 +28,8 @@ enum class ViewMode {
PickContact = 3,
Options = 4,
ConfirmDelete = 5,
Blocklist = 6,
AddBlock = 7,
};
enum class TextCaseMode {
@@ -171,6 +173,9 @@ int runSmsApp(int argc, char** argv) {
auto& colRed = pt.colRed;
ContactBook book;
BlockList blockList;
std::vector<SmsThread> inboxThreads;
std::vector<SmsThread> spamThreads;
std::vector<SmsThread> allThreads;
std::vector<SmsThread> filteredThreads;
std::vector<SmsMessage> threadMessages;
@@ -178,7 +183,10 @@ int runSmsApp(int argc, char** argv) {
FileStamp contactsStamp;
FileStamp modemLogStamp;
FileStamp blockFileStamp;
FileStamp blockLogStamp;
bool loadedOnce = false;
bool viewingSpamFolder = false;
ViewMode mode = ViewMode::Threads;
ViewMode prevMode = ViewMode::Threads;
@@ -188,6 +196,8 @@ int runSmsApp(int argc, char** argv) {
int selectedOption = 0;
int selectedPicker = 0;
int confirmSelected = 0;
int blockSelected = 0;
std::string addBlockInput;
std::string activeNumber;
std::string composeRecipient;
@@ -216,10 +226,15 @@ int runSmsApp(int argc, char** argv) {
int id;
std::string icon;
std::string label;
bool danger = false;
};
std::vector<OptionEntry> optionsList;
auto updateFilter = [&]() {
allThreads = viewingSpamFolder ? spamThreads : inboxThreads;
for (auto& t : allThreads) {
t.isBlocked = viewingSpamFolder || blockList.isBlocked(t.number);
}
filteredThreads.clear();
if (searchQuery.empty()) {
filteredThreads = allThreads;
@@ -247,13 +262,22 @@ int runSmsApp(int argc, char** argv) {
auto reloadAllData = [&](bool force = false) {
bool cChanged = contactsStamp.checkAndUpdate(getContactsFilePath());
bool lChanged = modemLogStamp.checkAndUpdate(getModemLogFilePath());
if (force || cChanged || lChanged || !loadedOnce) {
bool bChanged = blockFileStamp.checkAndUpdate(getBlockFilePath());
bool blChanged = blockLogStamp.checkAndUpdate(getBlockedModemLogFilePath());
if (force || cChanged || lChanged || bChanged || blChanged || !loadedOnce) {
loadedOnce = true;
book.load();
allThreads = loadSmsThreads(book);
blockList.load();
inboxThreads = loadSmsThreads(book, getModemLogDirPath());
spamThreads = loadSmsThreads(book, getBlockDirPath());
updateFilter();
if (blockSelected >= static_cast<int>(blockList.entries().size())) {
blockSelected = std::max(0, static_cast<int>(blockList.entries().size()) - 1);
}
if (!activeNumber.empty()) {
threadMessages = loadSmsThreadMessages(activeNumber);
std::string curBase =
viewingSpamFolder ? getBlockDirPath() : getModemLogDirPath();
threadMessages = loadSmsThreadMessages(activeNumber, curBase);
if (selectedMsg >= static_cast<int>(threadMessages.size())) {
selectedMsg =
std::max(0, static_cast<int>(threadMessages.size()) - 1);
@@ -266,7 +290,9 @@ int runSmsApp(int argc, char** argv) {
auto openThreadView = [&](const std::string& num) {
activeNumber = trimStr(num);
threadMessages = loadSmsThreadMessages(activeNumber);
std::string curBase =
viewingSpamFolder ? getBlockDirPath() : getModemLogDirPath();
threadMessages = loadSmsThreadMessages(activeNumber, curBase);
selectedMsg = std::max(0, static_cast<int>(threadMessages.size()) - 1);
mode = ViewMode::ThreadView;
};
@@ -289,22 +315,55 @@ int runSmsApp(int argc, char** argv) {
auto buildOptions = [&]() {
optionsList.clear();
if (mode == ViewMode::Threads) {
optionsList.push_back({1, kIconPlus, "New Message"});
optionsList.push_back({1, kIconPlus, "New Message", false});
if (!filteredThreads.empty()) {
optionsList.push_back({2, kIconEye, "Open Conversation"});
optionsList.push_back({3, kIconSend, "Reply to Selected"});
optionsList.push_back({4, kIconPhone, "Call Contact"});
optionsList.push_back({5, kIconUser, "Open in Contacts"});
optionsList.push_back({6, kIconTrash, "Delete Conversation"});
const auto& selTh = filteredThreads[selectedThread];
bool isBlk = blockList.isBlocked(selTh.number);
optionsList.push_back({2, kIconEye, "Open Conversation", false});
optionsList.push_back({3, kIconSend, "Reply to Selected", false});
optionsList.push_back({4, kIconPhone, "Call Contact", false});
if (isBlk || viewingSpamFolder) {
optionsList.push_back({8, kIconCheck, "Unblock & Restore", false});
} else {
optionsList.push_back({8, kIconBan, "Block Number (Spam)", true});
}
optionsList.push_back({5, kIconUser, "Open in Contacts", false});
optionsList.push_back({6, kIconTrash, "Delete Conversation", true});
}
if (viewingSpamFolder) {
optionsList.push_back(
{9, kIconSms,
"Switch to Inbox (" + std::to_string(inboxThreads.size()) + ")",
false});
} else {
optionsList.push_back(
{9, kIconShield,
"Spam Folder (" + std::to_string(spamThreads.size()) + ")",
false});
}
optionsList.push_back(
{10, kIconBan,
"Manage Blocklist (" + std::to_string(blockList.entries().size()) + ")",
false});
optionsList.push_back({11, kIconPlus, "Block a Number...", false});
} else if (mode == ViewMode::ThreadView) {
optionsList.push_back({3, kIconSend, "Reply / Compose"});
optionsList.push_back({4, kIconPhone, "Call Contact"});
bool isBlk = blockList.isBlocked(activeNumber);
optionsList.push_back({3, kIconSend, "Reply / Compose", false});
optionsList.push_back({4, kIconPhone, "Call Contact", false});
if (!threadMessages.empty()) {
optionsList.push_back({7, kIconCopy, "Forward Selected Msg"});
optionsList.push_back({7, kIconCopy, "Forward Selected Msg", false});
}
optionsList.push_back({5, kIconUser, "Save / View Contact"});
optionsList.push_back({6, kIconTrash, "Delete Conversation"});
if (isBlk || viewingSpamFolder) {
optionsList.push_back({8, kIconCheck, "Unblock & Restore", false});
} else {
optionsList.push_back({8, kIconBan, "Block Number (Spam)", true});
}
optionsList.push_back({5, kIconUser, "Save / View Contact", false});
optionsList.push_back({6, kIconTrash, "Delete Conversation", true});
optionsList.push_back(
{10, kIconBan,
"Manage Blocklist (" + std::to_string(blockList.entries().size()) + ")",
false});
}
selectedOption = 0;
};
@@ -462,9 +521,13 @@ int runSmsApp(int argc, char** argv) {
XDrawLine(dpy, pix, gc, 0, 37, kWinWidth, 37);
if (searchQuery.empty()) {
drawPango(layoutIcon, &colYellow, 8, 2, 34, kIconSms);
drawPango(layoutMain, &colWhite, 30, 2, 34, "Messages", 145);
std::string cnt = "[" + std::to_string(allThreads.size()) + "]";
drawPango(layoutIcon, viewingSpamFolder ? &colRed : &colYellow, 8, 2,
34, viewingSpamFolder ? kIconBan : kIconSms);
std::string hdrTitle =
viewingSpamFolder ? "Spam / Blocked" : "Messages";
drawPango(layoutMain, viewingSpamFolder ? &colRed : &colWhite, 30, 2,
34, hdrTitle, 145);
std::string cnt = "< [" + std::to_string(allThreads.size()) + "] >";
pango_layout_set_width(layoutSmall, -1);
pango_layout_set_text(layoutSmall, cnt.c_str(),
static_cast<int>(cnt.size()));
@@ -489,9 +552,15 @@ int runSmsApp(int argc, char** argv) {
if (filteredThreads.empty()) {
drawPango(layoutMain, &colMuted, 16, 110, 24,
searchQuery.empty() ? "No messages yet" : "No matches", 208);
searchQuery.empty()
? (viewingSpamFolder ? "No blocked messages"
: "No messages yet")
: "No matches",
208);
drawPango(layoutSmall, &colBlue, 16, 138, 20,
"Press Left Softkey for New SMS", 208);
viewingSpamFolder ? "Left/Right: Switch to Inbox"
: "Left Softkey: Options / Blocklist",
208);
} else {
int scroll = 0;
if (selectedThread >= visibleRows) {
@@ -515,17 +584,22 @@ int runSmsApp(int argc, char** argv) {
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH - 1);
}
const char* ic = th.hasDraft
? kIconEdit
: (th.lastIncoming ? kIconInCall : kIconOutCall);
XftColor* icCol = th.hasDraft
? &colYellow
: (th.lastIncoming ? &colGreen : &colBlue);
const char* ic =
th.isBlocked
? kIconBan
: (th.hasDraft ? kIconEdit
: (th.lastIncoming ? kIconInCall : kIconOutCall));
XftColor* icCol =
th.isBlocked
? &colRed
: (th.hasDraft ? &colYellow
: (th.lastIncoming ? &colGreen : &colBlue));
drawPango(layoutIcon, icCol, 6, ry + 1, 20, ic);
std::string title =
th.contactName.empty() ? th.number : th.contactName;
drawPango(layoutMain, &colWhite, 26, ry + 1, 20, title, 128);
drawPango(layoutMain, th.isBlocked ? &colRed : &colWhite, 26, ry + 1,
20, title, 128);
if (!th.lastDisplayTime.empty()) {
pango_layout_set_width(layoutSmall, -1);
@@ -807,18 +881,89 @@ int runSmsApp(int argc, char** argv) {
const int listY = 38;
const int rowH = 36;
for (size_t i = 0; i < optionsList.size(); ++i) {
int ry = listY + static_cast<int>(i) * rowH;
bool isSel = (static_cast<int>(i) == selectedOption);
const int visRows = 6;
int scroll = 0;
if (selectedOption >= visRows) {
scroll = selectedOption - visRows + 1;
}
for (int i = 0; i < visRows; ++i) {
int idx = scroll + i;
if (idx >= static_cast<int>(optionsList.size())) break;
int ry = listY + i * rowH;
bool isSel = (idx == selectedOption);
XSetForeground(dpy, gc, isSel ? pt.spec.selBg : pt.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH - 1);
drawPango(layoutIcon, isSel ? &colYellow : &colBlue, 10, ry, rowH,
optionsList[i].icon);
drawPango(layoutMain, &colWhite, 34, ry, rowH, optionsList[i].label,
198);
XftColor* icCol =
optionsList[idx].danger ? &colRed : (isSel ? &colYellow : &colBlue);
XftColor* txCol = optionsList[idx].danger ? &colRed : &colWhite;
drawPango(layoutIcon, icCol, 10, ry, rowH, optionsList[idx].icon);
drawPango(layoutMain, txCol, 34, ry, rowH, optionsList[idx].label, 198);
}
drawSoftkeyBar("Select", "Select", "Back");
} else if (mode == ViewMode::Blocklist) {
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 34);
drawPango(layoutIcon, &colRed, 8, 0, 34, kIconBan);
std::string hdr =
"Blocklist (" + std::to_string(blockList.entries().size()) + ")";
drawPango(layoutMain, &colWhite, 30, 0, 34, hdr, 200);
const auto& entries = blockList.entries();
if (entries.empty()) {
drawPango(layoutIcon, &colMuted, 112, 94, 24, kIconShield);
drawPango(layoutMain, &colMuted, 44, 124, 24, "Blocklist is empty",
180);
drawPango(layoutSmall, &colBlue, 22, 152, 20,
"Left Softkey: Block a Number", 204);
} else {
const int listY = 36;
const int rowH = 38;
const int visRows = 6;
int scroll = 0;
if (blockSelected >= visRows) {
scroll = blockSelected - visRows + 1;
}
for (int i = 0; i < visRows; ++i) {
int idx = scroll + i;
if (idx >= static_cast<int>(entries.size())) break;
const auto& e = entries[idx];
int ry = listY + i * rowH;
bool isSel = (idx == blockSelected);
XSetForeground(dpy, gc, isSel ? pt.spec.selBg : pt.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH - 1);
std::string cname = book.resolveName(e.number);
std::string topLine = cname.empty() ? e.number : cname;
std::string subLine =
cname.empty() ? e.label : (e.number + " (" + e.label + ")");
drawPango(layoutIcon, &colRed, 8, ry + 1, 20, kIconBan);
drawPango(layoutMain, &colWhite, 28, ry + 1, 20, topLine, 204);
drawPango(layoutSmall, isSel ? &colLight : &colMuted, 28, ry + 20, 16,
subLine, 204);
}
}
drawSoftkeyBar("Add New", entries.empty() ? "" : "Unblock", "Back");
} else if (mode == ViewMode::AddBlock) {
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 34);
drawPango(layoutIcon, &colRed, 8, 0, 34, kIconBan);
drawPango(layoutMain, &colWhite, 30, 0, 34, "Block Phone Number", 200);
drawPango(layoutSmall, &colMuted, 12, 54, 20,
"Enter number or prefix (e.g. +1800*):", 216);
XSetForeground(dpy, gc, pt.spec.bgInputFocus);
XFillRectangle(dpy, pix, gc, 12, 80, kWinWidth - 24, 34);
XSetForeground(dpy, gc, pt.spec.accentAlt);
XDrawRectangle(dpy, pix, gc, 12, 80, kWinWidth - 25, 33);
std::string disp = addBlockInput + "|";
drawPango(layoutMain, &colWhite, 18, 83, 28, disp, kWinWidth - 36);
drawPango(layoutSmall, &colMuted, 12, 124, 20,
"0-9 / * / #: Digits #: + prefix", 216);
drawPango(layoutSmall, &colMuted, 12, 146, 20,
"BackSpace/Left: Delete digit", 216);
drawSoftkeyBar("Block", "Save", "Cancel");
} else if (mode == ViewMode::ConfirmDelete) {
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 36);
@@ -997,6 +1142,49 @@ int runSmsApp(int argc, char** argv) {
} else if (optId == 7 && !threadMessages.empty()) {
std::string body = threadMessages[selectedMsg].text;
openComposeView("", body);
} else if (optId == 8) {
std::string target = (prevMode == ViewMode::ThreadView)
? activeNumber
: (!filteredThreads.empty()
? filteredThreads[selectedThread].number
: "");
if (!target.empty()) {
if (blockList.isBlocked(target) || viewingSpamFolder) {
blockList.unblockNumber(target);
moveSmsThreadBetweenDirs(target, getBlockDirPath(),
getModemLogDirPath());
std::lock_guard<std::mutex> lk(sendMutex);
statusBanner = "Unblocked & restored " + target;
statusBannerUntilMs = nowMs() + 2000;
} else {
std::string cname = book.resolveName(target);
blockList.blockNumber(target, cname.empty() ? "SMS Spam" : cname);
moveSmsThreadBetweenDirs(target, getModemLogDirPath(),
getBlockDirPath());
std::lock_guard<std::mutex> lk(sendMutex);
statusBanner = "Blocked " + target;
statusBannerUntilMs = nowMs() + 2000;
}
reloadAllData(true);
}
mode = ViewMode::Threads;
} else if (optId == 9) {
viewingSpamFolder = !viewingSpamFolder;
selectedThread = 0;
reloadAllData(true);
mode = ViewMode::Threads;
} else if (optId == 10) {
blockList.load();
blockSelected = 0;
mode = ViewMode::Blocklist;
} else if (optId == 11) {
std::string target = (prevMode == ViewMode::ThreadView)
? activeNumber
: (!filteredThreads.empty()
? filteredThreads[selectedThread].number
: "");
addBlockInput = target;
mode = ViewMode::AddBlock;
}
};
@@ -1010,6 +1198,10 @@ int runSmsApp(int argc, char** argv) {
if (!searchQuery.empty()) {
popUtf8Char(searchQuery);
updateFilter();
} else if (viewingSpamFolder) {
viewingSpamFolder = false;
selectedThread = 0;
updateFilter();
} else {
hideWindow();
return;
@@ -1066,10 +1258,40 @@ int runSmsApp(int argc, char** argv) {
} else {
mode = prevMode;
}
} else if (mode == ViewMode::Blocklist) {
if (isLeft) {
addBlockInput.clear();
mode = ViewMode::AddBlock;
} else {
reloadAllData(true);
mode = prevMode;
}
} else if (mode == ViewMode::AddBlock) {
if (isLeft) {
std::string num = trimStr(addBlockInput);
if (!normalizePhone(num).empty()) {
blockList.blockNumber(num, "SMS Blocklist");
moveSmsThreadBetweenDirs(num, getModemLogDirPath(),
getBlockDirPath());
reloadAllData(true);
std::lock_guard<std::mutex> lk(sendMutex);
statusBanner = "Blocked " + num;
statusBannerUntilMs = nowMs() + 2000;
}
mode = ViewMode::Blocklist;
} else {
if (!addBlockInput.empty()) {
popUtf8Char(addBlockInput);
} else {
mode = ViewMode::Blocklist;
}
}
} else if (mode == ViewMode::ConfirmDelete) {
if (isLeft) {
if (confirmSelected == 1) {
deleteSmsThread(activeNumber);
deleteSmsThread(activeNumber, viewingSpamFolder
? getBlockDirPath()
: getModemLogDirPath());
reloadAllData(true);
mode = ViewMode::Threads;
} else {
@@ -1189,7 +1411,13 @@ int runSmsApp(int argc, char** argv) {
}
if (mode == ViewMode::Threads) {
if (sym == XK_Up || sym == XK_KP_Up) {
if (sym == XK_Left || sym == XK_KP_Left || sym == XK_Right ||
sym == XK_KP_Right) {
viewingSpamFolder = !viewingSpamFolder;
selectedThread = 0;
updateFilter();
drawUI();
} else if (sym == XK_Up || sym == XK_KP_Up) {
if (!filteredThreads.empty()) {
selectedThread =
(selectedThread - 1 + static_cast<int>(filteredThreads.size())) %
@@ -1346,6 +1574,57 @@ int runSmsApp(int argc, char** argv) {
} else if (sym == XK_Return || sym == XK_KP_Enter) {
handleSoftkeyAction(true);
}
} else if (mode == ViewMode::Blocklist) {
if (sym == XK_Up || sym == XK_KP_Up) {
if (!blockList.entries().empty()) {
int n = static_cast<int>(blockList.entries().size());
blockSelected = (blockSelected + n - 1) % n;
drawUI();
}
} else if (sym == XK_Down || sym == XK_KP_Down) {
if (!blockList.entries().empty()) {
int n = static_cast<int>(blockList.entries().size());
blockSelected = (blockSelected + 1) % n;
drawUI();
}
} else if (sym == XK_Return || sym == XK_KP_Enter) {
if (!blockList.entries().empty() && blockSelected >= 0 &&
blockSelected < static_cast<int>(blockList.entries().size())) {
std::string num = blockList.entries()[blockSelected].number;
blockList.unblockNumber(num);
moveSmsThreadBetweenDirs(num, getBlockDirPath(),
getModemLogDirPath());
reloadAllData(true);
{
std::lock_guard<std::mutex> lk(sendMutex);
statusBanner = "Unblocked " + num;
statusBannerUntilMs = nowMs() + 1800;
}
drawUI();
}
}
} else if (mode == ViewMode::AddBlock) {
if (sym == XK_Left || sym == XK_KP_Left) {
if (!addBlockInput.empty()) {
popUtf8Char(addBlockInput);
drawUI();
}
} else if (sym == XK_Return || sym == XK_KP_Enter) {
handleSoftkeyAction(true);
} else {
char d = mapDialKey(sym, kc, ev.xkey.state);
if (d == '#') {
if (addBlockInput.empty()) {
addBlockInput.push_back('+');
} else {
addBlockInput.push_back('#');
}
drawUI();
} else if (d != '\0') {
addBlockInput.push_back(d);
drawUI();
}
}
} else if (mode == ViewMode::ConfirmDelete) {
if (sym == XK_Up || sym == XK_Down || sym == XK_KP_Up ||
sym == XK_KP_Down) {