summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/util.c b/src/util.c
index e15c31a..d89dcfe 100644
--- a/src/util.c
+++ b/src/util.c
@@ -729,23 +729,38 @@ I18N_FetchName(Display *dpy2, Window w, char **winname)
{
int status;
XTextProperty text_prop;
- char **list;
- int num;
+ int rc = 0;
+
+ *winname = NULL;
status = XGetWMName(dpy2, w, &text_prop);
- if (!status || !text_prop.value || !text_prop.nitems) {
- *winname = NULL;
- return 0;
- }
- status = XmbTextPropertyToTextList(dpy2, &text_prop, &list, &num);
- if (status < Success || !num || !*list) {
- *winname = NULL;
- return 0;
+ if (status && text_prop.value && text_prop.nitems) {
+ char **list = NULL;
+ int num;
+
+ status = XmbTextPropertyToTextList(dpy2, &text_prop, &list, &num);
+ if (status >= Success && num && list && *list) {
+ XFree(text_prop.value);
+ *winname = strdup(*list);
+ XFreeStringList(list);
+ rc = 1;
+ }
+ else {
+ char *value = NULL;
+
+ /*
+ * If the system's locale support is broken (e.g., missing useful
+ * parts), the preceding Xmb call may fail.
+ */
+ if (XFetchName(dpy2, w, &value) && value != NULL) {
+ *winname = strdup(value);
+ XFree(value);
+ rc = 1;
+ }
+ }
}
- XFree(text_prop.value);
- *winname = (char *) strdup(*list);
- XFreeStringList(list);
- return 1;
+
+ return rc;
}
Status