[MPlayer-dev-eng] [PATCH] Use _NET_WM_NAME for UTF-8 title in X11 if supported

Adam Tlałka atlka at pg.gda.pl
Wed Jun 21 13:28:43 CEST 2006


On Wed, 21 Jun 2006 12:11:04 +0200, Sergey Pinaev <dfo at antex.ru> wrote:

> On Wed, 21 Jun 2006 11:55:05 +0200
> Adam Tlałka <atlka at pg.gda.pl> wrote:
>
>> Look at the man page:
>> 	On  startup of the main program, the portable "C" locale is selected as
>>        default.
>>
>> So if you just want use only "C" locale you don't need to use  
>> setlocale(3)
>> at all.
>
> Please look at the tread from the beginning.
>
OK - as Uoti pointed it out file names in filesystem not always
have encoding corresponding to current LANG setting.
If you change LANG some file names will be listed inproperly
but open(bytes_of_name_string) will work. Anyway if you are using
some DOS or smb filesystems with linux there are iocharset options there
so kernel translates names internally which could lead
to serious errors too - unaccessible files.

So IMHO name should olways be treated as just some sequence of bytes
representing chars encoded in UTF-8 of course and in case of broken  
sequences and
nonprintable chars (range 0-0x1F and 0x80-0x9F, 0xFE, 0xFF)
we should use some additional representation %hex_code for example
as it works in URL's for example "brown\007fox" -> "brown%07fox" etc.
so there will be no filenames which can mess with our terminal
or can't be changed or renamed. But this should work on very low level
so every program could use this reprezentation without changes.

Anyway it's user responsibility for proper iocharset options if he uses  
them
so if LC_CTYPE != *.UTF-8 we can use setlocale(LC_CTYPE, "") before  
translating
the file name to UTF-8 and then restore the default by setlocale(LC_CTYPE,  
"C").
We should remember original name for subseqent use.
It's only needed in case of non UTF-8 and non-C locales so maybe there  
should be
a configure change which detects this case and sets some defines to get  
this
behaviour. In other case it's not needed.
Anyway it's a background compatibility which leads to problems so setting  
this
as non-default option maybe some solution:

void vo_x11_store_name(Display *dpy, Window win, const char *name) {
	if(vo_wm_type & vo_wm_NAME) {
		XTextProperty name_prop;
#ifdef SUPPORT_NON_UTF8_LOCALES
		setlocale(LC_CTYPE, "");
		XmbTextListToTextProperty(dpy, (char **)&name, 1, XUTF8StringStyle,  
&name_prop);
		setlocale(LC_CTYPE, "C");
#else
		Xutf8TextListToTextProperty(dpy, (char **)&name,1, XUTF8StringStyle,  
&name_prop);
#endif
		XSetTextProperty(dpy, win, &name_prop, XA_NET_WM_NAME);
	} else {
		/* Backup for non NET WMs */
		XStoreName(dpy, win, name);
	}
}

Regards

-- 
Adam Tlałka       mailto:atlka at pg.gda.pl    ^v^ ^v^ ^v^
Computer Center,  Gdańsk University of Technology, Poland
PGP public key:   finger atlka at sunrise.pg.gda.pl



More information about the MPlayer-dev-eng mailing list