summaryrefslogtreecommitdiff
path: root/src/xfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xfns.c')
-rw-r--r--src/xfns.c223
1 files changed, 110 insertions, 113 deletions
diff --git a/src/xfns.c b/src/xfns.c
index 931d31bcedf..5ebdeca97d5 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -281,6 +281,8 @@ x_window_to_frame (dpyinfo, wdesc)
Lisp_Object tail, frame;
struct frame *f;
+ if (wdesc == None) return 0;
+
for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
@@ -330,6 +332,8 @@ x_any_window_to_frame (dpyinfo, wdesc)
struct frame *f, *found;
struct x_output *x;
+ if (wdesc == None) return NULL;
+
found = NULL;
for (tail = Vframe_list; GC_CONSP (tail) && !found; tail = XCDR (tail))
{
@@ -384,6 +388,8 @@ x_non_menubar_window_to_frame (dpyinfo, wdesc)
struct frame *f;
struct x_output *x;
+ if (wdesc == None) return 0;
+
for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
@@ -430,6 +436,8 @@ x_menubar_window_to_frame (dpyinfo, wdesc)
struct frame *f;
struct x_output *x;
+ if (wdesc == None) return 0;
+
for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
@@ -475,6 +483,8 @@ x_top_window_to_frame (dpyinfo, wdesc)
struct frame *f;
struct x_output *x;
+ if (wdesc == None) return 0;
+
for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
{
frame = XCAR (tail);
@@ -1550,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.
-
- 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. */
+/* 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. */
-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;
@@ -1612,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
@@ -1628,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;
@@ -1648,20 +1617,21 @@ 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 (name));
+ 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))
+ 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 */
@@ -1674,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. */
@@ -1725,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 (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
@@ -2633,6 +2606,28 @@ x_window (f)
#endif /* not USE_GTK */
#endif /* not USE_X_TOOLKIT */
+/* Verify that the icon position args for this window are valid. */
+
+static void
+x_icon_verify (f, parms)
+ struct frame *f;
+ Lisp_Object parms;
+{
+ Lisp_Object icon_x, icon_y;
+
+ /* Set the position of the icon. Note that twm groups all
+ icons in an icon window. */
+ icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
+ icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
+ if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
+ {
+ CHECK_NUMBER (icon_x);
+ CHECK_NUMBER (icon_y);
+ }
+ else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
+ error ("Both left and top icon corners of icon must be specified");
+}
+
/* Handle the icon stuff for this window. Perhaps later we might
want an x_set_icon_position which can be called interactively as
well. */
@@ -3117,6 +3112,8 @@ This function is an internal primitive--use `make-frame' instead. */)
tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
f->no_split = minibuffer_only || EQ (tem, Qt);
+ x_icon_verify (f, parms);
+
/* Create the X widget or window. */
#ifdef USE_X_TOOLKIT
x_window (f, window_prompting, minibuffer_only);