diff --git a/dwm.c b/dwm.c index 4465af1..dd9bbe2 100644 --- a/dwm.c +++ b/dwm.c @@ -899,23 +899,40 @@ getstate(Window w) return result; } +void +sub_non_ascii_chars(char *txt, unsigned int size) { + int i; + for (i = 0; i < size; i++){ + //fprintf(stderr, "%c at idx %d is %d\n", txt[i], i, txt[i]); + if (txt[i] > 127 || txt[i] < 0) { + txt[i] = '?'; + } + } + //fprintf(stderr, "OUT |%s|\n", txt); +} + int gettextprop(Window w, Atom atom, char *text, unsigned int size) { char **list = NULL; int n; XTextProperty name; + char buf[size-1]; if (!text || size == 0) return 0; text[0] = '\0'; if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems) return 0; - if (name.encoding == XA_STRING) - strncpy(text, (char *)name.value, size - 1); - else { + if (name.encoding == XA_STRING) { + strncpy(buf, (char *)name.value, size - 1); + sub_non_ascii_chars(buf, size-1); + strncpy(text, buf, size - 1); + } else { if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { - strncpy(text, *list, size - 1); + strncpy(buf, *list, size - 1); + sub_non_ascii_chars(buf, size -1); + strncpy(text, buf, size - 1); XFreeStringList(list); } }