(Fx_list_fonts): Use a cache stored in FRAME_X_SCREEN.
[bpt/emacs.git] / src / xfns.c
index ea41cc8..4770023 100644 (file)
@@ -86,7 +86,6 @@ extern void free_frame_menubar ();
 #define min(a,b) ((a) < (b) ? (a) : (b))
 #define max(a,b) ((a) > (b) ? (a) : (b))
 
-#ifdef HAVE_X11
 /* X Resource data base */
 static XrmDatabase xrdb;
 
@@ -136,6 +135,10 @@ Lisp_Object Vx_no_window_manager;
 
 Lisp_Object Vmouse_depressed;
 
+/* For now, we have just one x_display structure since we only support
+   one X display.  */
+static struct x_screen the_x_screen;
+
 extern unsigned int x_mouse_x, x_mouse_y, x_mouse_grabbed;
 
 /* Atom for indicating window state to the window manager. */
@@ -156,19 +159,6 @@ extern Atom Xatom_wm_window_moved;     /* When the WM moves us. */
 /* EditRes protocol */
 extern Atom Xatom_editres_name;
 
-#else  /* X10 */
-
-/* Default size of an Emacs window.  */
-static char *default_window = "=80x24+0+0";
-
-#define MAXICID 80
-char iconidentity[MAXICID];
-#define ICONTAG "emacs@"
-char minibuffer_iconidentity[MAXICID];
-#define MINIBUFFER_ICONTAG "minibuffer@"
-
-#endif /* X10 */
-
 /* The last 23 bits of the timestamp of the last mouse button event. */
 Time mouse_timestamp;
 
@@ -219,7 +209,6 @@ Lisp_Object Qcursor_type;
 Lisp_Object Qfont;
 Lisp_Object Qforeground_color;
 Lisp_Object Qgeometry;
-/* Lisp_Object Qicon; */
 Lisp_Object Qicon_left;
 Lisp_Object Qicon_top;
 Lisp_Object Qicon_type;
@@ -228,6 +217,7 @@ Lisp_Object Qleft;
 Lisp_Object Qmouse_color;
 Lisp_Object Qnone;
 Lisp_Object Qparent_id;
+Lisp_Object Qscroll_bar_width;
 Lisp_Object Qsuppress_icon;
 Lisp_Object Qtop;
 Lisp_Object Qundefined_color;
@@ -415,6 +405,7 @@ void x_set_autolower ();
 void x_set_vertical_scroll_bars ();
 void x_set_visibility ();
 void x_set_menu_bar_lines ();
+void x_set_scroll_bar_width ();
 
 static struct x_frame_parm_table x_frame_parms[] =
 {
@@ -434,6 +425,7 @@ static struct x_frame_parm_table x_frame_parms[] =
   "vertical-scroll-bars", x_set_vertical_scroll_bars,
   "visibility", x_set_visibility,
   "menu-bar-lines", x_set_menu_bar_lines,
+  "scroll-bar-width", x_set_scroll_bar_width,
 };
 
 /* Attach the `x-frame-parameter' properties to
@@ -680,18 +672,12 @@ defined_color (color, color_def, alloc)
   Colormap screen_colormap;
 
   BLOCK_INPUT;
-#ifdef HAVE_X11
   screen_colormap
     = DefaultColormap (x_current_display, XDefaultScreen (x_current_display));
 
   foo = XParseColor (x_current_display, screen_colormap, color, color_def);
   if (foo && alloc)
     foo = XAllocColor (x_current_display, screen_colormap, color_def);
-#else
-  foo = XParseColor (color, color_def);
-  if (foo && alloc)
-    foo = XGetHardwareColor (color_def);
-#endif /* not HAVE_X11 */
   UNBLOCK_INPUT;
 
   if (foo)
@@ -719,13 +705,8 @@ x_decode_color (arg, def)
   else if (strcmp (XSTRING (arg)->data, "white") == 0)
     return WHITE_PIX_DEFAULT;
 
-#ifdef HAVE_X11
   if (x_screen_planes == 1)
     return def;
-#else
-  if (DISPLAY_CELLS == 1)
-    return def;
-#endif
 
   if (defined_color (XSTRING (arg)->data, &cdef, 1))
     return cdef.pixel;
@@ -749,14 +730,12 @@ x_set_foreground_color (f, arg, oldval)
   f->display.x->foreground_pixel = x_decode_color (arg, BLACK_PIX_DEFAULT);
   if (FRAME_X_WINDOW (f) != 0)
     {
-#ifdef HAVE_X11
       BLOCK_INPUT;
       XSetForeground (x_current_display, f->display.x->normal_gc,
                      f->display.x->foreground_pixel);
       XSetBackground (x_current_display, f->display.x->reverse_gc,
                      f->display.x->foreground_pixel);
       UNBLOCK_INPUT;
-#endif                         /* HAVE_X11 */
       recompute_basic_faces (f);
       if (FRAME_VISIBLE_P (f))
         redraw_frame (f);
@@ -776,7 +755,6 @@ x_set_background_color (f, arg, oldval)
   if (FRAME_X_WINDOW (f) != 0)
     {
       BLOCK_INPUT;
-#ifdef HAVE_X11
       /* The main frame area. */
       XSetBackground (x_current_display, f->display.x->normal_gc,
                      f->display.x->background_pixel);
@@ -794,11 +772,6 @@ x_set_background_color (f, arg, oldval)
                                SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)),
                                f->display.x->background_pixel);
       }
