diff --git a/CHANGELOG.md b/CHANGELOG.md index ef7e557..a0fc002 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,13 @@ Release versions follow the `
` format (where `2026` is `a`, ## Unreleased +### Full-length SMS conversation view and Unicode-aware composer +- Fixed `xsms` (`sms.so`) cutting long, concatenated, or Unicode messages short in the expanded conversation view: the body was handed to `pango_xft_render_layout()` as one multiline layout, and the target Pango/Xft stack only painted its first line (the example Ukrainian `Мелорінг дарує хіти! …` message stopped right before `є`). Reproduced on the connected phone with an instrumented `sms.so` (full 530-byte body, 13 measured layout lines, only one painted line) and a standalone ARM reproducer; `pango_xft_render_layout_line()` paints all lines. The QMI WMS reassembly and `sms.txt` parser were verified correct and are not the cause. +- Message bodies (and long composed text) are now rendered line by line through a shared `renderLayoutLines()` helper with an Xft clip rectangle, so no text overflows its bubble or the softkey bar. The selected message is scrollable with `Up`/`Down` (one line per press, with a right-edge scrollbar); the keys step to the previous/next message only at the top/bottom of an overflowing message. Card measurement now uses the same width as rendering. +- Replaced the byte-based `composeText.size()/160` counter with `smsTextMetrics()`, which decodes UTF-8 code points, detects the 3GPP TS 23.038 GSM 7-bit alphabet plus extension table, and reports GSM-7 septets (160 per part, 153 when concatenated) or UCS-2 UTF-16 units (70 per part, 67 when concatenated) with the correct part count. The offline-send fallback log now records units instead of bytes. +- `parseSmsHeaderLine()` strips the `[SIM n]` tag written by the QMI WMS daemon (`Received from 5050 [SIM 1] at …:`) and by older local send fallbacks (`Sent at … [SIM 1]:`), so senders and ISO timestamps stay clean; the fallback no longer writes the tag into `sms.txt`. +- Added a `scripts/check-rebuild.sh` guard that rejects a bulk `pango_xft_render_layout()` call in `sms_plugin.cpp` and requires the line-by-line renderer, scroll state, encoding metrics, and SIM-tag stripping. + ### Remove the remaining optional scripting runtimes - Removed `perl`, `perl-io-socket-ssl`, `tcl-lib`, `tcl-tls`, `sqlite-tcl`, `lua5.4`, `lua5.4-dev`, `lua5.5`, `lua5.5-dev`, and `sqlite` (CLI) from `scripts/rootfs-packages.txt` and added them to the prune denylist: 13 packages / 49.45 MiB including dependents. `sqlite-libs`, `tcl`, and all paramount runtimes stay. - Promoted `curl` to an explicit world entry and pinned `curl`, `bc`, `ed`, `rlwrap`, `mandoc`, `nano`, `less`, and `frotz` as core tools in `scripts/check-rebuild.sh`. diff --git a/MANUAL.md b/MANUAL.md index dd408b2..0169ca5 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -165,8 +165,9 @@ All twenty-five phone applications are compiled as shared-object plugins (`/usr/ 7. **SMS manager, composer, and spam filter (`sms.so` / `xsms`)**: - **Open**: select **Texts** from the System menu, or choose **Send SMS** / **Read Messages** from Contacts. - **Conversations, inbox, and spam folder**: browse SMS threads and drafts with contact name resolution, unread indicators, and message bubbles (`Recv` and `Sent`). Press `Left`/`Right` in the thread list (or use **Left softkey (`Options`)**) to switch between **`Inbox`** (`~/.local/share/sxmo/modem`) and the **`Spam`** folder (`~/.local/share/sxmo/block`). + - **Full-length messages**: open a thread with **Center `OK`** to read the complete text of long, concatenated, or Unicode (`UCS-2`) messages. Message bodies are drawn line by line and clipped to the bubble, so a multipart message is never cut off at its first line. `Up`/`Down` scrolls inside the selected message (a scrollbar on the right edge shows the position) and steps to the previous/next message once the top or bottom is reached; **Right softkey (`Back`)** returns to the thread list. The QMI WMS daemon reassembles 8-bit and 16-bit concatenated SMS across GSM-7 and UCS-2 (including split surrogate pairs) before writing `sms.txt`, and the `[SIM n]` tag in its log header is stripped when parsing. - **Anti-spam blocking**: press **Left softkey (`Options`)** on any thread or conversation to **Block Number (Spam)** (which adds the sender to `~/.config/sxmo/block.tsv` and moves their thread into the `Spam` folder), **Unblock & Restore** (which unblocks the sender and restores their thread to `Inbox`), **Manage Blocklist (N)**, or **Block a Number...**. Incoming texts from blocked numbers are silently routed into `~/.local/share/sxmo/block` without ringing or vibrating. - - **Multi-tap composer**: pick a recipient from Contacts/Recents or type a number (hold `0` for `+`), compose messages with multi-tap keypad entry (`#` cycles input mode), monitor live character/segment counts (`0/160`), save drafts automatically, and send via **Call (green)**, **Center `OK`**, or **Left softkey** (prompting to select **SIM 1** or **SIM 2** when two SIM cards are active in DSDS). + - **Multi-tap composer**: pick a recipient from Contacts/Recents or type a number (hold `0` for `+`), compose messages with multi-tap keypad entry (`#` cycles input mode), monitor live character/segment counts, save drafts automatically, and send via **Call (green)**, **Center `OK`**, or **Left softkey** (prompting to select **SIM 1** or **SIM 2** when two SIM cards are active in DSDS). The counter is encoding-aware: GSM-7 text shows `units/160` (or `units/306x2` for two concatenated parts at 153 septets each), while any character outside the GSM 7-bit alphabet (for example Ukrainian `є`, `і`, `ї`, `ґ`, or a supplementary-plane character) switches the whole message to UCS-2 and shows `units/70` (or `units/134x2` at 67 UTF-16 units per part). Long composed text is drawn line by line and scrolled so the end of the draft stays visible. 8. **File manager (`files.so` / `xfiles`)**: - **Open**: select **Files** from the System menu or press `Mod4+d`. diff --git a/README.md b/README.md index 0aecb7d..faff8c5 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs - **Zero-log privacy default and Extended Logging toggle (`xengmenu` / `dmenu config` / `bananarchy-engmenu-ctl logging`)**: extended system and session logging is **disabled by default** (`OFF`) across `sxmo_log`, `superd` and its managed services, `Xorg` (`-logfile /dev/null -logverbose 0`), `dwm`, `fcitx5` (`--verbose="*=0"`), `tinydm`, `NetworkManager` (`level=OFF`), `ModemManager` (`--log-level=ERR --log-file=/dev/null`), and kernel `printk`, ensuring zero eMMC log writes and zero idle logging activity. Extended RAM-only logging in `/tmp` (`/tmp/sxmo.log`, `/tmp/superd.log`, `/tmp/superd_state/superd/logs/*.log`) can be toggled at any time in the **Engineering Menu (`*#0001#` / `xengmenu` -> `8: Extended Logging`)**, **`Config -> Extended Logging`**, or via `bananarchy-engmenu-ctl logging [on|off|toggle|status]`. - **Global controls drawer (`xdrawer`) and `*` + `#` screenshot combo**: press **both softkeys together** from anywhere to adjust linear (`1%`–`100%`) speaker, earpiece, and ringtone volume, audio output routing (`Speaker`, `Earpiece`, `Headphones` with automatic 3.5mm jack plug/unplug routing), ringer mode (`Ring+Vib` / `Vibrate` / `Silent` / `DND`), 3-level vibration intensity (`Light` / `Medium` / `Strong`), flashlight, sound and microphone mute, screen brightness, and keypad backlight; press **`*` and `#` together** from anywhere to capture a `240x320` PNG screenshot (`scrot` via `bananarchy-screenshot`) to `~/Pictures/screenshot-YYYYMMDD-HHMMSS.png`. - **Phone dialer (`xdialer`), call log (`xcalllog`), and call screen (`xcallscreen`)**: press any digit on the home screen to start dialing with live T9 contact matching, run interactive carrier USSD codes (`*100#`, etc.), or type `*#06#` to inspect both IMEIs. When two SIM cards are active in Dual-SIM Dual Standby (DSDS), placing a call or running a USSD code prompts to choose between `SIM 1` and `SIM 2`. Incoming and active calls on either SIM (as well as incoming/active VoIP calls from `xsip` and `xtox`) open a dedicated call screen with an active `[SIM 1]`/`[SIM 2]`/`[SIP]`/`[TOX]` badge, earpiece/speaker switching, microphone mute, DTMF keypad, and one-key normalized WAV call recording (`~/Recordings/rec_HHMMSS_.wav`). The call log includes a 5-tab view (`All`, `Miss`, `In`, `Out`, `Spam`) with integrated anti-spam number blocking (`~/.config/sxmo/block.tsv`) that automatically hangs up blocked callers and logs them to the `Spam` tab without triggering missed-call notifications. -- **Contacts (`xcontacts`) and SMS manager (`xsms`)**: full phonebook editor with direct Qualcomm QMI SIM card contact import and export across SIM 1 and SIM 2, paired with a threaded SMS conversation view, multi-tap message composer with outgoing `SIM 1` / `SIM 2` selection when two SIMs are active, and built-in anti-spam blocklist / spam folder (`~/.local/share/sxmo/block`) with one-key thread blocking and restoration. +- **Contacts (`xcontacts`) and SMS manager (`xsms`)**: full phonebook editor with direct Qualcomm QMI SIM card contact import and export across SIM 1 and SIM 2, paired with a threaded SMS conversation view that renders and scrolls full-length concatenated/Unicode (`UCS-2`) messages line by line, a multi-tap message composer with an encoding-aware GSM-7/UCS-2 segment counter and outgoing `SIM 1` / `SIM 2` selection when two SIMs are active, and built-in anti-spam blocklist / spam folder (`~/.local/share/sxmo/block`) with one-key thread blocking and restoration. - **Modem and Dual-SIM manager (`xmodem`)**: 4-tab cellular control center (`SIMs`, `Radio`, `AT`, `Log`) supporting Dual-SIM Dual Standby (DSDS) with simultaneous network registration on both SIM slots, instant default SIM switching (`Set as Default SIM (Calls/SMS)`), full Primary/Secondary GW (`4G/Data`) slot swapping (`Make Primary GW (4G/Data Swap)`), SIM PIN unlock and PUK unblock wizards, 2G/3G/4G radio mode selection, interactive USSD sessions, and a live AT command console. - **Networks and Bluetooth manager (`xnetworks`) with OBEX file transfer (`bananarchy-bt-obex`)**: 3-tab connectivity manager for Wi-Fi networks, WPA2 password entry, Wi-Fi hotspot, USB tethering, 4G/LTE mobile data (`wwan0`) and APN editing, and Bluetooth pairing, with built-in Bluetooth OBEX Object Push file reception (`~/Downloads` status and receiver toggle in the `Bluetooth` tab) and **Send via Bluetooth** in `xfiles`. - **File manager (`xfiles`) with microSD automount (`sxmo_sdcard.sh`), Bluetooth file sharing, music and tracker player (`xmusic`), and camera (`xcamera`)**: keypad directory browser with automatic microSD card (`/dev/mmcblk1`) detection and `/media/sdcard` mounting/unmounting, **Send via Bluetooth** OBEX file push to paired/discovered devices, built-in text viewer, integrated GUI multi-tap text editor (`Edit in Text Editor`, available as an action on any file), image viewer, and dedicated monophonic ringtone viewer (`RingtoneView` for Nokia RTTTL `.nrt`/`.rtttl`/`.rtx`, Ericsson eMelody `.emy`, and IrDA iMelody `.imy` with graphical piano-roll pitch contour, note sequence viewer, live audio preview, and one-key assignment as call ringtone or notification/SMS sound — plus one-click actions to launch `.jar`/`.jad` MIDlets in the **ReMEdy (`remedy`)** J2ME emulator, launch `.gb`/`.gbc` ROMs in the Game Boy emulator, run `.yab` scripts in Yabasic inside the terminal, play audio, preview images, set any image as wallpaper, or install any audio, tracker, or monophonic melody file as call ringtone or notification/SMS sound), a 3-tab music and chiptune tracker module player (`WAV`, `MP3`, `OGG`, `FLAC`, `Opus`, `MOD`, `XM`, `IT`, `S3M`, `NRT`, `RTTTL`, `RTX`, `EMY`, `IMY`, and more), and a live V4L2 camera viewfinder with digital zoom, flash/torch control, self-timer, and photo gallery. diff --git a/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so b/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so index bb62113..754bec8 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so and b/overlay/rootfs/usr/lib/dwm/plugins/engmenu.so differ diff --git a/overlay/rootfs/usr/lib/dwm/plugins/sms.so b/overlay/rootfs/usr/lib/dwm/plugins/sms.so index e390330..97e6c47 100755 Binary files a/overlay/rootfs/usr/lib/dwm/plugins/sms.so and b/overlay/rootfs/usr/lib/dwm/plugins/sms.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/engmenu.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/engmenu.so index bb62113..754bec8 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/engmenu.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/engmenu.so differ diff --git a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so index e390330..97e6c47 100755 Binary files a/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so and b/prebuilt/sxmo-x11/usr/lib/dwm/plugins/sms.so differ diff --git a/scripts/check-rebuild.sh b/scripts/check-rebuild.sh index 61de30b..9ddf537 100755 --- a/scripts/check-rebuild.sh +++ b/scripts/check-rebuild.sh @@ -141,6 +141,21 @@ if ! "$BASE_DIR/scripts/sync-prebuilt-overlay.sh" --check; then fail "overlay/rootfs artifacts differ from prebuilt/" fi +echo "[check] SMS long-message rendering..." +SMS_SRC="$BASE_DIR/src/dwm-plugins/sms_plugin.cpp" +SMS_HDR="$BASE_DIR/src/dwm-plugins/phone_data.h" +if grep -qE '^[[:space:]]*pango_xft_render_layout\(' "$SMS_SRC"; then + fail "sms_plugin.cpp must not bulk-render multiline message bodies" +fi +if ! grep -q 'pango_xft_render_layout_line(' "$SMS_SRC"; then + fail "sms_plugin.cpp lost its line-by-line message body renderer" +fi +for token in msgScrollPx smsTextMetrics stripSmsSimTag; do + if ! grep -q "$token" "$SMS_SRC" && ! grep -q "$token" "$SMS_HDR"; then + fail "sms plugin lost $token" + fi +done + echo "[check] Local agent config stays ignored..." if [ -d "$BASE_DIR/.git" ]; then if ! git -C "$BASE_DIR" check-ignore -q .bantam.cfg; then diff --git a/src/dwm-plugins/phone_data.h b/src/dwm-plugins/phone_data.h index 69633ba..20f29f1 100644 --- a/src/dwm-plugins/phone_data.h +++ b/src/dwm-plugins/phone_data.h @@ -2141,6 +2141,28 @@ struct SmsThread { int messageCount = 0; }; +// The QMI WMS daemon tags reassembled (multipart) messages with the receiving +// SIM slot, e.g. "Received from 5050 [SIM 1] at :". Older local send +// fallbacks wrote "Sent at [SIM 1]:". Strip the tag so the sender and +// timestamp stay clean for the conversation view and time formatting. +inline std::string stripSmsSimTag(const std::string& s) { + std::string out = s; + size_t pos = 0; + while ((pos = out.find("[SIM ", pos)) != std::string::npos) { + size_t end = out.find(']', pos + 5); + if (end == std::string::npos) { + break; + } + size_t start = pos; + if (start > 0 && out[start - 1] == ' ') { + --start; + } + out.erase(start, end - start + 1); + pos = start; + } + return out; +} + inline bool parseSmsHeaderLine(const std::string& line, bool* outIncoming, std::string* outSender, @@ -2148,25 +2170,26 @@ inline bool parseSmsHeaderLine(const std::string& line, if (line.empty() || line.back() != ':') { return false; } - if (line.rfind("Received at ", 0) == 0 && line.size() > 13) { + std::string hdr = stripSmsSimTag(line.substr(0, line.size() - 1)); + if (hdr.rfind("Received at ", 0) == 0 && hdr.size() > 12) { *outIncoming = true; outSender->clear(); - *outIsoTime = line.substr(12, line.size() - 13); + *outIsoTime = hdr.substr(12); return true; } - if (line.rfind("Received from ", 0) == 0) { - size_t atPos = line.find(" at "); - if (atPos != std::string::npos && atPos + 4 < line.size() - 1) { + if (hdr.rfind("Received from ", 0) == 0) { + size_t atPos = hdr.find(" at ", 14); + if (atPos != std::string::npos && atPos + 4 < hdr.size()) { *outIncoming = true; - *outSender = line.substr(14, atPos - 14); - *outIsoTime = line.substr(atPos + 4, line.size() - (atPos + 4) - 1); + *outSender = hdr.substr(14, atPos - 14); + *outIsoTime = hdr.substr(atPos + 4); return true; } } - if (line.rfind("Sent at ", 0) == 0 && line.size() > 9) { + if (hdr.rfind("Sent at ", 0) == 0 && hdr.size() > 8) { *outIncoming = false; outSender->clear(); - *outIsoTime = line.substr(8, line.size() - 9); + *outIsoTime = hdr.substr(8); return true; } return false; diff --git a/src/dwm-plugins/sms_plugin.cpp b/src/dwm-plugins/sms_plugin.cpp index e3f0ff7..794ee1f 100644 --- a/src/dwm-plugins/sms_plugin.cpp +++ b/src/dwm-plugins/sms_plugin.cpp @@ -9,8 +9,11 @@ #include #include #include +#include #include #include +#include +#include namespace { @@ -18,6 +21,121 @@ using namespace bananarchy; volatile sig_atomic_t gRunning = 1; +// The PangoXft renderer on the target stack only paints the first line of a +// long multiline layout when the whole layout is handed to +// pango_xft_render_layout() in one call. Message bodies are therefore drawn +// line by line with pango_xft_render_layout_line(). +constexpr int kMsgScrollStep = 16; +constexpr int kMsgBodyWidth = kWinWidth - 32; // cardW - 14 + +std::vector decodeUtf8CodePoints(const std::string& s) { + std::vector out; + size_t i = 0; + while (i < s.size()) { + unsigned char c = static_cast(s[i]); + uint32_t cp = 0; + size_t n = 0; + if (c < 0x80) { + cp = c; + n = 1; + } else if ((c & 0xE0) == 0xC0) { + cp = c & 0x1F; + n = 2; + } else if ((c & 0xF0) == 0xE0) { + cp = c & 0x0F; + n = 3; + } else if ((c & 0xF8) == 0xF0) { + cp = c & 0x07; + n = 4; + } else { + ++i; + continue; + } + if (i + n > s.size()) break; + bool ok = true; + for (size_t k = 1; k < n; ++k) { + unsigned char cc = static_cast(s[i + k]); + if ((cc & 0xC0) != 0x80) { + ok = false; + break; + } + cp = (cp << 6) | (cc & 0x3F); + } + if (!ok) { + ++i; + continue; + } + out.push_back(cp); + i += n; + } + return out; +} + +struct SmsTextMetrics { + int units = 0; // GSM-7 septets or UTF-16 code units + int parts = 1; // concatenated SMS parts + int limit = 160; // capacity of the current number of parts + bool ucs2 = false; +}; + +// 3GPP TS 23.038 GSM 7-bit default alphabet and extension table. Any code +// point outside both forces UCS-2 (70 units per part, 67 when concatenated). +SmsTextMetrics smsTextMetrics(const std::string& text) { + static const std::unordered_set kBasic = [] { + std::unordered_set set; + for (uint32_t cp : decodeUtf8CodePoints( + "@\u00a3$\u00a5\u00e8\u00e9\u00f9\u00ec\u00f2\u00c7\n" + "\u00d8\u00f8\r\u00c5\u00e5" + "\u0394_\u03a6\u0393\u039b\u03a9\u03a0\u03a8\u03a3\u0398" + "\u039e\u00c6\u00e6\u00df\u00c9" + " !\"#\u00a4%&'()*+,-./0123456789:;<=>?" + "\u00a1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c4\u00d6\u00d1\u00dc" + "\u00a7\u00bfabcdefghijklmnopqrstuvwxyz\u00e4\u00f6\u00f1" + "\u00fc\u00e0")) { + set.insert(cp); + } + return set; + }(); + static const std::unordered_set kExt = [] { + std::unordered_set set; + for (uint32_t cp : decodeUtf8CodePoints("\f^{}\\[~]|\u20ac")) { + set.insert(cp); + } + return set; + }(); + + std::vector cps = decodeUtf8CodePoints(text); + bool ucs2 = false; + int septets = 0; + for (uint32_t cp : cps) { + if (kBasic.count(cp)) { + ++septets; + } else if (kExt.count(cp)) { + septets += 2; + } else { + ucs2 = true; + break; + } + } + + SmsTextMetrics m; + m.ucs2 = ucs2; + if (ucs2) { + int units = 0; + for (uint32_t cp : cps) { + units += (cp > 0xFFFF) ? 2 : 1; + } + m.units = units; + m.parts = units <= 70 ? 1 : (units + 66) / 67; + m.limit = m.parts == 1 ? 70 : m.parts * 67; + } else { + m.units = septets; + m.parts = septets <= 160 ? 1 : (septets + 152) / 153; + m.limit = m.parts == 1 ? 160 : m.parts * 153; + } + return m; +} + void handleSignal(int) { gRunning = 0; } @@ -167,6 +285,9 @@ int runSmsApp(int argc, char** argv) { std::string searchQuery; int selectedThread = 0; int selectedMsg = 0; + int msgScrollPx = 0; // vertical scroll inside the selected message + int msgTextH = 0; // wrapped height of the selected message body + int msgViewH = 0; // visible body height inside its card int selectedOption = 0; int selectedPicker = 0; int confirmSelected = 0; @@ -272,6 +393,7 @@ int runSmsApp(int argc, char** argv) { viewingSpamFolder ? getBlockDirPath() : getModemLogDirPath(); threadMessages = loadSmsThreadMessages(activeNumber, curBase); selectedMsg = std::max(0, static_cast(threadMessages.size()) - 1); + msgScrollPx = 0; mode = ViewMode::ThreadView; }; @@ -432,13 +554,13 @@ int runSmsApp(int argc, char** argv) { ContactBook::ensureParentDir(smsPath); std::ofstream smsOut(smsPath, std::ios::app); if (smsOut.is_open()) { - smsOut << "Sent at " << tbuf << " [SIM " << chosenSim << "]:\n" - << body << "\n\n"; + smsOut << "Sent at " << tbuf << ":\n" << body << "\n\n"; } std::ofstream logOut(getModemLogFilePath(), std::ios::app); if (logOut.is_open()) { logOut << tbuf << "\tsent_txt\t" << recipient << "\t[SIM " - << chosenSim << "] " << body.size() << " chars\n"; + << chosenSim << "] " << smsTextMetrics(body).units + << " units\n"; } removeSmsDraft(recipient); } @@ -463,6 +585,42 @@ int runSmsApp(int argc, char** argv) { return neo.drawPango(layout, color, x, y, h, text, maxW); }; + // pango_xft_render_layout() only paints the first line of a long multiline + // UTF-8 layout on the target Pango/Xft stack, so every multiline body is + // drawn one line at a time, clipped to its visible rectangle. yPx is the + // layout origin and scrollPx is the number of layout pixels hidden above + // the clip (negative when the layout starts below the clip top). + auto renderLayoutLines = [&](PangoLayout* layout, XftColor* color, int xPx, + int yPx, int clipX, int clipY, int clipW, + int clipH, int scrollPx) { + if (clipW <= 0 || clipH <= 0) { + return; + } + XRectangle clip { + static_cast(clipX), static_cast(clipY), + static_cast(clipW), + static_cast(clipH)}; + XftDrawSetClipRectangles(xftDraw, 0, 0, &clip, 1); + PangoLayoutIter* it = pango_layout_get_iter(layout); + if (it) { + do { + PangoRectangle logical{}; + pango_layout_iter_get_line_extents(it, nullptr, &logical); + int lineTop = logical.y / PANGO_SCALE; + int lineBottom = (logical.y + logical.height) / PANGO_SCALE; + if (lineBottom <= scrollPx) continue; + if (lineTop >= scrollPx + clipH) break; + PangoLayoutLine* line = pango_layout_iter_get_line_readonly(it); + int baseline = pango_layout_iter_get_baseline(it) / PANGO_SCALE; + pango_xft_render_layout_line( + xftDraw, color, line, xPx * PANGO_SCALE, + (yPx + baseline - scrollPx) * PANGO_SCALE); + } while (pango_layout_iter_next_line(it)); + pango_layout_iter_free(it); + } + XftDrawSetClip(xftDraw, nullptr); + }; + auto drawSoftkeyBar = [&](const std::string& leftLabel, const std::string& centerLabel, const std::string& rightLabel) { @@ -611,6 +769,7 @@ int runSmsApp(int argc, char** argv) { struct CardGeom { int idx; int h; + int bodyH; std::string header; std::string body; bool incoming; @@ -626,13 +785,14 @@ int runSmsApp(int argc, char** argv) { cg.header = (m.incoming ? "Recv " : "Sent ") + m.displayTime; cg.body = m.text; - pango_layout_set_width(layoutSmall, 204 * PANGO_SCALE); + pango_layout_set_width(layoutSmall, kMsgBodyWidth * PANGO_SCALE); pango_layout_set_wrap(layoutSmall, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layoutSmall, PANGO_ELLIPSIZE_NONE); pango_layout_set_text(layoutSmall, cg.body.c_str(), static_cast(cg.body.size())); int bw = 0, bh = 0; pango_layout_get_pixel_size(layoutSmall, &bw, &bh); + cg.bodyH = bh; cg.h = std::max(38, bh + 22); cards.push_back(cg); } @@ -679,14 +839,30 @@ int runSmsApp(int argc, char** argv) { drawPango(layoutSmall, cg.incoming ? &colGreen : &colBlue, cardX + 8, curY + 2, 14, cg.header, cardW - 14); - pango_layout_set_width(layoutSmall, (cardW - 14) * PANGO_SCALE); + pango_layout_set_width(layoutSmall, kMsgBodyWidth * PANGO_SCALE); pango_layout_set_wrap(layoutSmall, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layoutSmall, PANGO_ELLIPSIZE_NONE); pango_layout_set_text(layoutSmall, cg.body.c_str(), static_cast(cg.body.size())); - pango_xft_render_layout(xftDraw, &colWhite, layoutSmall, - (cardX + 8) * PANGO_SCALE, - (curY + 18) * PANGO_SCALE); + const int bodyViewH = std::max(0, cardH - 20); + const int maxScroll = std::max(0, cg.bodyH - bodyViewH); + const int scrollPx = + isSel ? std::clamp(msgScrollPx, 0, maxScroll) : 0; + renderLayoutLines(layoutSmall, &colWhite, cardX + 8, curY + 18, + cardX + 8, curY + 18, cardW - 16, bodyViewH, + scrollPx); + + if (isSel) { + msgTextH = cg.bodyH; + msgViewH = bodyViewH; + if (maxScroll > 0) { + int sbH = std::max(14, bodyViewH * bodyViewH / (cg.bodyH + 1)); + int sbY = curY + 18 + + (bodyViewH - sbH) * scrollPx / maxScroll; + XSetForeground(dpy, gc, pt.spec.accent); + XFillRectangle(dpy, pix, gc, cardX + cardW - 5, sbY, 3, sbH); + } + } curY += cardH + 4; } @@ -715,10 +891,13 @@ int runSmsApp(int argc, char** argv) { } else if (caseMode == TextCaseMode::Num) { modeBadge = "[123]"; } - int segs = std::max(1, static_cast(composeText.size() + 159) / 160); + SmsTextMetrics sm = smsTextMetrics(composeText); std::string rightHdr = std::string(modeBadge) + " " + - std::to_string(composeText.size()) + "/" + - std::to_string(segs * 160); + std::to_string(sm.units) + "/" + + std::to_string(sm.limit); + if (sm.parts > 1) { + rightHdr += "x" + std::to_string(sm.parts); + } pango_layout_set_width(layoutSmall, -1); pango_layout_set_text(layoutSmall, rightHdr.c_str(), static_cast(rightHdr.size())); @@ -775,12 +954,13 @@ int runSmsApp(int argc, char** argv) { if (th > bodyMaxH) { textY = 76 - (th - bodyMaxH); } - XRectangle clipRect {6, 73, static_cast(kWinWidth - 12), - static_cast(smsTapActive ? 134 : 154)}; - XftDrawSetClipRectangles(xftDraw, 0, 0, &clipRect, 1); - pango_xft_render_layout(xftDraw, &colWhite, layoutMain, - 12 * PANGO_SCALE, textY * PANGO_SCALE); - XftDrawSetClip(xftDraw, nullptr); + int clipY = 73; + int clipH = smsTapActive ? 134 : 154; + // Keep the layout origin at the clip top and express the upward + // scroll of a long draft as hidden layout pixels, so the tail of the + // text stays visible instead of being skipped by the line loop. + renderLayoutLines(layoutMain, &colWhite, 12, clipY, 6, clipY, + kWinWidth - 12, clipH, clipY - textY); } if (smsTapActive) { @@ -1505,14 +1685,24 @@ int runSmsApp(int argc, char** argv) { } } } else if (mode == ViewMode::ThreadView) { + int maxScroll = std::max(0, msgTextH - msgViewH); if (sym == XK_Up || sym == XK_KP_Up) { - if (selectedMsg > 0) { + if (msgScrollPx > 0) { + msgScrollPx = std::max(0, msgScrollPx - kMsgScrollStep); + drawUI(); + } else if (selectedMsg > 0) { --selectedMsg; + msgScrollPx = 0; drawUI(); } } else if (sym == XK_Down || sym == XK_KP_Down) { - if (selectedMsg + 1 < static_cast(threadMessages.size())) { + if (msgScrollPx < maxScroll) { + msgScrollPx = std::min(maxScroll, msgScrollPx + kMsgScrollStep); + drawUI(); + } else if (selectedMsg + 1 < + static_cast(threadMessages.size())) { ++selectedMsg; + msgScrollPx = 0; drawUI(); } } else if (sym == XK_Return || sym == XK_KP_Enter) {