summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-25 02:01:22 +0100
committerUoti Urpala <uau@mplayer2.org>2012-03-25 22:30:37 +0300
commit3e6e80a32c04e38c7d2fa77e4bcf1401e792dc7a (patch)
tree7afd049ef305d48ae176eb4ea20137f811c9b775
parent506d9beb666bae92a93b945594f4cb857e9a5ca5 (diff)
downloadmpv-3e6e80a32c04e38c7d2fa77e4bcf1401e792dc7a.tar.bz2
mpv-3e6e80a32c04e38c7d2fa77e4bcf1401e792dc7a.tar.xz
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
-rw-r--r--libvo/x11_common.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/libvo/x11_common.c b/libvo/x11_common.c
index cdbbc213b5..3df029e242 100644
--- a/libvo/x11_common.c
+++ b/libvo/x11_common.c
@@ -993,43 +993,32 @@ 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 STRING type
-static void vo_x11_set_property_string(struct vo *vo, Atom name, const char *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;
- XTextProperty prop = {0};
- int success;
-
- success = Xutf8TextListToTextProperty(x11->display, (char **)&t, 1,
- XStringStyle, &prop);
-
- // The call can fail if the string uses characters not in the STRING
- // encoding (which is latin-1 as far as I can tell). Try COMPOUND_TEXT
- // instead. (It is possible that COMPOUND_TEXT always works, but since the
- // difference in the type used for the property is visible to the Window
- // manager and the ICCCM seems to specify STRING, we're trying to be careful
- // and try STRING first.)
- // GTK seems to follow about the same fallback mechanism.
- if (success != Success) {
- XFree(prop.value);
- prop.value = NULL;
- success = Xutf8TextListToTextProperty(x11->display, (char **)&t, 1,
- XCompoundTextStyle, &prop);
- }
- if (success == Success)
- XSetTextProperty(x11->display, x11->window, &prop, name);
-
- XFree(prop.value);
+ XChangeProperty(x11->display, x11->window, name, x11->XAUTF8_STRING, 8,
+ PropModeReplace, t, strlen(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)
+// 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)
{
struct vo_x11_state *x11 = vo->x11;
+ XTextProperty prop = {0};
- XChangeProperty(x11->display, x11->window, name, x11->XAUTF8_STRING, 8,
- PropModeReplace, t, strlen(t));
+ if (Xutf8TextListToTextProperty(x11->display, (char **)&t, 1,
+ XStdICCTextStyle, &prop) == Success) {
+ XSetTextProperty(x11->display, x11->window, &prop, name);
+ } 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);
+ }
+
+ if (prop.value)
+ XFree(prop.value);
}
static void vo_x11_update_window_title(struct vo *vo)