Fix xkopher link focus and unlock clock; battery longevity pass

Map xkopher link focus through wrapped display rows and reset horizontal scroll in no-wrap mode. Refresh the status bar clock on unlock and from dmenu before republishing root WM_NAME. Re-analysis found two low-risk wins: force lz4 for the active zram swap and disable proactive compaction. Rebuild dmenu.so and smallweb.so, update guards and docs, redeploy live, and rebuild the image.
This commit is contained in:
Luxferre committed 2026-11-08 08:45:53 +02:00
1 parent 85c6a7b886
commit 3543556735
22 files changed
+402 -54

No files matched your search

+72 -39
View File
@@ -200,6 +200,44 @@ struct PageDocument {
std::vector<LinkItem> links;
};
// Display geometry shared by rendering and link-focus scrolling. Wrapped
// pages have more display rows than logical lines, so focus must be mapped
// through the same expansion that render() uses.
constexpr int kContentY = 36;
constexpr int kStatusY = 296 - static_cast<int>(NEO_SOFTBAR_H) - 18;
constexpr int kContentH = kStatusY - kContentY;
constexpr int kLineH = 16;
constexpr int kMaxVisLines = kContentH / kLineH;
constexpr int kWrapCols = 30;
struct RenderRow {
std::string text;
int linkIndex;
bool isHeading;
bool isQuote;
bool isError;
};
std::vector<RenderRow> buildRenderRows(const PageDocument& doc,
bool wrapLines) {
std::vector<RenderRow> rows;
for (const auto& dl : doc.lines) {
if (!wrapLines || dl.text.size() <= static_cast<size_t>(kWrapCols)) {
rows.push_back({dl.text, dl.linkIndex, dl.isHeading, dl.isQuote,
dl.isError});
} else {
size_t pos = 0;
while (pos < dl.text.size()) {
size_t take = std::min<size_t>(kWrapCols, dl.text.size() - pos);
rows.push_back({dl.text.substr(pos, take), dl.linkIndex,
dl.isHeading, dl.isQuote, dl.isError});
pos += take;
}
}
}
return rows;
}
void parseGophermap(const std::string& raw, const std::string& scheme,
PageDocument& doc) {
std::istringstream iss(raw);
@@ -642,16 +680,31 @@ int smallweb_run_main(int argc, char** argv) {
// Load initial homepage (bookmark #0 or about:kopher)
navigateTo(!bookmarks[0].empty() ? bookmarks[0] : "about:kopher");
// Keep the focused link visible in the actual display rows. With wrapping
// on, one logical line can become several rows; with wrapping off, a stale
// horizontal offset can hide the start of the link label.
auto ensureFocusedLinkVisible = [&]() {
if (currentDoc.links.empty() || focusedLinkIdx < 0 ||
focusedLinkIdx >= static_cast<int>(currentDoc.links.size())) return;
std::vector<RenderRow> rows = buildRenderRows(currentDoc, wrapLines);
int firstRow = -1;
for (int i = 0; i < static_cast<int>(rows.size()); ++i) {
if (rows[i].linkIndex == focusedLinkIdx) {
firstRow = i;
break;
}
}
if (firstRow < 0) return;
int maxTop = std::max(0, static_cast<int>(rows.size()) - kMaxVisLines);
scrollTopLine = std::clamp(std::max(0, firstRow - 4), 0, maxTop);
if (!wrapLines) scrollLeftCol = 0;
};
auto focusLinkRelative = [&](int delta) {
if (currentDoc.links.empty()) return;
int cnt = static_cast<int>(currentDoc.links.size());
focusedLinkIdx = (focusedLinkIdx + delta + cnt) % cnt;
for (size_t i = 0; i < currentDoc.lines.size(); ++i) {
if (currentDoc.lines[i].linkIndex == focusedLinkIdx) {
scrollTopLine = std::max(0, static_cast<int>(i) - 4);
break;
}
}
ensureFocusedLinkVisible();
};
auto render = [&]() {
@@ -673,39 +726,17 @@ int smallweb_run_main(int argc, char** argv) {
neoui_draw_header(kIconGlobe, NEO_TEXT_GREEN,
currentDoc.hostTitle.c_str(), protoBadge.c_str());
constexpr int kContentY = 36;
constexpr int kStatusY = 296 - NEO_SOFTBAR_H - 18;
constexpr int kContentH = kStatusY - kContentY;
constexpr int kLineH = 16;
int maxVisLines = kContentH / kLineH;
int maxVisLines = kMaxVisLines;
// Expand wrapped lines if wrapLines is enabled
struct RenderRow {
std::string text;
int linkIndex;
bool isHeading;
bool isQuote;
bool isError;
};
std::vector<RenderRow> rows;
for (const auto& dl : currentDoc.lines) {
if (!wrapLines || dl.text.size() <= 30) {
std::string sliced = dl.text;
if (!wrapLines && scrollLeftCol > 0) {
if (static_cast<size_t>(scrollLeftCol) < sliced.size()) {
sliced = sliced.substr(scrollLeftCol);
} else {
sliced.clear();
}
}
rows.push_back({sliced, dl.linkIndex, dl.isHeading, dl.isQuote, dl.isError});
} else {
size_t pos = 0;
while (pos < dl.text.size()) {
size_t take = std::min<size_t>(30, dl.text.size() - pos);
rows.push_back({dl.text.substr(pos, take), dl.linkIndex,
dl.isHeading, dl.isQuote, dl.isError});
pos += take;
// Build the same display rows used by link-focus scrolling, then apply
// horizontal slicing only in no-wrap mode.
std::vector<RenderRow> rows = buildRenderRows(currentDoc, wrapLines);
if (!wrapLines && scrollLeftCol > 0) {
for (auto& r : rows) {
if (static_cast<size_t>(scrollLeftCol) < r.text.size()) {
r.text = r.text.substr(scrollLeftCol);
} else {
r.text.clear();
}
}
}
@@ -1022,6 +1053,7 @@ int smallweb_run_main(int argc, char** argv) {
} else if (ch == ctrls.keyToggleWrap) {
wrapLines = !wrapLines;
scrollLeftCol = 0;
ensureFocusedLinkVisible();
} else if (ch == ctrls.keyLineStart) {
scrollLeftCol = 0;
} else if (ch == ctrls.keyLineEnd) {
@@ -1029,7 +1061,8 @@ int smallweb_run_main(int argc, char** argv) {
} else if (ch == ctrls.keyPageTop) {
scrollTopLine = 0;
} else if (ch == ctrls.keyPageEnd) {
scrollTopLine = static_cast<int>(currentDoc.lines.size());
scrollTopLine = static_cast<int>(
buildRenderRows(currentDoc, wrapLines).size());
}
render();
}
+58 -6
View File
@@ -327,30 +327,81 @@ t9_mode_badge(int mode)
}
}
static void
refresh_status_time(const char *status_dir)
{
char path[512], tbuf[128];
const char *fmt = getenv("SXMO_STATUS_DATE_FORMAT");
time_t now;
struct tm lt;
FILE *fp;
if (!fmt || !*fmt)
fmt = "%H:%M";
now = time(NULL);
if (!localtime_r(&now, &lt))
return;
if (!strftime(tbuf, sizeof(tbuf), fmt, &lt))
return;
snprintf(path, sizeof(path), "%s/099-time", status_dir);
fp = fopen(path, "w");
if (fp) {
fprintf(fp, " %s\n", tbuf);
fclose(fp);
}
}
static void
write_status_cache(const char *base, const char *status_line)
{
char path[512];
FILE *fp;
snprintf(path, sizeof(path), "%s/sxmo_status_bar_cache", base);
fp = fopen(path, "w");
if (fp) {
fprintf(fp, "%s\n", status_line);
fclose(fp);
}
}
static void
update_t9_status_indicator(void)
{
const char *rdir = getenv("XDG_RUNTIME_DIR");
const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000";
const char *status_name = getenv("SXMO_STATUS_NAME");
const char *badge = t9_mode_badge(t9_mode);
char path[256];
char path[512], status_dir[512];
FILE *fp;
if (!status_name || !*status_name)
status_name = "default";
snprintf(path, sizeof(path), "%s/sxmo_status", base);
mkdir(path, 0755);
snprintf(status_dir, sizeof(status_dir), "%s/sxmo_status/%s", base,
status_name);
mkdir(status_dir, 0755);
snprintf(path, sizeof(path), "%s/sxmo_t9_mode", base);
FILE *fp = fopen(path, "w");
fp = fopen(path, "w");
if (fp) {
fprintf(fp, "%s\n", badge);
fclose(fp);
}
snprintf(path, sizeof(path), "%s/sxmo_status/default/005-input-method", base);
snprintf(path, sizeof(path), "%s/005-input-method", status_dir);
fp = fopen(path, "w");
if (fp) {
fprintf(fp, "%s\n", badge);
fclose(fp);
}
/* The statusbar hook skips periodics while the panel is dark. Refresh the
* clock here so opening dmenu or changing T9 mode after unlock cannot
* republish a stale root WM_NAME from the cached status files. */
refresh_status_time(status_dir);
if (dpy && root) {
char status_dir[256];
snprintf(status_dir, sizeof(status_dir), "%s/sxmo_status/default", base);
DIR *dir = opendir(status_dir);
if (dir) {
char names[32][64];
@@ -377,7 +428,7 @@ update_t9_status_indicator(void)
size_t pos = 0;
status_line[0] = '\0';
for (int i = 0; i < count; i++) {
char fpath[320];
char fpath[640];
snprintf(fpath, sizeof(fpath), "%s/%s", status_dir, names[i]);
FILE *sfp = fopen(fpath, "r");
if (!sfp)
@@ -398,6 +449,7 @@ update_t9_status_indicator(void)
fclose(sfp);
}
if (pos > 0) {
write_status_cache(base, status_line);
XStoreName(dpy, root, status_line);
XFlush(dpy);
}