-#else
-      temp = XMakeTile (f->display.x->background_pixel);
-      XChangeBackground (FRAME_X_WINDOW (f), temp);
-      XFreePixmap (temp);
-#endif                         /* not HAVE_X11 */
       UNBLOCK_INPUT;
 
       recompute_basic_faces (f);
@@ -825,7 +798,6 @@ x_set_mouse_color (f, arg, oldval)
     f->display.x->mouse_pixel = f->display.x->foreground_pixel;
 
   BLOCK_INPUT;
-#ifdef HAVE_X11
 
   /* It's not okay to crash if the user selects a screwy cursor.  */
   x_catch_errors ();
@@ -895,13 +867,6 @@ x_set_mouse_color (f, arg, oldval)
     XRecolorCursor (x_current_display, cross_cursor,
                     &fore_color, &back_color);
   }
-#else /* X10 */
-  cursor = XCreateCursor (16, 16, MouseCursor, MouseMask,
-                         0, 0,
-                         f->display.x->mouse_pixel,
-                         f->display.x->background_pixel,
-                         GXcopy);
-#endif /* X10 */
 
   if (FRAME_X_WINDOW (f) != 0)
     {
@@ -911,7 +876,7 @@ x_set_mouse_color (f, arg, oldval)
   if (cursor != f->display.x->text_cursor && f->display.x->text_cursor != 0)
       XFreeCursor (XDISPLAY f->display.x->text_cursor);
   f->display.x->text_cursor = cursor;
-#ifdef HAVE_X11
+
   if (nontext_cursor != f->display.x->nontext_cursor
       && f->display.x->nontext_cursor != 0)
       XFreeCursor (XDISPLAY f->display.x->nontext_cursor);
@@ -925,7 +890,6 @@ x_set_mouse_color (f, arg, oldval)
       && f->display.x->cross_cursor != 0)
       XFreeCursor (XDISPLAY f->display.x->cross_cursor);
   f->display.x->cross_cursor = cross_cursor;
-#endif /* HAVE_X11 */
 
   XFlushQueue ();
   UNBLOCK_INPUT;
@@ -955,14 +919,12 @@ x_set_cursor_color (f, arg, oldval)
 
   if (FRAME_X_WINDOW (f) != 0)
     {
-#ifdef HAVE_X11
       BLOCK_INPUT;
       XSetBackground (x_current_display, f->display.x->cursor_gc,
                      f->display.x->cursor_pixel);
       XSetForeground (x_current_display, f->display.x->cursor_gc,
                      fore_pixel);
       UNBLOCK_INPUT;
-#endif /* HAVE_X11 */
 
       if (FRAME_VISIBLE_P (f))
        {
@@ -994,13 +956,6 @@ x_set_border_color (f, arg, oldval)
   CHECK_STRING (arg, 0);
   str = XSTRING (arg)->data;
 
-#ifndef HAVE_X11
-  if (!strcmp (str, "grey") || !strcmp (str, "Grey")
-      || !strcmp (str, "gray") || !strcmp (str, "Gray"))
-    pix = -1;
-  else
-#endif /* X10 */
-
     pix = x_decode_color (arg, BLACK_PIX_DEFAULT);
 
   x_set_border_pixel (f, pix);
@@ -1022,19 +977,8 @@ x_set_border_pixel (f, pix)
       int mask;
 
       BLOCK_INPUT;
-#ifdef HAVE_X11
       XSetWindowBorder (x_current_display, FRAME_X_WINDOW (f),
                         pix);
-#else
-      if (pix < 0)
-        temp = XMakePixmap ((Bitmap) XStoreBitmap (gray_width, gray_height,
-                                                  gray_bits),
-                            BLACK_PIX_DEFAULT, WHITE_PIX_DEFAULT);
-      else
-        temp = XMakeTile (pix);
-      XChangeBorder (FRAME_X_WINDOW (f), temp);
-      XFreePixmap (XDISPLAY temp);
-#endif /* not HAVE_X11 */
       UNBLOCK_INPUT;
 
       if (FRAME_VISIBLE_P (f))
@@ -1383,11 +1327,24 @@ x_set_vertical_scroll_bars (f, arg, oldval)
        x_set_window_size (f, 0, FRAME_WIDTH (f), FRAME_HEIGHT (f));
     }
 }
+
+void
+x_set_scroll_bar_width (f, arg, oldval)
+     struct frame *f;
+     Lisp_Object arg, oldval;
+{
+  if (XFASTINT (arg) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f))
+    {
+      int wid = FONT_WIDTH (f->display.x->font);
+      FRAME_SCROLL_BAR_PIXEL_WIDTH (f) = XFASTINT (arg);
+      FRAME_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
+      if (FRAME_X_WINDOW (f))
+       x_set_window_size (f, 0, FRAME_WIDTH (f), FRAME_HEIGHT (f));
+    }
+}
 \f
 /* Subroutines of creating an X frame.  */
 
