Re: [hackers] [lsw][patch] Better handling of window title with non-ascii chars

2017-11-25 Thread Hiltjo Posthuma
On Fri, Nov 24, 2017 at 04:53:16PM +0100, Silvan Jegen wrote:
> On Fri, Nov 24, 2017 at 12:35 PM, Hiltjo Posthuma
>  wrote:
> > On Wed, Nov 22, 2017 at 10:47:39PM +0100, Julien Steinhauser wrote:
> >> Hello
> >>
> >> I've seen window title with non-ascii chars incorrectly displayed,
> >> using Xutf8TextPropertyToTextList instead of XmbTextPropertyToTextList
> >> as in the diff below fixed it.
> >>
> >> Regards
> >>
> >> Julien
> >>
> >> diff --git a/lsw.c b/lsw.c
> >> index fc40fef..9a5bee1 100644
> >> --- a/lsw.c
> >> +++ b/lsw.c
> >> @@ -55,7 +55,7 @@ getname(Window win) {
> >>   if(!XGetTextProperty(dpy, win, , netwmname) || prop.nitems == 0)
> >>   if(!XGetWMName(dpy, win, ) || prop.nitems == 0)
> >>   return "";
> >> - if(!XmbTextPropertyToTextList(dpy, , , ) && n > 0) {
> >> + if(!Xutf8TextPropertyToTextList(dpy, , , ) && n > 0) {
> >>   strncpy(buf, list[0], sizeof buf);
> >>   XFreeStringList(list);
> >>   } else
> >>
> >
> > Hey,
> >
> > Which OS, libc and locale do you use?
> > uname -a, locale, libc + version?
> >
> > On both OpenBSD and Linux glibc with UTF-8 locale it should not be needed.
> 
> I suspect that this is not standard-conform since the locale is set to
> the "C" one on startup of a program according to
> 
> https://linux.die.net/man/3/setlocale
> 
> until setlocale is called.
> 
> The "C" locale does not support multibyte characters by default it seems:
> 

It should not be needed normally, because the data is printed directly.
Then it also can work on all encodings without needing conversion. The
X11 manual is vague about the exact behaviour imho.

Like I said tested on both OpenBSD and Linux glibc it works fine atleast.

I'm waiting for Julien to provide more information about his system.

I think I'd prefer a patch like posted below, then it works in more encodings.
@Julien can you test with the below patch?

> "A program that hasn't called setlocale() can't expect to be able to
> use the multibyte
> interfaces reasonably anyway, so it doesn't matter that they default
> to byte mode when the program starts up." from [0]
> 
> 
> Cheers,
> 
> Silvan
> 
> [0] http://www.openwall.com/lists/musl/2014/06/27/4
> 

diff --git a/lsw.c b/lsw.c
index fc40fef..09622e0 100644
--- a/lsw.c
+++ b/lsw.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +16,8 @@ int
 main(int argc, char *argv[]) {
int i;
 
+   setlocale(LC_CTYPE, "");
+
if(!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "%s: cannot open display\n", argv[0]);
exit(EXIT_FAILURE);



Re: [hackers] [lsw][patch] Better handling of window title with non-ascii chars

2017-11-24 Thread Silvan Jegen
On Fri, Nov 24, 2017 at 12:35 PM, Hiltjo Posthuma
 wrote:
> On Wed, Nov 22, 2017 at 10:47:39PM +0100, Julien Steinhauser wrote:
>> Hello
>>
>> I've seen window title with non-ascii chars incorrectly displayed,
>> using Xutf8TextPropertyToTextList instead of XmbTextPropertyToTextList
>> as in the diff below fixed it.
>>
>> Regards
>>
>> Julien
>>
>> diff --git a/lsw.c b/lsw.c
>> index fc40fef..9a5bee1 100644
>> --- a/lsw.c
>> +++ b/lsw.c
>> @@ -55,7 +55,7 @@ getname(Window win) {
>>   if(!XGetTextProperty(dpy, win, , netwmname) || prop.nitems == 0)
>>   if(!XGetWMName(dpy, win, ) || prop.nitems == 0)
>>   return "";
>> - if(!XmbTextPropertyToTextList(dpy, , , ) && n > 0) {
>> + if(!Xutf8TextPropertyToTextList(dpy, , , ) && n > 0) {
>>   strncpy(buf, list[0], sizeof buf);
>>   XFreeStringList(list);
>>   } else
>>
>
> Hey,
>
> Which OS, libc and locale do you use?
> uname -a, locale, libc + version?
>
> On both OpenBSD and Linux glibc with UTF-8 locale it should not be needed.

I suspect that this is not standard-conform since the locale is set to
the "C" one on startup of a program according to

https://linux.die.net/man/3/setlocale

until setlocale is called.

The "C" locale does not support multibyte characters by default it seems:

"A program that hasn't called setlocale() can't expect to be able to
use the multibyte
interfaces reasonably anyway, so it doesn't matter that they default
to byte mode when the program starts up." from [0]


Cheers,

Silvan

[0] http://www.openwall.com/lists/musl/2014/06/27/4



Re: [hackers] [lsw][patch] Better handling of window title with non-ascii chars

2017-11-24 Thread Hiltjo Posthuma
On Wed, Nov 22, 2017 at 10:47:39PM +0100, Julien Steinhauser wrote:
> Hello
> 
> I've seen window title with non-ascii chars incorrectly displayed,
> using Xutf8TextPropertyToTextList instead of XmbTextPropertyToTextList
> as in the diff below fixed it.
> 
> Regards
> 
> Julien
> 
> diff --git a/lsw.c b/lsw.c
> index fc40fef..9a5bee1 100644
> --- a/lsw.c
> +++ b/lsw.c
> @@ -55,7 +55,7 @@ getname(Window win) {
>   if(!XGetTextProperty(dpy, win, , netwmname) || prop.nitems == 0)
>   if(!XGetWMName(dpy, win, ) || prop.nitems == 0)
>   return "";
> - if(!XmbTextPropertyToTextList(dpy, , , ) && n > 0) {
> + if(!Xutf8TextPropertyToTextList(dpy, , , ) && n > 0) {
>   strncpy(buf, list[0], sizeof buf);
>   XFreeStringList(list);
>   } else
> 

Hey,

Which OS, libc and locale do you use?
uname -a, locale, libc + version?

On both OpenBSD and Linux glibc with UTF-8 locale it should not be needed.

-- 
Kind regards,
Hiltjo



Re: [hackers] [lsw][patch] Better handling of window title with non-ascii chars

2017-11-24 Thread Silvan Jegen
Hi

On Wed, Nov 22, 2017 at 10:47 PM, Julien Steinhauser  wrote:
> I've seen window title with non-ascii chars incorrectly displayed,
> using Xutf8TextPropertyToTextList instead of XmbTextPropertyToTextList
> as in the diff below fixed it.

We do not seem to be using locale.h and its setlocale function here so
using the UTF8 variant of that call is what we have to use to make it
work if people are using UTF8-encoded properties. As long as we are
happy with just supporting UTF8 this is the right function to call so
this patch looks good to me.


Cheers,

Silvan



[hackers] [lsw][patch] Better handling of window title with non-ascii chars

2017-11-22 Thread Julien Steinhauser
Hello

I've seen window title with non-ascii chars incorrectly displayed,
using Xutf8TextPropertyToTextList instead of XmbTextPropertyToTextList
as in the diff below fixed it.

Regards

Julien

diff --git a/lsw.c b/lsw.c
index fc40fef..9a5bee1 100644
--- a/lsw.c
+++ b/lsw.c
@@ -55,7 +55,7 @@ getname(Window win) {
if(!XGetTextProperty(dpy, win, , netwmname) || prop.nitems == 0)
if(!XGetWMName(dpy, win, ) || prop.nitems == 0)
return "";
-   if(!XmbTextPropertyToTextList(dpy, , , ) && n > 0) {
+   if(!Xutf8TextPropertyToTextList(dpy, , , ) && n > 0) {
strncpy(buf, list[0], sizeof buf);
XFreeStringList(list);
} else