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
};