-#ifdef HAVE_X11
-
 /* Make sure that Vx_resource_name is set to a reasonable value.  */
 static void
 validate_x_resource_name ()
@@ -1421,14 +1378,14 @@ extern XrmDatabase x_load_resources ();
 
 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
   "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
-This uses `NAME.ATTRIBUTE' as the key and `Emacs.INSTANCE' as the\n\
+This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
 class, where INSTANCE is the name under which Emacs was invoked, or\n\
 the name specified by the `-name' or `-rn' command-line arguments.\n\
 \n\
 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
 class, respectively.  You must specify both of them or neither.\n\
-If you specify them, the key is `NAME.COMPONENT.ATTRIBUTE'\n\
-and the class is `Emacs.INSTANCE.SUBCLASS'.")
+If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
+and the class is `Emacs.CLASS.SUBCLASS'.")
   (attribute, class, component, subclass)
      Lisp_Object attribute, class, component, subclass;
 {
@@ -1525,38 +1482,6 @@ x_get_resource_string (attribute, class)
   return x_get_string_resource (xrdb, name_key, class_key);
 }
 
-#else  /* X10 */
-
-DEFUN ("x-get-default", Fx_get_default, Sx_get_default, 1, 1, 0,
-  "Get X default ATTRIBUTE from the system, or nil if no default.\n\
-Value is a string (when not nil) and ATTRIBUTE is also a string.\n\
-The defaults are specified in the file `~/.Xdefaults'.")
-  (arg)
-     Lisp_Object arg;
-{
-  register unsigned char *value;
-
-  CHECK_STRING (arg, 1);
-
-  value = (unsigned char *) XGetDefault (XDISPLAY 
-                                        XSTRING (Vinvocation_name)->data,
-                                        XSTRING (arg)->data);
-  if (value == 0)
-    /* Try reversing last two args, in case this is the buggy version of X.  */
-    value = (unsigned char *) XGetDefault (XDISPLAY
-                                          XSTRING (arg)->data,
-                                          XSTRING (Vinvocation_name)->data);
-  if (value != 0)
-    return build_string (value);
-  else
-    return (Qnil);
-}
-
-#define Fx_get_resource(attribute, class, component, subclass) \
-  Fx_get_default (attribute)
-
-#endif /* X10 */
-
 /* Types we might convert a resource string into.  */
 enum resource_types
   {
@@ -1719,7 +1644,6 @@ The value of `left' or `top' may be an integer or `-'.\n\
   return result;
 }
 
-#ifdef HAVE_X11
 /* Calculate the desired size and position of this window,
    and return the flags saying which aspects were specified.
 
@@ -1771,7 +1695,7 @@ x_figure_window_size (f, parms)
 
   f->display.x->vertical_scroll_bar_extra
     = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
-       ? VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f)
+       ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f)
        : 0);
   f->display.x->pixel_width = CHAR_TO_PIXEL_WIDTH (f, f->width);
   f->display.x->pixel_height = CHAR_TO_PIXEL_HEIGHT (f, f->height);
@@ -1840,9 +1764,9 @@ XSetWMProtocols (dpy, w, protocols, count)
 \f
 #ifdef USE_X_TOOLKIT
 
-/* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS
-   and WM_DELETE_WINDOW, then add them.  (They may already be present
-   because of the toolkit (Motif adds them, for example, but Xt doesn't).  */
+/* WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them.  (They may
+   already be present because of the toolkit (Motif adds some of them,
+   for example, but Xt doesn't).  */
 
 static void
 hack_wm_protocols (widget)
@@ -1852,6 +1776,7 @@ hack_wm_protocols (widget)
   Window w = XtWindow (widget);
   int need_delete = 1;
   int need_focus = 1;
+  int need_save = 1;
 
   BLOCK_INPUT;
   {
@@ -1868,16 +1793,18 @@ hack_wm_protocols (widget)
       while (nitems > 0)
        {
          nitems--;
-         if (atoms [nitems] == Xatom_wm_delete_window)   need_delete = 0;
-         else if (atoms [nitems] == Xatom_wm_take_focus) need_focus = 0;
+         if (atoms[nitems] == Xatom_wm_delete_window)      need_delete = 0;
+         else if (atoms[nitems] == Xatom_wm_take_focus)    need_focus = 0;
+         else if (atoms[nitems] == Xatom_wm_save_yourself) need_save = 0;
        }
     if (atoms) XFree ((char *) atoms);
   }
   {
     Atom props [10];
     int count = 0;
-    if (need_delete) props [count++] = Xatom_wm_delete_window;
-    if (need_focus)  props [count++] = Xatom_wm_take_focus;
+    if (need_delete) props[count++] = Xatom_wm_delete_window;
+    if (need_focus)  props[count++] = Xatom_wm_take_focus;
+    if (need_save)   props[count++] = Xatom_wm_save_yourself;
     if (count)
       XChangeProperty (dpy, w, Xatom_wm_protocols, XA_ATOM, 32, PropModeAppend,
                       (unsigned char *) props, count);
@@ -2247,7 +2174,6 @@ x_make_gc (f)
 
   UNBLOCK_INPUT;
 }
