various fixes and gratuitous movements.
[bpt/emacs.git] / src / xfns.c
index edc538f..59fa8e0 100644 (file)
@@ -20,15 +20,15 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 /* Image support (XBM, XPM, PBM, JPEG, TIFF, GIF, PNG, GS). tooltips,
-   toolbars, busy-cursor, file selection dialog added by Gerd
+   tool-bars, busy-cursor, file selection dialog added by Gerd
    Moellmann <gerd@gnu.org>.  */
 
 /* Completely rewritten by Richard Stallman.  */
 
 /* Rewritten for X11 by Joseph Arceneaux */
 
-#include <signal.h>
 #include <config.h>
+#include <signal.h>
 #include <stdio.h>
 #include <math.h>
 
@@ -52,11 +52,6 @@ Boston, MA 02111-1307, USA.  */
 
 #ifdef HAVE_X_WINDOWS
 
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#else
-extern void abort ();
-#endif
 #include <ctype.h>
 
 /* On some systems, the character-composition stuff is broken in X11R5.  */
@@ -251,7 +246,7 @@ Lisp_Object Qx_frame_parameter;
 Lisp_Object Qx_resource_name;
 Lisp_Object Quser_position;
 Lisp_Object Quser_size;
-Lisp_Object Qdisplay;
+extern Lisp_Object Qdisplay;
 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
 Lisp_Object Qscreen_gamma;
 
@@ -259,7 +254,7 @@ Lisp_Object Qscreen_gamma;
 
 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
 extern Lisp_Object Qunsplittable, Qmenu_bar_lines, Qbuffer_predicate, Qtitle;
-extern Lisp_Object Qtoolbar_lines;
+extern Lisp_Object Qtool_bar_lines;
 
 extern Lisp_Object Vwindow_system_version;
 
@@ -294,12 +289,9 @@ check_x_frame (frame)
   FRAME_PTR f;
 
   if (NILP (frame))
-    f = selected_frame;
-  else
-    {
-      CHECK_LIVE_FRAME (frame, 0);
-      f = XFRAME (frame);
-    }
+    frame = selected_frame;
+  CHECK_LIVE_FRAME (frame, 0);
+  f = XFRAME (frame);
   if (! FRAME_X_P (f))
     error ("Non-X frame used");
   return f;
