Mercurial > emacs
changeset 56879:fcda7ee97ef5
* xfns.c (x_set_name_internal): New function. Check if we shall call
xfree before ENCODE_UTF_8.
(x_set_name, x_set_title): Call x_set_name_internal.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Thu, 02 Sep 2004 16:15:48 +0000 |
parents | 0fd89f7ceec6 |
children | 6bb35c70240a |
files | src/ChangeLog src/xfns.c |
diffstat | 2 files changed, 92 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Thu Sep 02 09:46:47 2004 +0000 +++ b/src/ChangeLog Thu Sep 02 16:15:48 2004 +0000 @@ -1,3 +1,9 @@ +2004-09-02 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> + + * xfns.c (x_set_name_internal): New function. Check if we shall call + xfree before ENCODE_UTF_8. + (x_set_name, x_set_title): Call x_set_name_internal. + 2004-08-31 NAKAMURA Toshikazu <nr-tkz@nifty.com> (tiny change) * w32fns.c (w32_load_font): If a BDF font is already loaded, do not
--- a/src/xfns.c Thu Sep 02 09:46:47 2004 +0000 +++ b/src/xfns.c Thu Sep 02 16:15:48 2004 +0000 @@ -1560,6 +1560,90 @@ } +/* Set the WM name to NAME for frame F. Also set the icon name. + If the frame already has an icon name, use that, otherwise set the + icon name to NAME. */ + +static void +x_set_name_internal (f, name) + FRAME_PTR f; + Lisp_Object name; +{ + if (FRAME_X_WINDOW (f)) + { + BLOCK_INPUT; +#ifdef HAVE_X11R4 + { + XTextProperty text, icon; + int bytes, stringp; + int do_free_icon_value = 0, do_free_text_value = 0; + Lisp_Object coding_system; + + coding_system = Qcompound_text; + /* Note: Encoding strategy + + We encode NAME by compound-text and use "COMPOUND-TEXT" in + text.encoding. But, there are non-internationalized window + managers which don't support that encoding. So, if NAME + contains only ASCII and 8859-1 characters, encode it by + iso-latin-1, and use "STRING" in text.encoding hoping that + such window managers at least analyze this format correctly, + i.e. treat 8-bit bytes as 8859-1 characters. + + We may also be able to use "UTF8_STRING" in text.encoding + in the future which can encode all Unicode characters. + But, for the moment, there's no way to know that the + current window manager supports it or not. */ + text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp); + text.encoding = (stringp ? XA_STRING + : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); + text.format = 8; + text.nitems = bytes; + + /* Check early, because ENCODE_UTF_8 below may GC and name may be + relocated. */ + do_free_text_value = text.value != SDATA (name); + + if (NILP (f->icon_name)) + { + icon = text; + } + else + { + /* See the above comment "Note: Encoding strategy". */ + icon.value = x_encode_text (f->icon_name, coding_system, 0, + &bytes, &stringp); + icon.encoding = (stringp ? XA_STRING + : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); + icon.format = 8; + icon.nitems = bytes; + do_free_icon_value = icon.value != SDATA (f->icon_name); + } + +#ifdef USE_GTK + gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + SDATA (ENCODE_UTF_8 (name))); +#else /* not USE_GTK */ + XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); +#endif /* not USE_GTK */ + + XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon); + + if (do_free_icon_value) + xfree (icon.value); + if (do_free_text_value) + xfree (text.value); + } +#else /* not HAVE_X11R4 */ + XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + SDATA (name)); + XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + SDATA (name)); +#endif /* not HAVE_X11R4 */ + UNBLOCK_INPUT; + } +} + /* Change the name of frame F to NAME. If NAME is nil, set F's name to x_id_name. @@ -1615,73 +1699,7 @@ if (! NILP (f->title)) name = f->title; - if (FRAME_X_WINDOW (f)) - { - BLOCK_INPUT; -#ifdef HAVE_X11R4 - { - XTextProperty text, icon; - int bytes, stringp; - Lisp_Object coding_system; - - /* Note: Encoding strategy - - We encode NAME by compound-text and use "COMPOUND-TEXT" in - text.encoding. But, there are non-internationalized window - managers which don't support that encoding. So, if NAME - contains only ASCII and 8859-1 characters, encode it by - iso-latin-1, and use "STRING" in text.encoding hoping that - such window managers at least analyze this format correctly, - i.e. treat 8-bit bytes as 8859-1 characters. - - We may also be able to use "UTF8_STRING" in text.encoding - in the future which can encode all Unicode characters. - But, for the moment, there's no way to know that the - current window manager supports it or not. */ - coding_system = Qcompound_text; - text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp); - text.encoding = (stringp ? XA_STRING - : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); - text.format = 8; - text.nitems = bytes; - - if (NILP (f->icon_name)) - { - icon = text; - } - else - { - /* See the above comment "Note: Encoding strategy". */ - icon.value = x_encode_text (f->icon_name, coding_system, 0, - &bytes, &stringp); - icon.encoding = (stringp ? XA_STRING - : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); - icon.format = 8; - icon.nitems = bytes; - } -#ifdef USE_GTK - gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - SDATA (ENCODE_UTF_8 (name))); -#else /* not USE_GTK */ - XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); -#endif /* not USE_GTK */ - - XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon); - - if (!NILP (f->icon_name) - && icon.value != (unsigned char *) SDATA (f->icon_name)) - xfree (icon.value); - if (text.value != (unsigned char *) SDATA (name)) - xfree (text.value); - } -#else /* not HAVE_X11R4 */ - XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), - SDATA (name)); - XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), - SDATA (name)); -#endif /* not HAVE_X11R4 */ - UNBLOCK_INPUT; - } + x_set_name_internal (f, name); } /* This function should be called when the user's lisp code has @@ -1735,62 +1753,7 @@ else CHECK_STRING (name); - if (FRAME_X_WINDOW (f)) - { - BLOCK_INPUT; -#ifdef HAVE_X11R4 - { - XTextProperty text, icon; - int bytes, stringp; - Lisp_Object coding_system; - - coding_system = Qcompound_text; - /* See the comment "Note: Encoding strategy" in x_set_name. */ - text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp); - text.encoding = (stringp ? XA_STRING - : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); - text.format = 8; - text.nitems = bytes; - - if (NILP (f->icon_name)) - { - icon = text; - } - else - { - /* See the comment "Note: Encoding strategy" in x_set_name. */ - icon.value = x_encode_text (f->icon_name, coding_system, 0, - &bytes, &stringp); - icon.encoding = (stringp ? XA_STRING - : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); - icon.format = 8; - icon.nitems = bytes; - } - -#ifdef USE_GTK - gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - SDATA (ENCODE_UTF_8 (name))); -#else /* not USE_GTK */ - XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); -#endif /* not USE_GTK */ - - XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), - &icon); - - if (!NILP (f->icon_name) - && icon.value != (unsigned char *) SDATA (f->icon_name)) - xfree (icon.value); - if (text.value != (unsigned char *) SDATA (name)) - xfree (text.value); - } -#else /* not HAVE_X11R4 */ - XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), - SDATA (name)); - XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), - SDATA (name)); -#endif /* not HAVE_X11R4 */ - UNBLOCK_INPUT; - } + x_set_name_internal (f, name); } void