-#endif /* HAVE_X11 */
 
 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
        1, 1, 0,
@@ -2261,7 +2187,6 @@ be shared by the new frame.")
   (parms)
      Lisp_Object parms;
 {
-#ifdef HAVE_X11
   struct frame *f;
   Lisp_Object frame, tem;
   Lisp_Object name;
@@ -2382,8 +2307,10 @@ be shared by the new frame.")
   x_default_parameter (f, parms, Qborder_color, build_string ("black"),
                       "borderColor", "BorderColor", string);
 
-  x_default_parameter (f, parms, Qmenu_bar_lines, make_number (0),
+  x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
                       "menuBarLines", "MenuBarLines", number);
+  x_default_parameter (f, parms, Qscroll_bar_width, make_number (12),
+                      "scrollBarWidth", "ScrollBarWidth", number);
 
   f->display.x->parent_desc = ROOT_WINDOW;
   window_prompting = x_figure_window_size (f, parms);
@@ -2444,6 +2371,10 @@ be shared by the new frame.")
   tem = x_get_arg (parms, Qunsplittable, 0, 0, boolean);
   f->no_split = minibuffer_only || EQ (tem, Qt);
 
+  FRAME_X_SCREEN (f) = &the_x_screen;
+  FRAME_X_SCREEN (f)->reference_count++;
+  the_x_screen.x_display_value = x_current_display;
+
   UNGCPRO;
 
   /* It is now ok to make the frame official
@@ -2471,247 +2402,6 @@ be shared by the new frame.")
   }
 
   return unbind_to (count, frame);
-#else /* X10 */
-  struct frame *f;
-  Lisp_Object frame, tem;
-  Lisp_Object name;
-  int pixelwidth, pixelheight;
-  Cursor cursor;
-  int height, width;
-  Window parent;
-  Pixmap temp;
-  int minibuffer_only = 0;
-  Lisp_Object vscroll, hscroll;
-
-  if (x_current_display == 0)
-    error ("X windows are not in use or not initialized");
-
-  name = Fassq (Qname, parms);
-
-  tem = x_get_arg (parms, Qminibuffer, 0, 0, symbol);
-  if (EQ (tem, Qnone))
-    f = make_frame_without_minibuffer (Qnil);
-  else if (EQ (tem, Qonly))
-    {
-      f = make_minibuffer_frame ();
-      minibuffer_only = 1;
-    }
-  else if (EQ (tem, Qnil) || EQ (tem, Qunbound))
-    f = make_frame (1);
-  else
-    f = make_frame_without_minibuffer (tem);
-
-  parent = ROOT_WINDOW;
-
-  XSET (frame, Lisp_Frame, f);
-  f->output_method = output_x_window;
-  f->display.x = (struct x_display *) xmalloc (sizeof (struct x_display));
-  bzero (f->display.x, sizeof (struct x_display));
-
-  /* Some temporary default values for height and width. */
-  width = 80;
-  height = 40;
-  f->display.x->left_pos = -1;
-  f->display.x->top_pos = -1;
-
-  /* Give the frame a default name (which may be overridden with PARMS).  */
-
-  strncpy (iconidentity, ICONTAG, MAXICID);
-  if (gethostname (&iconidentity[sizeof (ICONTAG) - 1],
-                  (MAXICID - 1) - sizeof (ICONTAG)))
-    iconidentity[sizeof (ICONTAG) - 2] = '\0';
-  f->name = build_string (iconidentity);
-
-  /* Extract some window parameters from the supplied values.
-     These are the parameters that affect window geometry.  */
-
-  tem = x_get_arg (parms, Qfont, "BodyFont", 0, string);
-  if (EQ (tem, Qunbound))
-    tem = build_string ("9x15");
-  x_set_font (f, tem, Qnil);
-  x_default_parameter (f, parms, Qborder_color,
-                      build_string ("black"), "Border", 0, string);
-  x_default_parameter (f, parms, Qbackground_color,
-                      build_string ("white"), "Background", 0, string);
-  x_default_parameter (f, parms, Qforeground_color,
-                      build_string ("black"), "Foreground", 0, string);
-  x_default_parameter (f, parms, Qmouse_color,
-                      build_string ("black"), "Mouse", 0, string);
-  x_default_parameter (f, parms, Qcursor_color,
-                      build_string ("black"), "Cursor", 0, string);
-  x_default_parameter (f, parms, Qborder_width,
-                      make_number (2), "BorderWidth", 0, number);
-  x_default_parameter (f, parms, Qinternal_border_width,
-                      make_number (4), "InternalBorderWidth", 0, number);
-  x_default_parameter (f, parms, Qauto_raise,
-                      Qnil, "AutoRaise", 0, boolean);
-
-  hscroll = EQ (x_get_arg (parms, Qhorizontal_scroll_bar, 0, 0, boolean), Qt);
-  vscroll = EQ (x_get_arg (parms, Qvertical_scroll_bar, 0, 0, boolean), Qt);
-
-  if (f->display.x->internal_border_width < 0)
-    f->display.x->internal_border_width = 0;
-
-  tem = x_get_arg (parms, Qwindow_id, 0, 0, number);
-  if (!EQ (tem, Qunbound))
-    {
-      WINDOWINFO_TYPE wininfo;
-      int nchildren;
-      Window *children, root;
-
-      CHECK_NUMBER (tem, 0);
-      FRAME_X_WINDOW (f) = (Window) XINT (tem);
-
-      BLOCK_INPUT;
-      XGetWindowInfo (FRAME_X_WINDOW (f), &wininfo);
-      XQueryTree (FRAME_X_WINDOW (f), &parent, &nchildren, &children);
-      xfree (children);
-      UNBLOCK_INPUT;
-
-      height = PIXEL_TO_CHAR_HEIGHT (f, wininfo.height);
-      width  = PIXEL_TO_CHAR_WIDTH  (f, wininfo.width);
-      f->display.x->left_pos = wininfo.x;
-      f->display.x->top_pos = wininfo.y;
-      FRAME_SET_VISIBILITY (f, wininfo.mapped != 0);
-      f->display.x->border_width = wininfo.bdrwidth;
-      f->display.x->parent_desc = parent;
-    }
-  else
-    {
-      tem = x_get_arg (parms, Qparent_id, 0, 0, number);
-      if (!EQ (tem, Qunbound))
-       {
-         CHECK_NUMBER (tem, 0);
-         parent = (Window) XINT (tem);
-       }
-      f->display.x->parent_desc = parent;
-      tem = x_get_arg (parms, Qheight, 0, 0, number);
-      if (EQ (tem, Qunbound))
-       {
-         tem = x_get_arg (parms, Qwidth, 0, 0, number);
-         if (EQ (tem, Qunbound))
-           {
-             tem = x_get_arg (parms, Qtop, 0, 0, number);
-             if (EQ (tem, Qunbound))
-               tem = x_get_arg (parms, Qleft, 0, 0, number);
-           }
-       }
-      /* Now TEM is Qunbound if no edge or size was specified.
-        In that case, we must do rubber-banding.  */
-      if (EQ (tem, Qunbound))
-       {
-         tem = x_get_arg (parms, Qgeometry, 0, 0, number);
-         x_rubber_band (f,
-                        &f->display.x->left_pos, &f->display.x->top_pos,
-                        &width, &height,
-                        (XTYPE (tem) == Lisp_String
-                         ? (char *) XSTRING (tem)->data : ""),
-                        XSTRING (f->name)->data,
-                        !NILP (hscroll), !NILP (vscroll));
-       }
-      else
-       {
-         /* Here if at least one edge or size was specified.
-            Demand that they all were specified, and use them.  */
-         tem = x_get_arg (parms, Qheight, 0, 0, number);
-         if (EQ (tem, Qunbound))
-           error ("Height not specified");
-         CHECK_NUMBER (tem, 0);
-         height = XINT (tem);
-
-         tem = x_get_arg (parms, Qwidth, 0, 0, number);
-         if (EQ (tem, Qunbound))
-           error ("Width not specified");
-         CHECK_NUMBER (tem, 0);
-         width = XINT (tem);
-
-         tem = x_get_arg (parms, Qtop, 0, 0, number);
-         if (EQ (tem, Qunbound))
-           error ("Top position not specified");
-         CHECK_NUMBER (tem, 0);
-         f->display.x->left_pos = XINT (tem);
-
-         tem = x_get_arg (parms, Qleft, 0, 0, number);
-         if (EQ (tem, Qunbound))
-           error ("Left position not specified");
-         CHECK_NUMBER (tem, 0);
-         f->display.x->top_pos = XINT (tem);
-       }
-
-      pixelwidth  = CHAR_TO_PIXEL_WIDTH  (f, width);
-      pixelheight = CHAR_TO_PIXEL_HEIGHT (f, height);
-      
-      BLOCK_INPUT;
-      FRAME_X_WINDOW (f)
-       = XCreateWindow (parent,
-                        f->display.x->left_pos,   /* Absolute horizontal offset */
-                        f->display.x->top_pos,    /* Absolute Vertical offset */
-                        pixelwidth, pixelheight,
-                        f->display.x->border_width,
-                        BLACK_PIX_DEFAULT, WHITE_PIX_DEFAULT);
-      UNBLOCK_INPUT;
-      if (FRAME_X_WINDOW (f) == 0)
-       error ("Unable to create window.");
-    }
-
-  /* Install the now determined height and width
-     in the windows and in phys_lines and desired_lines.  */
-  change_frame_size (f, height, width, 1, 0);
-  XSelectInput (FRAME_X_WINDOW (f), KeyPressed | ExposeWindow
-               | ButtonPressed | ButtonReleased | ExposeRegion | ExposeCopy
-               | EnterWindow | LeaveWindow | UnmapWindow );
-  x_set_resize_hint (f);
-
-  /* Tell the server the window's default name.  */
-  XStoreName (XDISPLAY FRAME_X_WINDOW (f), XSTRING (f->name)->data);
-
-  /* Now override the defaults with all the rest of the specified
-     parms.  */
-  tem = x_get_arg (parms, Qunsplittable, 0, 0, boolean);
-  f->no_split = minibuffer_only || EQ (tem, Qt);
-
-  /* Do not create an icon window if the caller says not to */
-  if (!EQ (x_get_arg (parms, Qsuppress_icon, 0, 0, boolean), Qt)
-      || f->display.x->parent_desc != ROOT_WINDOW)
-    {
-      x_text_icon (f, iconidentity);
-      x_default_parameter (f, parms, Qicon_type, Qnil,
-                          "BitmapIcon", 0, symbol);
-    }
-
-  /* Tell the X server the previously set values of the
-     background, border and mouse colors; also create the mouse cursor.  */
-  BLOCK_INPUT;
-  temp = XMakeTile (f->display.x->background_pixel);
-  XChangeBackground (FRAME_X_WINDOW (f), temp);
-  XFreePixmap (temp);
-  UNBLOCK_INPUT;
-  x_set_border_pixel (f, f->display.x->border_pixel);
-
-  x_set_mouse_color (f, Qnil, Qnil);
-
-  /* Now override the defaults with all the rest of the specified parms.  */
-
-  Fmodify_frame_parameters (frame, parms);
-
-  /* Make the window appear on the frame and enable display.  */
-  {
-    Lisp_Object visibility;
-
-    visibility = x_get_arg (parms, Qvisibility, 0, 0, symbol);
-    if (EQ (visibility, Qunbound))
-      visibility = Qt;
-
-    if (! EQ (visibility, Qicon)
-       && ! NILP (visibility))
-      x_make_window_visible (f);
-  }
-
-  SET_FRAME_GARBAGED (f);
-
-  Vframe_list = Fcons (frame, Vframe_list);
-  return frame;
-#endif /* X10 */
 }
 
 Lisp_Object