@@ -315,9 +307,10 @@ check_x_display_info (frame)
 {
   if (NILP (frame))
     {
-      if (FRAME_X_P (selected_frame)
-         && FRAME_LIVE_P (selected_frame))
-       return FRAME_X_DISPLAY_INFO (selected_frame);
+      struct frame *sf = XFRAME (selected_frame);
+      
+      if (FRAME_X_P (sf) && FRAME_LIVE_P (sf))
+       return FRAME_X_DISPLAY_INFO (sf);
       else if (x_display_list != 0)
        return x_display_list;
       else
@@ -351,13 +344,13 @@ x_window_to_frame (dpyinfo, wdesc)
   Lisp_Object tail, frame;
   struct frame *f;
 
-  for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
+  for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
     {
-      frame = XCONS (tail)->car;
+      frame = XCAR (tail);
       if (!GC_FRAMEP (frame))
         continue;
       f = XFRAME (frame);
-      if (f->output_data.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
+      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
        continue;
 #ifdef USE_X_TOOLKIT
       if ((f->output_data.x->edit_widget 
@@ -389,13 +382,13 @@ x_any_window_to_frame (dpyinfo, wdesc)
   struct frame *f;
   struct x_output *x;
 
-  for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
+  for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
     {
-      frame = XCONS (tail)->car;
+      frame = XCAR (tail);
       if (!GC_FRAMEP (frame))
         continue;
       f = XFRAME (frame);
-      if (f->output_data.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
+      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
        continue;
       x = f->output_data.x;
       /* This frame matches if the window is any of its widgets.  */
@@ -427,13 +420,13 @@ x_non_menubar_window_to_frame (dpyinfo, wdesc)
   struct frame *f;
   struct x_output *x;
 
-  for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
+  for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
     {
-      frame = XCONS (tail)->car;
+      frame = XCAR (tail);
       if (!GC_FRAMEP (frame))
         continue;
       f = XFRAME (frame);
-      if (f->output_data.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
+      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
        continue;
       x = f->output_data.x;
       /* This frame matches if the window is any of its widgets.  */
@@ -462,13 +455,13 @@ x_menubar_window_to_frame (dpyinfo, wdesc)
   struct frame *f;
   struct x_output *x;
 
-  for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
+  for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
     {
-      frame = XCONS (tail)->car;
+      frame = XCAR (tail);
       if (!GC_FRAMEP (frame))
         continue;
       f = XFRAME (frame);
-      if (f->output_data.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
+      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
        continue;
       x = f->output_data.x;
       /* Match if the window is this frame's menubar.  */
@@ -491,13 +484,13 @@ x_top_window_to_frame (dpyinfo, wdesc)
   struct frame *f;
   struct x_output *x;
 
-  for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
+  for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
     {
-      frame = XCONS (tail)->car;
+      frame = XCAR (tail);
       if (!GC_FRAMEP (frame))
         continue;
       f = XFRAME (frame);
-      if (f->output_data.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
+      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
        continue;
       x = f->output_data.x;
 
@@ -669,7 +662,7 @@ x_create_bitmap_from_file (f, file)
   /* XReadBitmapFile won't handle magic file names.  */
   if (fd == 0)
     return -1;
-  close (fd);
+  emacs_close (fd);
 
   filename = (char *) XSTRING (found)->data;
 
@@ -769,7 +762,7 @@ void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_scroll_bar_width P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_unsplittable P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_toolbar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
+void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object,
                                      Lisp_Object));
 void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object,
@@ -803,7 +796,7 @@ static struct x_frame_parm_table x_frame_parms[] =
   "unsplittable", x_set_unsplittable,
   "vertical-scroll-bars", x_set_vertical_scroll_bars,
   "visibility", x_set_visibility,
-  "toolbar-lines", x_set_toolbar_lines,
+  "tool-bar-lines", x_set_tool_bar_lines,
   "scroll-bar-foreground", x_set_scroll_bar_foreground,
   "scroll-bar-background", x_set_scroll_bar_background,
   "screen-gamma", x_set_screen_gamma
@@ -1027,18 +1020,18 @@ x_set_frame_parameters (f, alist)
            if (leftpos < 0)
              f->output_data.x->size_hint_flags |= XNegative;
          }
-       else if (CONSP (left) && EQ (XCONS (left)->car, Qminus)
-                && CONSP (XCONS (left)->cdr)
-                && INTEGERP (XCONS (XCONS (left)->cdr)->car))
+       else if (CONSP (left) && EQ (XCAR (left), Qminus)
+                && CONSP (XCDR (left))
+                && INTEGERP (XCAR (XCDR (left))))
          {
-           leftpos = - XINT (XCONS (XCONS (left)->cdr)->car);
+           leftpos = - XINT (XCAR (XCDR (left)));
            f->output_data.x->size_hint_flags |= XNegative;
          }
-       else if (CONSP (left) && EQ (XCONS (left)->car, Qplus)
-                && CONSP (XCONS (left)->cdr)
-                && INTEGERP (XCONS (XCONS (left)->cdr)->car))
+       else if (CONSP (left) && EQ (XCAR (left), Qplus)
+                && CONSP (XCDR (left))
+                && INTEGERP (XCAR (XCDR (left))))
          {
-           leftpos = XINT (XCONS (XCONS (left)->cdr)->car);
+           leftpos = XINT (XCAR (XCDR (left)));
          }
 
        if (EQ (top, Qminus))
@@ -1049,18 +1042,18 @@ x_set_frame_parameters (f, alist)
            if (toppos < 0)
              f->output_data.x->size_hint_flags |= YNegative;
          }
-       else if (CONSP (top) && EQ (XCONS (top)->car, Qminus)
-                && CONSP (XCONS (top)->cdr)
-                && INTEGERP (XCONS (XCONS (top)->cdr)->car))
+       else if (CONSP (top) && EQ (XCAR (top), Qminus)
+                && CONSP (XCDR (top))
+                && INTEGERP (XCAR (XCDR (top))))
          {
-           toppos = - XINT (XCONS (XCONS (top)->cdr)->car);
+           toppos = - XINT (XCAR (XCDR (top)));
            f->output_data.x->size_hint_flags |= YNegative;
          }
-       else if (CONSP (top) && EQ (XCONS (top)->car, Qplus)
-                && CONSP (XCONS (top)->cdr)
-                && INTEGERP (XCONS (XCONS (top)->cdr)->car))
+       else if (CONSP (top) && EQ (XCAR (top), Qplus)
+                && CONSP (XCDR (top))
+                && INTEGERP (XCAR (XCDR (top))))
          {
-           toppos = XINT (XCONS (XCONS (top)->cdr)->car);
+           toppos = XINT (XCAR (XCDR (top)));
          }
 
 
@@ -1205,7 +1198,7 @@ x_report_frame_params (f, alistptr)
                  (FRAME_VISIBLE_P (f) ? Qt
                   : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
   store_in_alist (alistptr, Qdisplay,
-                 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->car);
+                 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
 
   if (f->output_data.x->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
     tem = Qnil;
@@ -1237,7 +1230,7 @@ gamma_correct (f, color)
    If ALLOC is nonzero, allocate a new colormap cell.  */
 
 int
-defined_color (f, color, color_def, alloc)
+x_defined_color (f, color, color_def, alloc)
      FRAME_PTR f;
      char *color;
      XColor *color_def;
@@ -1348,9 +1341,9 @@ x_decode_color (f, arg, def)
   if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
     return def;
 
-  /* defined_color is responsible for coping with failures
+  /* x_defined_color is responsible for coping with failures
      by looking for a near-miss.  */
-  if (defined_color (f, XSTRING (arg)->data, &cdef, 1))
+  if (x_defined_color (f, XSTRING (arg)->data, &cdef, 1))
     return cdef.pixel;
 
   Fsignal (Qerror, Fcons (build_string ("undefined color"),
@@ -1405,7 +1398,7 @@ x_set_foreground_color (f, arg, oldval)
       XSetBackground (FRAME_X_DISPLAY (f), f->output_data.x->reverse_gc,
                      f->output_data.x->foreground_pixel);
       UNBLOCK_INPUT;
-      recompute_basic_faces (f);
+      update_face_from_frame_parameter (f, Qforeground_color, arg);
       if (FRAME_VISIBLE_P (f))
         redraw_frame (f);
     }
@@ -1416,9 +1409,6 @@ x_set_background_color (f, arg, oldval)
      struct frame *f;
      Lisp_Object arg, oldval;
 {
-  Pixmap temp;
-  int mask;
-
   unsigned long pixel
     = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
 
@@ -1447,7 +1437,7 @@ x_set_background_color (f, arg, oldval)
       }
       UNBLOCK_INPUT;
 
-      recompute_basic_faces (f);
+      update_face_from_frame_parameter (f, Qbackground_color, arg);
 
       if (FRAME_VISIBLE_P (f))
         redraw_frame (f);
@@ -1586,6 +1576,8 @@ x_set_mouse_color (f, arg, oldval)
 
   XFlush (FRAME_X_DISPLAY (f));
   UNBLOCK_INPUT;
+
+  update_face_from_frame_parameter (f, Qmouse_color, arg);
 }
 
 void
@@ -1631,6 +1623,8 @@ x_set_cursor_color (f, arg, oldval)
          x_update_cursor (f, 1);
        }
     }
+
+  update_face_from_frame_parameter (f, Qcursor_color, arg);
 }
 \f
 /* Set the border-color of frame F to value described by ARG.
@@ -1649,15 +1643,12 @@ x_set_border_color (f, arg, oldval)
      struct frame *f;
      Lisp_Object arg, oldval;
 {
-  unsigned char *str;
   int pix;
 
   CHECK_STRING (arg, 0);
-  str = XSTRING (arg)->data;
-
   pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
-
   x_set_border_pixel (f, pix);
+  update_face_from_frame_parameter (f, Qborder_color, arg);
 }
 
 /* Set the border-color of frame F to pixel value PIX.
@@ -1674,9 +1665,6 @@ x_set_border_pixel (f, pix)
 
   if (FRAME_X_WINDOW (f) != 0 && f->output_data.x->border_width > 0)
     {
-      Pixmap temp;
-      int mask;
-
       BLOCK_INPUT;
       XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
                        (unsigned long)pix);
@@ -1697,11 +1685,11 @@ x_set_cursor_type (f, arg, oldval)
       FRAME_DESIRED_CURSOR (f) = BAR_CURSOR;
       f->output_data.x->cursor_width = 2;
     }
-  else if (CONSP (arg) && EQ (XCONS (arg)->car, Qbar)
-          && INTEGERP (XCONS (arg)->cdr))
+  else if (CONSP (arg) && EQ (XCAR (arg), Qbar)
+          && INTEGERP (XCDR (arg)))
     {
       FRAME_DESIRED_CURSOR (f) = BAR_CURSOR;
-      f->output_data.x->cursor_width = XINT (XCONS (arg)->cdr);
+      f->output_data.x->cursor_width = XINT (XCDR (arg));
     }
   else
     /* Treat anything unknown as "box cursor".
@@ -1758,7 +1746,7 @@ x_icon_type (f)
 
   tem = assq_no_quit (Qicon_type, f->param_alist);
   if (CONSP (tem))
-    return XCONS (tem)->cdr;
+    return XCDR (tem);
   else
     return Qnil;
 }
@@ -1935,7 +1923,9 @@ x_set_menu_bar_lines (f, value, oldval)
      Lisp_Object value, oldval;
 {
   int nlines;
+#ifndef USE_X_TOOLKIT
   int olines = FRAME_MENU_BAR_LINES (f);
+#endif
 
   /* Right now, menu bars don't work properly in minibuf-only frames;
      most of the commands try to apply themselves to the minibuffer
@@ -1984,7 +1974,7 @@ x_set_menu_bar_lines (f, value, oldval)
    The frame's height doesn't change.  */
 
 void
-x_set_toolbar_lines (f, value, oldval)
+x_set_tool_bar_lines (f, value, oldval)
      struct frame *f;
      Lisp_Object value, oldval;
 {
@@ -1999,8 +1989,8 @@ x_set_toolbar_lines (f, value, oldval)
   /* Make sure we redisplay all windows in this frame.  */
   ++windows_or_buffers_changed;
 
-  delta = nlines - FRAME_TOOLBAR_LINES (f);
-  FRAME_TOOLBAR_LINES (f) = nlines;
+  delta = nlines - FRAME_TOOL_BAR_LINES (f);
+  FRAME_TOOL_BAR_LINES (f) = nlines;
   x_set_menu_bar_lines_1 (FRAME_ROOT_WINDOW (f), delta);
   adjust_glyphs (f);
 }
@@ -2034,7 +2024,8 @@ x_set_scroll_bar_foreground (f, value, oldval)
        (*condemn_scroll_bars_hook) (f);
       if (judge_scroll_bars_hook)
        (*judge_scroll_bars_hook) (f);
-      
+
+      update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
       redraw_frame (f);
     }
 }
@@ -2069,6 +2060,7 @@ x_set_scroll_bar_background (f, value, oldval)
       if (judge_scroll_bars_hook)
        (*judge_scroll_bars_hook) (f);
       
+      update_face_from_frame_parameter (f, Qscroll_bar_background, value);
       redraw_frame (f);
     }
 }
@@ -2580,6 +2572,7 @@ x_get_resource_string (attribute, class)
 {
   char *name_key;
   char *class_key;
+  struct frame *sf = SELECTED_FRAME ();
 
   /* Allocate space for the components, the dots which separate them,
      and the final '\0'.  */
@@ -2593,7 +2586,7 @@ x_get_resource_string (attribute, class)
           attribute);
   sprintf (class_key, "%s.%s", EMACS_CLASS, class);
 
-  return x_get_string_resource (FRAME_X_DISPLAY_INFO (selected_frame)->xrdb,
+  return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
                                name_key, class_key);
 }
 
@@ -2863,8 +2856,6 @@ x_figure_window_size (f, parms)
      Lisp_Object parms;
 {
   register Lisp_Object tem0, tem1, tem2;
-  int height, width, left, top;
-  register int geometry;
   long window_prompting = 0;
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
 
@@ -2918,18 +2909,18 @@ x_figure_window_size (f, parms)
          f->output_data.x->top_pos = 0;
          window_prompting |= YNegative;
        }
-      else if (CONSP (tem0) && EQ (XCONS (tem0)->car, Qminus)
-              && CONSP (XCONS (tem0)->cdr)
-              && INTEGERP (XCONS (XCONS (tem0)->cdr)->car))
+      else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
+              && CONSP (XCDR (tem0))
+              && INTEGERP (XCAR (XCDR (tem0))))
        {
-         f->output_data.x->top_pos = - XINT (XCONS (XCONS (tem0)->cdr)->car);
+         f->output_data.x->top_pos = - XINT (XCAR (XCDR (tem0)));
          window_prompting |= YNegative;
        }
-      else if (CONSP (tem0) && EQ (XCONS (tem0)->car, Qplus)
-              && CONSP (XCONS (tem0)->cdr)
-              && INTEGERP (XCONS (XCONS (tem0)->cdr)->car))
+      else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
+              && CONSP (XCDR (tem0))
+              && INTEGERP (XCAR (XCDR (tem0))))
        {
-         f->output_data.x->top_pos = XINT (XCONS (XCONS (tem0)->cdr)->car);
+         f->output_data.x->top_pos = XINT (XCAR (XCDR (tem0)));
        }
       else if (EQ (tem0, Qunbound))
        f->output_data.x->top_pos = 0;
@@ -2946,18 +2937,18 @@ x_figure_window_size (f, parms)
          f->output_data.x->left_pos = 0;
          window_prompting |= XNegative;
        }
-      else if (CONSP (tem1) && EQ (XCONS (tem1)->car, Qminus)
-              && CONSP (XCONS (tem1)->cdr)
-              && INTEGERP (XCONS (XCONS (tem1)->cdr)->car))
+      else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
+              && CONSP (XCDR (tem1))
+              && INTEGERP (XCAR (XCDR (tem1))))
        {
-         f->output_data.x->left_pos = - XINT (XCONS (XCONS (tem1)->cdr)->car);
+         f->output_data.x->left_pos = - XINT (XCAR (XCDR (tem1)));
          window_prompting |= XNegative;
        }
