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:
1 parent
85c6a7b886
commit
3543556735
22 files changed
+402
-54
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user