0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

x11: fix setting UTF-8 window titles for some special cases

Setting the WM_NAME/WM_ICON_NAME window properties didn't always work:
apparently there are some characters that can't be represented in the X
STRING or COMPOUND_TEXT encodings, such as U+2013 EN DASH. The function
Xutf8TextListToTextProperty partially converts the string, and returns
a value different from 'Success'. This means vo_x11_set_property_string
didn't set these window properties.

On most modern window managers, this is not a problem, since these use
the _NET_WM_NAME/_NET_ICON_NAME and the UTF8_STRING encoding. Some older
WMs like IceWM don't read these, and the window title remains blank.

It's not clear what exactly we should do in this situation, but fix it
by setting set the WM_NAME/WM_ICON_NAME properties as UTF8_TEXT. This
violates the ICCCM, but at least IceWM seems to handle this well.

See also:
  http://lists.freedesktop.org/archives/xorg/2004-September/003391.html
  http://lists.freedesktop.org/archives/xorg/2004-September/003395.html

Also fix a minor memory leak when conversion to COMPOUND_TEXT fails.
This commit is contained in:
wm4 2012-01-25 02:01:22 +01:00
parent 316658ad48
commit d5a8059f93

View File

@ -1005,6 +1005,15 @@ static int vo_x11_get_gnome_layer(struct vo_x11_state *x11, Window win)
return WIN_LAYER_NORMAL;
}
// set a X text property that expects a UTF8_STRING type
static void vo_x11_set_property_utf8(struct vo *vo, Atom name, const char *t)
{
struct vo_x11_state *x11 = vo->x11;
XChangeProperty(x11->display, x11->window, name, x11->XAUTF8_STRING, 8,
PropModeReplace, t, strlen(t));
}
// set a X text property that expects a STRING or COMPOUND_TEXT type
static void vo_x11_set_property_string(struct vo *vo, Atom name, const char *t)
{
@ -1015,17 +1024,14 @@ static void vo_x11_set_property_string(struct vo *vo, Atom name, const char *t)
XStdICCTextStyle, &prop) == Success)
{
XSetTextProperty(x11->display, x11->window, &prop, name);
XFree(prop.value);
} else {
// Strictly speaking this violates the ICCCM, but there's no way we
// can do this correctly.
vo_x11_set_property_utf8(vo, name, t);
}
}
// set a X text property that expects a UTF8_STRING type
static void vo_x11_set_property_utf8(struct vo *vo, Atom name, const char *t)
{
struct vo_x11_state *x11 = vo->x11;
XChangeProperty(x11->display, x11->window, name, x11->XAUTF8_STRING, 8,
PropModeReplace, t, strlen(t));
if (prop.value)
XFree(prop.value);
}
static void vo_x11_update_window_title(struct vo *vo)