-      else if (CONSP (tem1) && EQ (XCONS (tem1)->car, Qplus)
-              && CONSP (XCONS (tem1)->cdr)
-              && INTEGERP (XCONS (XCONS (tem1)->cdr)->car))
+      else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
+              && CONSP (XCDR (tem1))
+              && INTEGERP (XCAR (XCDR (tem1))))
        {
-         f->output_data.x->left_pos = XINT (XCONS (XCONS (tem1)->cdr)->car);
+         f->output_data.x->left_pos = XINT (XCAR (XCDR (tem1)));
        }
       else if (EQ (tem1, Qunbound))
        f->output_data.x->left_pos = 0;
@@ -3142,7 +3133,6 @@ x_window (f, window_prompting, minibuffer_only)
         ? (f->output_data.x->menubar_widget->core.height
            + f->output_data.x->menubar_widget->core.border_width)
         : 0);
-    extern char *lwlib_toolkit_type;
 
 #if 0 /* Experimentally, we now get the right results
         for -geometry -0-0 without this.  24 Aug 96, rms.  */
@@ -3670,8 +3660,8 @@ This function is an internal primitive--use `make-frame' instead.")
     }
 
   /* Create fontsets from `global_fontset_alist' before handling fonts.  */
-  for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCONS (tem)->cdr)
-    fs_register_fontset (f, XCONS (tem)->car);
+  for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCDR (tem))
+    fs_register_fontset (f, XCAR (tem));
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
@@ -3773,7 +3763,7 @@ This function is an internal primitive--use `make-frame' instead.")
   
   x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
                       "menuBar", "MenuBar", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qtoolbar_lines, make_number (0),
+  x_default_parameter (f, parms, Qtool_bar_lines, make_number (0),
                       "toolBar", "ToolBar", RES_TYPE_NUMBER);
   x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
                       "scrollBarWidth", "ScrollBarWidth",
@@ -3807,13 +3797,13 @@ 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);
 
-  /* Create the X widget or window.  Add the toolbar height to the
+  /* Create the X widget or window.  Add the tool-bar height to the
      initial frame height so that the user gets a text display area of
      the size he specified with -g or via .Xdefaults.  Later changes
-     of the toolbar height don't change the frame size.  This is done
+     of the tool-bar height don't change the frame size.  This is done
      so that users can create tall Emacs frames without having to
-     guess how tall the toolbar will get.  */
-  f->height += FRAME_TOOLBAR_LINES (f);
+     guess how tall the tool-bar will get.  */
+  f->height += FRAME_TOOL_BAR_LINES (f);
 
 #ifdef USE_X_TOOLKIT
   x_window (f, window_prompting, minibuffer_only);
@@ -3851,7 +3841,7 @@ This function is an internal primitive--use `make-frame' instead.")
 
   /* Set up faces after all frame parameters are known.  */
   call1 (Qface_set_after_frame_default, frame);
