From d2cf6912b9c1ddf8e608d3a0f663ffc7a3fec1c2 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Wed, 13 Apr 2011 00:18:32 +0300 Subject: [PATCH] Save X11 window title regardless of unconvertible characters If Xutf8TextPropertyToTextList or XmbTextPropertyToTextList returns a positive number, that means some characters were unconvertible and have been replaced with XDefaultString(). Use the resulting string even in that case, as if the function had returned Success. The previous version ignored the string and didn't even free it. --- src/osdep/osdep.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/osdep/osdep.c b/src/osdep/osdep.c index 078434b0..7aab5b99 100644 --- a/src/osdep/osdep.c +++ b/src/osdep/osdep.c @@ -506,19 +506,27 @@ xprop_to_string(Display *display, const XTextProperty *text_prop, int to_cp) unsigned char *ret = NULL; /* defines X_HAVE_UTF8_STRING if - * Xutf8TextPropertyToTextList is available. */ + * Xutf8TextPropertyToTextList is available. + * + * The X...TextPropertyToTextList functions return a negative + * error code, or Success=0, or the number of unconvertible + * characters. Use the result even if some characters were + * unconvertible, because convert_string() can be lossy too, + * and it seems better to restore an approximation of the + * original title than to restore a default title that may be + * entirely different. */ #if defined(CONFIG_UTF8) && defined(X_HAVE_UTF8_STRING) from_cp = get_cp_index("UTF-8"); if (Xutf8TextPropertyToTextList(display, text_prop, &list, - &count) != Success) + &count) < 0) return NULL; #else /* !defined(X_HAVE_UTF8_STRING) || !defined(CONFIG_UTF8) */ from_cp = get_cp_index("System"); if (XmbTextPropertyToTextList(display, text_prop, &list, - &count) != Success) + &count) < 0) return NULL; #endif /* !defined(X_HAVE_UTF8_STRING) || !defined(CONFIG_UTF8) */