From 1ad94dec1c63cbfb2b884da29a7b4267fa8e15bf Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 16 Dec 2002 22:01:15 +0000 Subject: [PATCH] use META_PROP_VALUE_STRING_AS_UTF8 so we convert old Latin-1 WM_NAME to 2002-12-16 Havoc Pennington * src/window-props.c: use META_PROP_VALUE_STRING_AS_UTF8 so we convert old Latin-1 WM_NAME to UTF-8 * src/xprops.h (enum): add META_PROP_VALUE_STRING_AS_UTF8 to get a latin1 string then convert. --- ChangeLog | 8 ++++++++ src/window-props.c | 4 ++-- src/xprops.c | 43 +++++++++++++++++++++++++++++++++++++++++-- src/xprops.h | 1 + 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index bedf4bdcd..f490ac0a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-12-16 Havoc Pennington + + * src/window-props.c: use META_PROP_VALUE_STRING_AS_UTF8 so + we convert old Latin-1 WM_NAME to UTF-8 + + * src/xprops.h (enum): add META_PROP_VALUE_STRING_AS_UTF8 to get a + latin1 string then convert. + 2002-12-15 Havoc Pennington * src/window.c (meta_window_new): get window name before anything diff --git a/src/window-props.c b/src/window-props.c index bcf639817..59bce1f45 100644 --- a/src/window-props.c +++ b/src/window-props.c @@ -228,7 +228,7 @@ init_wm_name (MetaDisplay *display, Atom property, MetaPropValue *value) { - value->type = META_PROP_VALUE_STRING; + value->type = META_PROP_VALUE_STRING_AS_UTF8; value->atom = XA_WM_NAME; } @@ -302,7 +302,7 @@ init_wm_icon_name (MetaDisplay *display, Atom property, MetaPropValue *value) { - value->type = META_PROP_VALUE_STRING; + value->type = META_PROP_VALUE_STRING_AS_UTF8; value->atom = XA_WM_ICON_NAME; } diff --git a/src/xprops.c b/src/xprops.c index 88f7e17d4..2c1f03169 100644 --- a/src/xprops.c +++ b/src/xprops.c @@ -897,6 +897,24 @@ get_task (MetaDisplay *display, False, req_type); } +static char* +latin1_to_utf8 (const char *text) +{ + GString *str; + const char *p; + + str = g_string_new (""); + + p = text; + while (*p) + { + g_string_append_unichar (str, *p); + ++p; + } + + return g_string_free (str, FALSE); +} + void meta_prop_get_values (MetaDisplay *display, Window xwindow, @@ -936,6 +954,7 @@ meta_prop_get_values (MetaDisplay *display, values[i].required_type = display->atom_utf8_string; break; case META_PROP_VALUE_STRING: + case META_PROP_VALUE_STRING_AS_UTF8: values[i].required_type = XA_STRING; break; case META_PROP_VALUE_MOTIF_HINTS: @@ -1047,6 +1066,27 @@ meta_prop_get_values (MetaDisplay *display, &values[i].v.str)) values[i].type = META_PROP_VALUE_INVALID; break; + case META_PROP_VALUE_STRING_AS_UTF8: + if (!latin1_string_from_results (&results, + &values[i].v.str)) + values[i].type = META_PROP_VALUE_INVALID; + else + { + char *new_str; + char *xmalloc_new_str; + + new_str = latin1_to_utf8 (values[i].v.str); + xmalloc_new_str = ag_Xmalloc (strlen (new_str) + 1); + if (xmalloc_new_str != NULL) + { + strcpy (xmalloc_new_str, new_str); + meta_XFree (values[i].v.str); + values[i].v.str = xmalloc_new_str; + } + + g_free (new_str); + } + break; case META_PROP_VALUE_MOTIF_HINTS: if (!motif_hints_from_results (&results, &values[i].v.motif_hints)) @@ -1119,9 +1159,8 @@ free_value (MetaPropValue *value) case META_PROP_VALUE_INVALID: break; case META_PROP_VALUE_UTF8: - meta_XFree (value->v.str); - break; case META_PROP_VALUE_STRING: + case META_PROP_VALUE_STRING_AS_UTF8: meta_XFree (value->v.str); break; case META_PROP_VALUE_MOTIF_HINTS: diff --git a/src/xprops.h b/src/xprops.h index 24180ee6f..fdf54615e 100644 --- a/src/xprops.h +++ b/src/xprops.h @@ -134,6 +134,7 @@ typedef enum META_PROP_VALUE_INVALID, META_PROP_VALUE_UTF8, META_PROP_VALUE_STRING, + META_PROP_VALUE_STRING_AS_UTF8, META_PROP_VALUE_MOTIF_HINTS, META_PROP_VALUE_CARDINAL, META_PROP_VALUE_WINDOW,