-  
+
 #ifdef USE_X_TOOLKIT
   /* Create the menu bar.  */
   if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
@@ -3918,9 +3908,8 @@ x_get_focus_frame (frame)
 }
 
 \f
-DEFUN ("x-color-defined-p", Fx_color_defined_p, Sx_color_defined_p, 1, 2, 0,
-       "Return non-nil if color COLOR is supported on frame FRAME.\n\
-If FRAME is omitted or nil, use the selected frame.")
+DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
+  "Internal function called by `color-defined-p', which see.")
   (color, frame)
      Lisp_Object color, frame;
 {
@@ -3929,18 +3918,14 @@ If FRAME is omitted or nil, use the selected frame.")
 
   CHECK_STRING (color, 1);
 
-  if (defined_color (f, XSTRING (color)->data, &foo, 0))
+  if (x_defined_color (f, XSTRING (color)->data, &foo, 0))
     return Qt;
   else
     return Qnil;
 }
 
-DEFUN ("x-color-values", Fx_color_values, Sx_color_values, 1, 2, 0,
-  "Return a description of the color named COLOR on frame FRAME.\n\
-The value is a list of integer RGB values--(RED GREEN BLUE).\n\
-These values appear to range from 0 to 65280 or 65535, depending\n\
-on the system; white is (65280 65280 65280) or (65535 65535 65535).\n\
-If FRAME is omitted or nil, use the selected frame.")
+DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
+  "Internal function called by `color-values', which see.")
   (color, frame)
      Lisp_Object color, frame;
 {
@@ -3949,7 +3934,7 @@ If FRAME is omitted or nil, use the selected frame.")
 
   CHECK_STRING (color, 1);
 
-  if (defined_color (f, XSTRING (color)->data, &foo, 0))
+  if (x_defined_color (f, XSTRING (color)->data, &foo, 0))
     {
       Lisp_Object rgb[3];
 
@@ -3962,11 +3947,8 @@ If FRAME is omitted or nil, use the selected frame.")
     return Qnil;
 }
 
-DEFUN ("x-display-color-p", Fx_display_color_p, Sx_display_color_p, 0, 1, 0,
-  "Return t if the X display supports color.\n\
-The optional argument DISPLAY specifies which display to ask about.\n\
-DISPLAY should be either a frame or a display name (a string).\n\
-If omitted or nil, that stands for the selected frame's display.")
+DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
+  "Internal function called by `display-color-p', which see.")
   (display)
      Lisp_Object display;
 {
@@ -5259,10 +5241,10 @@ x_display_info_for_name (name)
 
   for (dpyinfo = x_display_list, names = x_display_name_list;
        dpyinfo;
-       dpyinfo = dpyinfo->next, names = XCONS (names)->cdr)
+       dpyinfo = dpyinfo->next, names = XCDR (names))
     {
       Lisp_Object tem;
-      tem = Fstring_equal (XCONS (XCONS (names)->car)->car, name);
+      tem = Fstring_equal (XCAR (XCAR (names)), name);
       if (!NILP (tem))
        return dpyinfo;
     }
@@ -5380,8 +5362,8 @@ DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
   Lisp_Object tail, result;
 
   result = Qnil;
-  for (tail = x_display_name_list; ! NILP (tail); tail = XCONS (tail)->cdr)
-    result = Fcons (XCONS (XCONS (tail)->car)->car, result);
+  for (tail = x_display_name_list; ! NILP (tail); tail = XCDR (tail))
+    result = Fcons (XCAR (XCAR (tail)), result);
 
   return result;
 }
@@ -5445,10 +5427,10 @@ Lisp_Object Qxbm;
 
 /* Keywords.  */
 
-Lisp_Object QCtype, QCdata, QCfile, QCascent, QCmargin, QCrelief;
-extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground;
+Lisp_Object QCtype, QCdata, QCascent, QCmargin, QCrelief;
+extern Lisp_Object QCwidth, QCheight, QCforeground, QCbackground, QCfile;
 Lisp_Object QCalgorithm, QCcolor_symbols, QCheuristic_mask;
-extern Lisp_Object QCimage;
+Lisp_Object QCindex;
 
 /* Other symbols.  */
 
@@ -5457,7 +5439,7 @@ Lisp_Object Qlaplace;
 /* Time in seconds after which images should be removed from the cache
    if not displayed.  */
 
-Lisp_Object Vimage_eviction_seconds;
+Lisp_Object Vimage_cache_eviction_delay;
 
 /* Function prototypes.  */
 
