Re: [dev] Problem with windows name

From: Страхиња Радић <contact_AT_strahinja.org>
Date: Mon, 10 Jul 2023 08:56:46 +0200

Adding to gettextprop in dwm.c:

        // ...
        if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems)
                return 0;
        FILE* log = fopen("/home/user/dwm.log", "at");
        fprintf(log, "---------------\n");
        fprintf(log, "atom = {%lu}\n", atom);
        fprintf(log, "text = {%s}\n", text);
        fprintf(log, "value = {%s}\n", name.value);
        fprintf(log, "encoding = {%lu}\n", name.encoding);
        fprintf(log, "format = {%d}\n", name.format);
        fprintf(log, "nitems = {%lu}\n", name.nitems);
        fclose(log);
        if (name.encoding == XA_STRING) {
        // ...

I got:

---------------
atom = {39}
text = {}
value = {this<E1>test.odt - LibreOffice Writer}
encoding = {31}
format = {8}
nitems = {34}
---------------
atom = {39}
text = {}
value = {this<E1>testL<FA>.odt - LibreOffice Writer}
encoding = {385}
format = {8}
nitems = {38}

So COMPOUND_TEXT sets the encoding field of XTextProperty to 385, a value not
listed in Xatom.h, while STRING sets it to 31 (XA_STRING). The code:

        if (name.encoding == XA_STRING) {
                strncpy(text, (char *)name.value, size - 1);
        } else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
&& n > 0 && *list) {
                strncpy(text, *list, size - 1);
                XFreeStringList(list);
        }

converts any string not having XA_STRING as encoding with
XmbTextPropertyToTextList[1].

The issue is that ISO 8859-1-encoded text, marked as XA_STRING, is copied with
strncpy, and treated as UTF-8 later on in drw_text in drw.c. It probably should
be converted to UTF-8 from the current locale, even when encoding field is set
to XA_STRING. However, when I commented out the first branch like this:

        /*if (name.encoding == XA_STRING) {
                strncpy(text, (char *)name.value, size - 1);
        } else*/ if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
&& n > 0 && *list) {
                strncpy(text, *list, size - 1);
                XFreeStringList(list);
        }

The document title in LibreOffice was shown correctly. *However*, the output
from slstatus, containing UTF-8 while having the encoding field also set to
XA_STRING, was *not* shown correctly, even though the description of
XmbTextPropertyToTextList states that

> The input text strings must be given in the current locale encoding (for
> XmbTextListToTextProperty and XwcTextListToTextProperty), or in UTF-8 encoding
> (for Xutf8TextListToTextProperty).

and my LANG is set to sr_RS.UTF-8 (so my "current locale encoding" should be
UTF-8).

So, this would be a workaround, but one with further potential issues.


[1]: https://linux.die.net/man/3/xmbtextpropertytotextlist
Received on Mon Jul 10 2023 - 08:56:46 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 10 2023 - 09:00:09 CEST