@@ -2757,84 +2447,6 @@ DEFUN ("unfocus-frame", Funfocus_frame, Sunfocus_frame, 0, 0, 0,
   return Qnil;
 }
 \f
-#ifndef HAVE_X11
-/* Computes an X-window size and position either from geometry GEO
-   or with the mouse.
-
-   F is a frame.  It specifies an X window which is used to
-   determine which display to compute for.  Its font, borders
-   and colors control how the rectangle will be displayed.
-
-   X and Y are where to store the positions chosen.
-   WIDTH and HEIGHT are where to store the sizes chosen.
-
-   GEO is the geometry that may specify some of the info.
-   STR is a prompt to display.
-   HSCROLL and VSCROLL say whether we have horiz and vert scroll bars.  */
-
-int
-x_rubber_band (f, x, y, width, height, geo, str, hscroll, vscroll)
-     struct frame *f;
-     int *x, *y, *width, *height;
-     char *geo;
-     char *str;
-     int hscroll, vscroll;
-{
-  OpaqueFrame frame;
-  Window tempwindow;
-  WindowInfo wininfo;
-  int border_color;
-  int background_color;
-  Lisp_Object tem;
-  int mask;
-
-  BLOCK_INPUT;
-
-  background_color = f->display.x->background_pixel;
-  border_color = f->display.x->border_pixel;
-
-  frame.bdrwidth = f->display.x->border_width;
-  frame.border = XMakeTile (border_color);
-  frame.background = XMakeTile (background_color);
-  tempwindow = XCreateTerm (str, "emacs", geo, default_window, &frame, 10, 5,
-                           (2 * f->display.x->internal_border_width
-                            + (vscroll ? VSCROLL_WIDTH : 0)),
-                           (2 * f->display.x->internal_border_width
-                            + (hscroll ? HSCROLL_HEIGHT : 0)),
-                           width, height, f->display.x->font,
-                           FONT_WIDTH (f->display.x->font),
-                           f->display.x->line_height);
-  XFreePixmap (frame.border);
-  XFreePixmap (frame.background);
-
-  if (tempwindow != 0)
-    {
-      XQueryWindow (tempwindow, &wininfo);
-      XDestroyWindow (tempwindow);
-      *x = wininfo.x;
-      *y = wininfo.y;
-    }
-
-  /* Coordinates we got are relative to the root window.
-     Convert them to coordinates relative to desired parent window
-     by scanning from there up to the root.  */
-  tempwindow = f->display.x->parent_desc;
-  while (tempwindow != ROOT_WINDOW)
-    {
-      int nchildren;
-      Window *children;
-      XQueryWindow (tempwindow, &wininfo);
-      *x -= wininfo.x;
-      *y -= wininfo.y;
-      XQueryTree (tempwindow, &tempwindow, &nchildren, &children);
-      xfree (children);
-    }
-
-  UNBLOCK_INPUT;
-  return tempwindow != 0;
-}
-#endif /* not HAVE_X11 */
-\f
 DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 3, 0,
   "Return a list of the names of available fonts matching PATTERN.\n\
 If optional arguments FACE and FRAME are specified, return only fonts\n\
@@ -2859,6 +2471,7 @@ even if they match PATTERN and FACE.")
   XFontStruct *info;
   XFontStruct *size_ref;
   Lisp_Object list;