@@ -5529,23 +5511,18 @@ valid_image_p (object)
 }
 
 
-/* Display an error message with format string FORMAT and argument
-   ARG.  Signaling an error, e.g. when an image cannot be loaded,
-   is not a good idea because this would interrupt redisplay, and
-   the error message display would lead to another redisplay.  This
-   function therefore simply displays a message.  */
+/* Log error message with format string FORMAT and argument ARG.
+   Signaling an error, e.g. when an image cannot be loaded, is not a
+   good idea because this would interrupt redisplay, and the error
+   message display would lead to another redisplay.  This function
+   therefore simply displays a message.  */
 
 static void
 image_error (format, arg1, arg2)
      char *format;
      Lisp_Object arg1, arg2;
 {
-  Lisp_Object args[3];
-
-  args[0] = build_string (format);
-  args[1] = arg1;
-  args[2] = arg2;
-  Fmessage (make_number (DIM (args)), args);
+  add_to_log (format, arg1, arg2);
 }
 
 
@@ -5588,10 +5565,8 @@ struct image_keyword
 };
 
 
-static int parse_image_spec P_ ((Lisp_Object spec,
-                                struct image_keyword *keywords,
-                                int nkeywords, Lisp_Object type,
-                                int allow_other_keys_p));
+static int parse_image_spec P_ ((Lisp_Object, struct image_keyword *,
+                                int, Lisp_Object));
 static Lisp_Object image_spec_value P_ ((Lisp_Object, Lisp_Object, int *));
 
 
@@ -5599,17 +5574,14 @@ static Lisp_Object image_spec_value P_ ((Lisp_Object, Lisp_Object, int *));
    has the format (image KEYWORD VALUE ...).  One of the keyword/
    value pairs must be `:type TYPE'.  KEYWORDS is a vector of
    image_keywords structures of size NKEYWORDS describing other
-   allowed keyword/value pairs.  ALLOW_OTHER_KEYS_P non-zero means
-   allow KEYWORD/VALUE pairs other than those described by KEYWORDS
-   without checking them.  Value is non-zero if SPEC is valid.  */
+   allowed keyword/value pairs.  Value is non-zero if SPEC is valid.  */
 
 static int
-parse_image_spec (spec, keywords, nkeywords, type, allow_other_keys_p)
+parse_image_spec (spec, keywords, nkeywords, type)
      Lisp_Object spec;
      struct image_keyword *keywords;
      int nkeywords;
      Lisp_Object type;
-     int allow_other_keys_p;
 {
   int i;
   Lisp_Object plist;
@@ -5640,11 +5612,7 @@ parse_image_spec (spec, keywords, nkeywords, type, allow_other_keys_p)
          break;
 
       if (i == nkeywords)
-       {
-         if (!allow_other_keys_p)
-           return 0;
-         continue;
-       }
+       continue;
 
       /* Record that we recognized the keyword.  If a keywords
         was found more than once, it's an error.  */
@@ -5829,8 +5797,8 @@ prepare_image_for_display (f, img)
 
   /* If IMG doesn't have a pixmap yet, load it now, using the image
      type dependent loader function.  */
-  if (img->pixmap == 0)
-    img->type->load (f, img);
+  if (img->pixmap == 0 && !img->load_failed_p)
+    img->load_failed_p = img->type->load (f, img) == 0;
 }
      
 
@@ -5902,7 +5870,7 @@ x_alloc_image_color (f, img, color_name, dflt)
 
   xassert (STRINGP (color_name));
 
-  if (defined_color (f, XSTRING (color_name)->data, &color, 1))
+  if (x_defined_color (f, XSTRING (color_name)->data, &color, 1))
     {
       /* This isn't called frequently so we get away with simply
         reallocating the color vector to the needed size, here.  */
@@ -5986,14 +5954,14 @@ clear_image_cache (f, force_p)
 {
   struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
 
-  if (c && INTEGERP (Vimage_eviction_seconds))
+  if (c && INTEGERP (Vimage_cache_eviction_delay))
     {
       EMACS_TIME t;
       unsigned long old;
       int i, any_freed_p = 0;
 
       EMACS_GET_TIME (t);
-      old = EMACS_SECS (t) - XFASTINT (Vimage_eviction_seconds);
+      old = EMACS_SECS (t) - XFASTINT (Vimage_cache_eviction_delay);
       
       for (i = 0; i < c->used; ++i)
        {
@@ -6056,6 +6024,7 @@ lookup_image (f, spec)
   int i;
   unsigned hash;
   struct gcpro gcpro1;
+  EMACS_TIME now;
 
   /* F must be a window-system frame, and SPEC must be a valid image
      specification.  */
@@ -6075,18 +6044,15 @@ lookup_image (f, spec)
   /* If not found, create a new image and cache it.  */
   if (img == NULL)
     {
-      extern Lisp_Object QCenable, QCselect;
-      Lisp_Object tem;
-      int loading_failed_p;
-      
       img = make_image (spec, hash);
       cache_image (f, img);
-      loading_failed_p = img->type->load (f, img) == 0;
+      img->load_failed_p = img->type->load (f, img) == 0;
+      xassert (!interrupt_input_blocked);
 
       /* If we can't load the image, and we don't have a width and
         height, use some arbitrary width and height so that we can
         draw a rectangle for it.  */
-      if (loading_failed_p)
+      if (img->load_failed_p)
        {
          Lisp_Object value;
 
@@ -6134,6 +6100,10 @@ lookup_image (f, spec)
        }
     }
 
+  /* We're using IMG, so set its timestamp to `now'.  */
+  EMACS_GET_TIME (now);
+  img->timestamp = EMACS_SECS (now);
+  
   UNGCPRO;
   
   /* Value is the image id.  */
@@ -6282,7 +6252,7 @@ x_destroy_x_image (ximg)
 /* Put XImage XIMG into pixmap PIXMAP on frame F.  WIDTH and HEIGHT
    are width and height of both the image and pixmap.  */
 
-void
+static void
 x_put_x_image (f, ximg, pixmap, width, height)
      struct frame *f;
      XImage *ximg;
