[PATCH] Prevent wrong UTF-8 window title truncation

3 views
Skip to first unread message

david.m...@gmail.com

unread,
Jan 14, 2026, 10:32:59 PMJan 14
to Window Maker Development
The patch is fixing some UTF-8 truncation issue that could happen with the window title
when it was shrinked to be displayed in the window list (F11).
Issue was reported at https://github.com/window-maker/wmaker/issues/61
---
 src/misc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/misc.c b/src/misc.c
index ffd97e6e..4c920520 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -311,7 +311,8 @@ char *ShrinkString(WMFont *font, const char *string, int width)
  p1 = 0;
  p2 = p;
  t = (p2 - p1) / 2;
- while (p2 > p1 && p1 != t) {
+ while (p2 > p1) {
+ int old_t = t;
  /* ensure we cut at UTF-8 character boundary */
  utf8_safe_pos = utf8_find_char_start(string, p - t);
  t = p - utf8_safe_pos;
@@ -319,12 +320,20 @@ char *ShrinkString(WMFont *font, const char *string, int width)
  w = WMWidthOfString(font, &string[utf8_safe_pos], t);
  if (w > width) {
  p2 = t;
- t = p1 + (p2 - p1) / 2;
  } else if (w < width) {
  p1 = t;
- t = p1 + (p2 - p1) / 2;
- } else
- p2 = p1 = t;
+ } else {
+ p1 = t;
+ break;
+ }
+
+ /* Calculate new t for next iteration */
+ t = p1 + (p2 - p1) / 2;
+
+ /* Prevent infinite loop if we're not making progress */
+ if (t == old_t || (p2 - p1) <= 1) {
+ break;
+ }
  }
 
  /* ensure final cut is at UTF-8 character boundary */
--
2.43.0

0001-Prevent-wrong-UTF-8-window-title-truncation.patch
Reply all
Reply to author
Forward
0 new messages