+  FRAME_PTR f;
 
   check_x ();
   CHECK_STRING (pattern, 0);
@@ -2867,11 +2480,14 @@ even if they match PATTERN and FACE.")
   if (!NILP (frame))
     CHECK_LIVE_FRAME (frame, 2);
 
+  f = NILP (frame) ? selected_frame : XFRAME (frame);
+
+  /* Determine the width standard for comparison with the fonts we find.  */
+
   if (NILP (face))
     size_ref = 0;
   else
     {
-      FRAME_PTR f = NILP (frame) ? selected_frame : XFRAME (frame);
       int face_id;
 
       /* Don't die if we get called with a terminal frame.  */
@@ -2891,6 +2507,42 @@ even if they match PATTERN and FACE.")
        }
     }
 
+  /* See if we cached the result for this particular query.  */
+  list = Fassoc (pattern, FRAME_X_SCREEN (f)->font_list_cache);
+
+  /* We have info in the cache for this PATTERN.  */
+  if (!NILP (list))
+    {
+      Lisp_Object tem, newlist;
+
+      /* We have info about this pattern.  */
+      list = XCONS (list)->cdr;
+
+      if (size_ref == 0)
+       return list;
+
+      BLOCK_INPUT;
+
+      /* Filter the cached info and return just the fonts that match FACE.  */
+      newlist = Qnil;
+      for (tem = list; CONSP (tem); tem = XCONS (tem)->cdr)
+       {
+         XFontStruct *thisinfo;
+
+          thisinfo = XLoadQueryFont (x_current_display,
+                                    XSTRING (XCONS (tem)->car)->data);
+
+          if (thisinfo && same_size_fonts (thisinfo, size_ref))
+           newlist = Fcons (XCONS (tem)->car, newlist);
+
+         XFreeFont (x_current_display, thisinfo);
+        }
+
+      UNBLOCK_INPUT;
+
+      return newlist;
+    }
+
   BLOCK_INPUT;
 
   /* Solaris 2.3 has a bug in XListFontsWithInfo.  */