@@ -6344,7 +6314,6 @@ static int xbm_load_image_from_file P_ ((struct frame *f, struct image *img,
 static int xbm_image_p P_ ((Lisp_Object object));
 static int xbm_read_bitmap_file_data P_ ((char *, int *, int *,
                                          unsigned char **));
-static int xbm_read_hexint P_ ((FILE *));
 
 
 /* Indices of image specification fields in xbm_format, below.  */
@@ -6437,7 +6406,7 @@ xbm_image_p (object)
   struct image_keyword kw[XBM_LAST];
   
   bcopy (xbm_format, kw, sizeof kw);
-  if (!parse_image_spec (object, kw, XBM_LAST, Qxbm, 0))
+  if (!parse_image_spec (object, kw, XBM_LAST, Qxbm))
     return 0;
 
   xassert (EQ (kw[XBM_TYPE].value, Qxbm));
@@ -6643,8 +6612,6 @@ xbm_read_bitmap_file_data (file, width, height, data)
   /* Parse defines for width, height and hot-spots.  */
   while (LA1 == '#')
     {
-      char *p;
-
       match ();
       expect_ident ("define");
       expect (XBM_TK_IDENT);
@@ -6855,7 +6822,7 @@ xbm_load (f, img)
 
       /* Parse the list specification.  */
       bcopy (xbm_format, fmt, sizeof fmt);
-      parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm, 0);
+      parsed_p = parse_image_spec (img->spec, fmt, XBM_LAST, Qxbm);
       xassert (parsed_p);
 
       /* Get specified width, and height.  */
@@ -7014,7 +6981,7 @@ xpm_image_p (object)
 {
   struct image_keyword fmt[XPM_LAST];
   bcopy (xpm_format, fmt, sizeof fmt);
-  return (parse_image_spec (object, fmt, XPM_LAST, Qxpm, 0)
+  return (parse_image_spec (object, fmt, XPM_LAST, Qxpm)
          /* Either `:file' or `:data' must be present.  */
          && fmt[XPM_FILE].count + fmt[XPM_DATA].count == 1
          /* Either no `:color-symbols' or it's a list of conses
@@ -7098,6 +7065,7 @@ xpm_load (f, img)
       if (!STRINGP (file))
        {
          image_error ("Cannot find image file %s", specified_file, Qnil);
+         UNBLOCK_INPUT;
          return 0;
        }
       
@@ -7513,10 +7481,10 @@ x_laplace (f, img)
 
 /* Build a mask for image IMG which is used on frame F.  FILE is the
    name of an image file, for error messages.  HOW determines how to
-   determine the background color of IMG.  If it is an integer, take
-   that as the pixel value of the background.  Otherwise, determine
-   the background color of IMG heuristically.  Value is non-zero
-   if successful.  */
+   determine the background color of IMG.  If it is a list '(R G B)',
+   with R, G, and B being integers >= 0, take that as the color of the
+   background.  Otherwise, determine the background color of IMG
+   heuristically.  Value is non-zero if successful. */
 
 static int
 x_build_heuristic_mask (f, file, img, how)
@@ -7526,9 +7494,8 @@ x_build_heuristic_mask (f, file, img, how)
      Lisp_Object how;
 {
   Display *dpy = FRAME_X_DISPLAY (f);
-  Window win = FRAME_X_WINDOW (f);
   XImage *ximg, *mask_img;
-  int x, y, rc;
+  int x, y, rc, look_at_corners_p;
   unsigned long bg;
 
   BLOCK_INPUT;
@@ -7546,12 +7513,41 @@ x_build_heuristic_mask (f, file, img, how)
   ximg = XGetImage (dpy, img->pixmap, 0, 0, img->width, img->height,
                    ~0, ZPixmap);
 
-  /* Determine the background color of ximg.  If HOW is an integer,
-     take that as a pixel color.  Otherwise, try to determine the
-     color heuristically.  */
-  if (NATNUMP (how))
-    bg = XFASTINT (how);
-  else
+  /* Determine the background color of ximg.  If HOW is `(R G B)'
+     take that as color.  Otherwise, try to determine the color
+     heuristically. */
+  look_at_corners_p = 1;
+  
+  if (CONSP (how))
+    {
+      int rgb[3], i = 0;
+
+      while (i < 3
+            && CONSP (how)
+            && NATNUMP (XCAR (how)))
+       {
+         rgb[i] = XFASTINT (XCAR (how)) & 0xffff;
+         how = XCDR (how);
+       }
+
+      if (i == 3 && NILP (how))
+       {
+         char color_name[30];
+         XColor exact, color;
+         Colormap cmap;
+
+         sprintf (color_name, "#%04x%04x%04x", rgb[0], rgb[1], rgb[2]);
+         
+         cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
+         if (XLookupColor (dpy, cmap, color_name, &exact, &color))
+           {
+             bg = color.pixel;
+             look_at_corners_p = 0;
+           }
+       }
+    }
+  
+  if (look_at_corners_p)
     {
       unsigned long corners[4];
       int i, best_count;
@@ -7655,7 +7651,7 @@ pbm_image_p (object)
   
   bcopy (pbm_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, PBM_LAST, Qpbm, 0)
+  if (!parse_image_spec (object, fmt, PBM_LAST, Qpbm)
       || (fmt[PBM_ASCENT].count 
          && XFASTINT (fmt[PBM_ASCENT].value) > 100))
     return 0;
@@ -7710,7 +7706,7 @@ pbm_load (f, img)
   FILE *fp;
   char magic[2];
   int raw_p, x, y;
-  int width, height, max_color_idx = 0, value;
+  int width, height, max_color_idx = 0;
   XImage *ximg;
   Lisp_Object file, specified_file;
   enum {PBM_MONO, PBM_GRAY, PBM_COLOR} type;
@@ -7948,7 +7944,7 @@ static struct image_keyword png_format[PNG_LAST] =
   {":heuristic-mask",  IMAGE_DONT_CHECK_VALUE_TYPE,            0}
 };
 
-/* Structure describing the image type `gif'.  */
+/* Structure describing the image type `png'.  */
 
 static struct image_type png_type =
 {
@@ -7969,7 +7965,7 @@ png_image_p (object)
   struct image_keyword fmt[PNG_LAST];
   bcopy (png_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, PNG_LAST, Qpng, 1)
+  if (!parse_image_spec (object, fmt, PNG_LAST, Qpng)
       || (fmt[PNG_ASCENT].count 
          && XFASTINT (fmt[PNG_ASCENT].value) > 100))
     return 0;
@@ -8010,7 +8006,7 @@ png_load (f, img)
      struct image *img;
 {
   Lisp_Object file, specified_file;
-  int rc, x, y, i;
+  int x, y, i;
   XImage *ximg, *mask_img = NULL;
   struct gcpro gcpro1;
   png_struct *png_ptr = NULL;
@@ -8139,10 +8135,13 @@ png_load (f, img)
 
   /* Tell the PNG lib to handle gamma correction for us.  */
 
+#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
   if (png_get_sRGB (png_ptr, info_ptr, &intent))
     /* There is a special chunk in the image specifying the gamma.  */
     png_set_sRGB (png_ptr, info_ptr, intent);
-  else if (png_get_gAMA (png_ptr, info_ptr, &image_gamma))
+  else
+#endif
+  if (png_get_gAMA (png_ptr, info_ptr, &image_gamma))
     /* Image contains gamma information.  */
     png_set_gamma (png_ptr, screen_gamma, image_gamma);
   else
@@ -8387,7 +8386,7 @@ jpeg_image_p (object)
   
   bcopy (jpeg_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg, 0)
+  if (!parse_image_spec (object, fmt, JPEG_LAST, Qjpeg)
       || (fmt[JPEG_ASCENT].count 
          && XFASTINT (fmt[JPEG_ASCENT].value) > 100))
     return 0;
@@ -8423,7 +8422,7 @@ jpeg_load (f, img)
   JSAMPARRAY buffer;
   int row_stride, x, y;
   XImage *ximg = NULL;
-  int rc, value;
+  int rc;
   unsigned long *colors;
   int width, height;
   struct gcpro gcpro1;
@@ -8634,7 +8633,7 @@ tiff_image_p (object)
   struct image_keyword fmt[TIFF_LAST];
   bcopy (tiff_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, TIFF_LAST, Qtiff, 1)
+  if (!parse_image_spec (object, fmt, TIFF_LAST, Qtiff)
       || (fmt[TIFF_ASCENT].count 
          && XFASTINT (fmt[TIFF_ASCENT].value) > 100))
     return 0;
@@ -8810,7 +8809,7 @@ gif_image_p (object)
   struct image_keyword fmt[GIF_LAST];
   bcopy (gif_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, GIF_LAST, Qgif, 1)
+  if (!parse_image_spec (object, fmt, GIF_LAST, Qgif)
       || (fmt[GIF_ASCENT].count 
          && XFASTINT (fmt[GIF_ASCENT].value) > 100))
     return 0;
@@ -8835,7 +8834,6 @@ gif_load (f, img)
   struct gcpro gcpro1;
   Lisp_Object image;
   int ino, image_left, image_top, image_width, image_height;
-  int bg;
 
   specified_file = image_spec_value (img->spec, QCfile, NULL);
   file = x_find_image_file (specified_file);
@@ -8866,7 +8864,7 @@ gif_load (f, img)
       return 0;
     }
 
-  image = image_spec_value (img->spec, QCimage, NULL);
+  image = image_spec_value (img->spec, QCindex, NULL);
   ino = INTEGERP (image) ? XFASTINT (image) : 0;
   if (ino >= gif->ImageCount)
     {
@@ -8941,17 +8939,28 @@ gif_load (f, img)
       static int interlace_start[] = {0, 4, 2, 1};
       static int interlace_increment[] = {8, 8, 4, 2};
       int pass, inc;
+      int row = interlace_start[0];
 
-      for (pass = 0; pass < 4; ++pass)
+      pass = 0;
+
+      for (y = 0; y < image_height; y++)
        {
-         inc = interlace_increment[pass];
-         for (y = interlace_start[pass]; y < image_height; y += inc)
-           for (x = 0; x < image_width; ++x)
-             {
-               unsigned i = gif->SavedImages[ino].RasterBits[y * image_width + x];
-               XPutPixel (ximg, x + image_left, y + image_top, 
-                          pixel_colors[i]);
-             }
+         if (row >= image_height)
+           {
+             row = interlace_start[++pass];
+             while (row >= image_height)
+               row = interlace_start[++pass];
+           }
+         
+         for (x = 0; x < image_width; x++)
+           {
+             unsigned int i
+               = gif->SavedImages[ino].RasterBits[(y * image_width) + x];
+             XPutPixel (ximg, x + image_left, row + image_top,
+                        pixel_colors[i]);
+           }
+         
+         row += interlace_increment[pass];
        }
     }
   else
@@ -8987,9 +8996,9 @@ static int gs_image_p P_ ((Lisp_Object object));
 static int gs_load P_ ((struct frame *f, struct image *img));
 static void gs_clear_image P_ ((struct frame *f, struct image *img));
 
-/* The symbol `ghostscript' identifying images of this type.  */
+/* The symbol `postscript' identifying images of this type.  */
 
-Lisp_Object Qghostscript;
+Lisp_Object Qpostscript;
 
 /* Keyword symbols.  */
 
@@ -9035,7 +9044,7 @@ static struct image_keyword gs_format[GS_LAST] =
 
 static struct image_type gs_type =
 {
-  &Qghostscript,
+  &Qpostscript,
   gs_image_p,
   gs_load,
   gs_clear_image,
@@ -9069,7 +9078,7 @@ gs_image_p (object)
   
   bcopy (gs_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, GS_LAST, Qghostscript, 1)
+  if (!parse_image_spec (object, fmt, GS_LAST, Qpostscript)
       || (fmt[GS_ASCENT].count 
          && XFASTINT (fmt[GS_ASCENT].value) > 100))
     return 0;
@@ -9384,7 +9393,7 @@ DEFUN ("x-show-busy-cursor", Fx_show_busy_cursor,
        Sx_show_busy_cursor, 0, 0, 0,
   "Show a busy cursor, if not already shown.\n\
 Each call to this function must be matched by a call to\n\
-x-undisplay-busy-cursor to make the busy pointer disappear again.")
+`x-hide-busy-cursor' to make the busy pointer disappear again.")
   ()
 {
   ++busy_count;
@@ -9406,11 +9415,13 @@ x-undisplay-busy-cursor to make the busy pointer disappear again.")
                XSetWindowAttributes attrs;
 
                attrs.cursor = f->output_data.x->busy_cursor;
+               
                f->output_data.x->busy_window
                  = XCreateWindow (FRAME_X_DISPLAY (f),
                                   FRAME_OUTER_WINDOW (f),
                                   0, 0, 32000, 32000, 0, 0,
-                                  InputOnly, CopyFromParent,
+                                  InputOnly,
+                                  CopyFromParent,
                                   mask, &attrs);
              }
 
@@ -9427,8 +9438,8 @@ DEFUN ("x-hide-busy-cursor", Fx_hide_busy_cursor,
        Sx_hide_busy_cursor, 0, 1, 0,
   "Hide a busy-cursor.\n\
 A busy-cursor will actually be undisplayed when a matching\n\
-`x-undisplay-busy-cursor' is called for each `x-display-busy-cursor'\n\
-issued.  FORCE non-nil means undisplay the busy-cursor forcibly,\n\
+`x-hide-busy-cursor' is called for each `x-show-busy-cursor'\n\
+issued.  FORCE non-nil means hide the busy-cursor forcibly,\n\
 not counting calls.")
   (force)
      Lisp_Object force;
@@ -9497,11 +9508,10 @@ x_create_tip_frame (dpyinfo, parms)
   struct frame *f;
   Lisp_Object frame, tem;
   Lisp_Object name;
-  int minibuffer_only = 0;
   long window_prompting = 0;
   int width, height;
   int count = specpdl_ptr - specpdl;
-  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
+  struct gcpro gcpro1, gcpro2, gcpro3;
   struct kboard *kb;
 
   check_x ();
@@ -9559,8 +9569,8 @@ x_create_tip_frame (dpyinfo, parms)
     }
 
   /* Create fontsets from `global_fontset_alist' before handling fonts.  */
-  for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCONS (tem)->cdr)
-    fs_register_fontset (f, XCONS (tem)->car);
+  for (tem = Vglobal_fontset_alist; CONSP (tem); tem = XCDR (tem))
+    fs_register_fontset (f, XCAR (tem));
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
@@ -9725,19 +9735,20 @@ x_create_tip_frame (dpyinfo, parms)
 
 
 DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 4, 0,
-  "Show tooltip STRING on frame FRAME.\n\
+  "Show STRING in a \"tooltip\" window on frame FRAME.\n\
+A tooltip window is a small X window displaying STRING at\n\
+the current mouse position.\n\
 FRAME nil or omitted means use the selected frame.\n\
 PARMS is an optional list of frame parameters which can be\n\
 used to change the tooltip's appearance.\n\
 Automatically hide the tooltip after TIMEOUT seconds.\n\
 TIMEOUT nil means use the default timeout of 5 seconds.")
   (string, frame, parms, timeout)
-     Lisp_Object string, frame, parms;
+     Lisp_Object string, frame, parms, timeout;
 {
   struct frame *f;
   struct window *w;
   Window root, child;
-  struct it it;
   Lisp_Object buffer;
   struct buffer *old_buffer;
   struct text_pos pos;
@@ -9863,7 +9874,7 @@ TIMEOUT nil means use the default timeout of 5 seconds.")
 
 
 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
-  "Hide the current tooltip, if there is any.\n\
+  "Hide the current tooltip window, if there is any.\n\
 Value is t is tooltip was open, nil otherwise.")
   ()
 {
@@ -9922,7 +9933,7 @@ selection dialog's entry field, if MUSTMATCH is non-nil.")
      Lisp_Object prompt, dir, default_filename, mustmatch;
 {
   int result;
-  struct frame *f = selected_frame;
+  struct frame *f = SELECTED_FRAME ();
   Lisp_Object file = Qnil;
   Widget dialog, text, list, help;
   Arg al[10];
@@ -10090,7 +10101,7 @@ DEFUN ("lookup-image", Flookup_image, Slookup_image, 1, 1, 0, "")
   int id = -1;
   
   if (valid_image_p (spec))
-    id = lookup_image (selected_frame, spec);
+    id = lookup_image (SELECTED_FRAME (), spec);
 
   debug_print (spec);
   return make_number (id);
@@ -10173,8 +10184,6 @@ syms_of_xfns ()
   staticpro (&Quser_position);
   Quser_size = intern ("user-size");
   staticpro (&Quser_size);
-  Qdisplay = intern ("display");
-  staticpro (&Qdisplay);
   Qscroll_bar_foreground = intern ("scroll-bar-foreground");
   staticpro (&Qscroll_bar_foreground);
   Qscroll_bar_background = intern ("scroll-bar-background");
@@ -10284,12 +10293,12 @@ such a font.  This is especially effective for such large fonts as\n\
 Chinese, Japanese, and Korean.");
   Vx_pixel_size_width_font_regexp = Qnil;
 
-  DEFVAR_LISP ("image-eviction-seconds", &Vimage_eviction_seconds,
+  DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay,
      "Time after which cached images are removed from the cache.\n\
 When an image has not been displayed this many seconds, remove it\n\
 from the image cache.  Value must be an integer or nil with nil\n\
 meaning don't clear the cache.");
-  Vimage_eviction_seconds = make_number (30 * 60);
+  Vimage_cache_eviction_delay = make_number (30 * 60);
 
   DEFVAR_LISP ("image-types", &Vimage_types,
      "List of supported image types.\n\
@@ -10316,10 +10325,10 @@ Each element of the list is a symbol for a supported image type.");
   defsubr (&Sx_contour_region);
   defsubr (&Sx_uncontour_region);
 #endif
-  defsubr (&Sx_display_color_p);
+  defsubr (&Sxw_display_color_p);
   defsubr (&Sx_display_grayscale_p);
-  defsubr (&Sx_color_defined_p);
-  defsubr (&Sx_color_values);
+  defsubr (&Sxw_color_defined_p);
+  defsubr (&Sxw_color_values);
   defsubr (&Sx_server_max_request_size);
   defsubr (&Sx_server_vendor);
   defsubr (&Sx_server_version);
@@ -10369,8 +10378,6 @@ Each element of the list is a symbol for a supported image type.");
   staticpro (&Qxbm);
   QCtype = intern (":type");
   staticpro (&QCtype);
-  QCfile = intern (":file");
-  staticpro (&QCfile);
   QCalgorithm = intern (":algorithm");
   staticpro (&QCalgorithm);
   QCheuristic_mask = intern (":heuristic-mask");
@@ -10385,8 +10392,8 @@ Each element of the list is a symbol for a supported image type.");
   staticpro (&QCmargin);
   QCrelief = intern (":relief");
   staticpro (&QCrelief);
-  Qghostscript = intern ("ghostscript");
-  staticpro (&Qghostscript);
+  Qpostscript = intern ("postscript");
+  staticpro (&Qpostscript);
   QCloader = intern (":loader");
   staticpro (&QCloader);
   QCbounding_box = intern (":bounding-box");
@@ -10395,6 +10402,8 @@ Each element of the list is a symbol for a supported image type.");
   staticpro (&QCpt_width);
   QCpt_height = intern (":pt-height");
   staticpro (&QCpt_height);
+  QCindex = intern (":index");
+  staticpro (&QCindex);
   Qpbm = intern ("pbm");
   staticpro (&Qpbm);