summaryrefslogtreecommitdiff
path: root/src/xfns.c
diff options
context:
space:
mode:
authorJan Djärv <jan.h.d@swipnet.se>2004-09-02 16:15:48 +0000
committerJan Djärv <jan.h.d@swipnet.se>2004-09-02 16:15:48 +0000
commitb10daec70920a4d17425bdfe816f2e4ec1a793e1 (patch)
tree5c3fc5a93377643f3d2a69500f33f8583f7fd0de /src/xfns.c
parentc3829a8e2fa294b3b15c4827d11c12653e2df3c3 (diff)
downloademacs-b10daec70920a4d17425bdfe816f2e4ec1a793e1.tar.gz
* 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.
Diffstat (limited to 'src/xfns.c')
-rw-r--r--src/xfns.c187
1 files changed, 75 insertions, 112 deletions
diff --git a/src/xfns.c b/src/xfns.c
index 8368e62a445..5ebdeca97d5 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1560,61 +1560,15 @@ x_encode_text (string, coding_system, selectionp, text_bytes, stringp)
}
-/* Change the name of frame F to NAME. If NAME is nil, set F's name to
- x_id_name.
-
- If EXPLICIT is non-zero, that indicates that lisp code is setting the
- name; if NAME is a string, set F's name to NAME and set
- F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
+/* 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. */
- If EXPLICIT is zero, that indicates that Emacs redisplay code is
- suggesting a new name, which lisp code should override; if
- F->explicit_name is set, ignore the new name; otherwise, set it. */
-
-void
-x_set_name (f, name, explicit)
- struct frame *f;
+static void
+x_set_name_internal (f, name)
+ FRAME_PTR f;
Lisp_Object name;
- int explicit;
{
- /* Make sure that requests from lisp code override requests from
- Emacs redisplay code. */
- if (explicit)
- {
- /* If we're switching from explicit to implicit, we had better
- update the mode lines and thereby update the title. */
- if (f->explicit_name && NILP (name))
- update_mode_lines = 1;
-
- f->explicit_name = ! NILP (name);
- }
- else if (f->explicit_name)
- return;
-
- /* If NAME is nil, set the name to the x_id_name. */
- if (NILP (name))
- {
- /* Check for no change needed in this very common case
- before we do any consing. */
- if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
- SDATA (f->name)))
- return;
- name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
- }
- else
- CHECK_STRING (name);
-
- /* Don't change the name if it's already NAME. */
- if (! NILP (Fstring_equal (name, f->name)))
- return;
-
- f->name = name;
-
- /* For setting the frame title, the title parameter should override
- the name parameter. */
- if (! NILP (f->title))
- name = f->title;
-
if (FRAME_X_WINDOW (f))
{
BLOCK_INPUT;
@@ -1622,8 +1576,10 @@ x_set_name (f, name, explicit)
{
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
@@ -1638,13 +1594,16 @@ x_set_name (f, name, explicit)
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;
+ /* 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;
@@ -1658,7 +1617,9 @@ x_set_name (f, name, explicit)
: 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)));
@@ -1668,10 +1629,9 @@ x_set_name (f, name, explicit)
XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
- if (!NILP (f->icon_name)
- && icon.value != (unsigned char *) SDATA (f->icon_name))
+ if (do_free_icon_value)
xfree (icon.value);
- if (text.value != (unsigned char *) SDATA (name))
+ if (do_free_text_value)
xfree (text.value);
}
#else /* not HAVE_X11R4 */
@@ -1684,6 +1644,64 @@ x_set_name (f, name, explicit)
}
}
+/* Change the name of frame F to NAME. If NAME is nil, set F's name to
+ x_id_name.
+
+ If EXPLICIT is non-zero, that indicates that lisp code is setting the
+ name; if NAME is a string, set F's name to NAME and set
+ F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
+
+ If EXPLICIT is zero, that indicates that Emacs redisplay code is
+ suggesting a new name, which lisp code should override; if
+ F->explicit_name is set, ignore the new name; otherwise, set it. */
+
+void
+x_set_name (f, name, explicit)
+ struct frame *f;
+ Lisp_Object name;
+ int explicit;
+{
+ /* Make sure that requests from lisp code override requests from
+ Emacs redisplay code. */
+ if (explicit)
+ {
+ /* If we're switching from explicit to implicit, we had better
+ update the mode lines and thereby update the title. */
+ if (f->explicit_name && NILP (name))
+ update_mode_lines = 1;
+
+ f->explicit_name = ! NILP (name);
+ }
+ else if (f->explicit_name)
+ return;
+
+ /* If NAME is nil, set the name to the x_id_name. */
+ if (NILP (name))
+ {
+ /* Check for no change needed in this very common case
+ before we do any consing. */
+ if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
+ SDATA (f->name)))
+ return;
+ name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
+ }
+ else
+ CHECK_STRING (name);
+
+ /* Don't change the name if it's already NAME. */
+ if (! NILP (Fstring_equal (name, f->name)))
+ return;
+
+ f->name = name;
+
+ /* For setting the frame title, the title parameter should override
+ the name parameter. */
+ if (! NILP (f->title))
+ name = f->title;
+
+ x_set_name_internal (f, name);
+}
+
/* This function should be called when the user's lisp code has
specified a name for the frame; the name will override any set by the
redisplay code. */
@@ -1735,62 +1753,7 @@ x_set_title (f, name, old_name)
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