@@ -2912,10 +2564,20 @@ even if they match PATTERN and FACE.")
 
   if (names)
     {
-      Lisp_Object *tail;
       int i;
+      Lisp_Object full_list;
+
+      /* Make a list of all the fonts we got back.
+        Store that in the font cache for the display.  */
+      full_list = Qnil;
+      for (i = 0; i < num_fonts; i++)
+       full_list = Fcons (build_string (names[i]), full_list);
+      FRAME_X_SCREEN (f)->font_list_cache
+       = Fcons (Fcons (pattern, full_list),
+                FRAME_X_SCREEN (f)->font_list_cache);
 
-      tail = &list;
+      /* Make a list of the fonts that have the right width.  */
+      list = Qnil;
       for (i = 0; i < num_fonts; i++)
         {
          XFontStruct *thisinfo;
@@ -2929,11 +2591,9 @@ even if they match PATTERN and FACE.")
 #endif
           if (thisinfo && (! size_ref
                           || same_size_fonts (thisinfo, size_ref)))
-           {
-             *tail = Fcons (build_string (names[i]), Qnil);
-             tail = &XCONS (*tail)->cdr;
-           }
+           list = Fcons (build_string (names[i]), list);
         }
+      list = Fnreverse (list);
 
       BLOCK_INPUT;
 #ifdef BROKEN_XLISTFONTSWITHINFO
@@ -3011,6 +2671,18 @@ DEFUN ("x-display-color-p", Fx_display_color_p, Sx_display_color_p, 0, 0, 0,
     }
 }
 
+DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
+  0, 0, 0,
+  "Return t if the X screen currently in use supports grayscale.")
+  ()
+{
+  check_x ();
+
+  return (x_screen_planes > 1
+         && (screen_visual->class == StaticGray
+             || screen_visual->class == GrayScale));
+}
+
 DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
   0, 1, 0,
   "Returns the width in pixels of the display FRAME is on.")
@@ -4010,44 +3682,6 @@ x_draw_pixmap (f, x, y, image_data, width, height)
 }
 #endif
 \f
-#ifndef HAVE_X11
-DEFUN ("x-store-cut-buffer", Fx_store_cut_buffer, Sx_store_cut_buffer,
-  1, 1, "sStore text in cut buffer: ",
-  "Store contents of STRING into the cut buffer of the X window system.")
-  (string)
-     register Lisp_Object string;
-{
-  int mask;
-
-  CHECK_STRING (string, 1);
-  if (! FRAME_X_P (selected_frame))
-    error ("Selected frame does not understand X protocol.");
-
-  BLOCK_INPUT;
-  XStoreBytes ((char *) XSTRING (string)->data, XSTRING (string)->size);
-  UNBLOCK_INPUT;
-
-  return Qnil;
-}
-
-DEFUN ("x-get-cut-buffer", Fx_get_cut_buffer, Sx_get_cut_buffer, 0, 0, 0,
-  "Return contents of cut buffer of the X window system, as a string.")
-  ()
-{
-  int len;
-  register Lisp_Object string;
-  int mask;
-  register char *d;
-
-  BLOCK_INPUT;
-  d = XFetchBytes (&len);
-  string = make_string (d, len);
-  XFree (d);
-  UNBLOCK_INPUT;
-  return string;
-}
-#endif /* X10 */
-\f
 #if 0 /* I'm told these functions are superfluous
         given the ability to bind function keys.  */
 
@@ -4149,8 +3783,6 @@ See the documentation of `x-rebind-key' for more information.")
 #endif /* HAVE_X11 */
 #endif /* 0 */
 \f
-#ifdef HAVE_X11
-
 #ifndef HAVE_XSCREENNUMBEROFSCREEN
 int
 XScreenNumberOfScreen (scr)
@@ -4213,7 +3845,6 @@ select_visual (screen, depth)
   XFree ((char *) vinfo);
   return v;
 }
-#endif /* HAVE_X11 */
 
 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
        1, 2, 0, "Open a connection to an X server.\n\
@@ -4243,7 +3874,6 @@ Optional second arg XRM_STRING is a string of resources in xrdb format.")
   x_term_init (XSTRING (display)->data, xrm_option,
               XSTRING (Vx_resource_name)->data);
 
-#ifdef HAVE_X11
   XFASTINT (Vwindow_system_version) = 11;
 
   BLOCK_INPUT;
@@ -4257,6 +3887,8 @@ Optional second arg XRM_STRING is a string of resources in xrdb format.")
   x_current_display->db = xrdb;
 #endif
 
+  the_x_screen.name = display;
+
   x_screen = DefaultScreenOfDisplay (x_current_display);
 
   screen_visual = select_visual (x_screen, &n_planes);
@@ -4283,9 +3915,6 @@ Optional second arg XRM_STRING is a string of resources in xrdb format.")
                                        False);
   Xatom_editres_name =  XInternAtom (x_current_display, "Editres", False);
   UNBLOCK_INPUT;
-#else /* not HAVE_X11 */
-  XFASTINT (Vwindow_system_version) = 10;
-#endif /* not HAVE_X11 */
   return Qnil;
 }
 
@@ -4300,7 +3929,7 @@ DEFUN ("x-close-current-connection", Fx_close_current_connection,
      really intended only to be called when killing emacs, then there's
      no reason for it to have a lisp interface at all.  */
   check_x();
-#ifdef HAVE_X11
+
   /* This is ONLY used when killing emacs;  For switching displays
      we'll have to take care of setting CloseDownMode elsewhere. */
 
@@ -4313,7 +3942,7 @@ DEFUN ("x-close-current-connection", Fx_close_current_connection,
     }
   else
     fatal ("No current X display connection to close\n");
-#endif
+
   return Qnil;
 }
 
@@ -4349,6 +3978,11 @@ syms_of_xfns ()
   /* This is zero if not using X windows.  */
   x_current_display = 0;
 
+  the_x_screen.font_list_cache = Qnil;
+  the_x_screen.name = Qnil;
+  staticpro (&the_x_screen.font_list_cache);
+  staticpro (&the_x_screen.name);
+
   /* The section below is built by the lisp expression at the top of the file,
      just above where these variables are declared.  */
   /*&&& init symbols here &&&*/
@@ -4392,6 +4026,8 @@ syms_of_xfns ()
   staticpro (&Qnone);
   Qparent_id = intern ("parent-id");
   staticpro (&Qparent_id);
+  Qscroll_bar_width = intern ("scroll-bar-width");
+  staticpro (&Qscroll_bar_width);
   Qsuppress_icon = intern ("suppress-icon");
   staticpro (&Qsuppress_icon);
   Qtop = intern ("top");
@@ -4478,7 +4114,6 @@ or when you set the mouse color.");
   Fprovide (intern ("x-toolkit"));
 #endif
 
-#ifdef HAVE_X11
   defsubr (&Sx_get_resource);
 #if 0
   defsubr (&Sx_draw_rectangle);
@@ -4486,8 +4121,9 @@ or when you set the mouse color.");
   defsubr (&Sx_contour_region);
   defsubr (&Sx_uncontour_region);
 #endif
-  defsubr (&Sx_display_color_p);
   defsubr (&Sx_list_fonts);
+  defsubr (&Sx_display_color_p);
+  defsubr (&Sx_display_grayscale_p);
   defsubr (&Sx_color_defined_p);
   defsubr (&Sx_color_values);
   defsubr (&Sx_server_max_request_size);
@@ -4509,11 +4145,6 @@ or when you set the mouse color.");
   defsubr (&Sx_track_pointer);
   defsubr (&Sx_grab_pointer);
   defsubr (&Sx_ungrab_pointer);
-#endif
-#else
-  defsubr (&Sx_get_default);
-  defsubr (&Sx_store_cut_buffer);
-  defsubr (&Sx_get_cut_buffer);
 #endif
   defsubr (&Sx_parse_geometry);
   defsubr (&Sx_create_frame);