]> code.delx.au - gnu-emacs/blobdiff - src/xfns.c
Don't declare logb if it is a macro.
[gnu-emacs] / src / xfns.c
index e5a71fdd6661e219da9bd7d6c1095269d48997b3..c0313b20b0116955d0ca8d35a3df31190c928091 100644 (file)
@@ -1,5 +1,5 @@
 /* Functions for the X window system.
-   Copyright (C) 1989, 1992, 1993 Free Software Foundation.
+   Copyright (C) 1989, 1992, 1993, 1994 Free Software Foundation.
 
 This file is part of GNU Emacs.
 
@@ -103,6 +103,7 @@ extern char *x_id_name;
 /* The background and shape of the mouse pointer, and shape when not
    over text or in the modeline. */
 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
+Lisp_Object Vx_cross_pointer_shape;
 
 /* Color of chars displayed in cursor box. */
 Lisp_Object Vx_cursor_fore_pixel;
@@ -146,6 +147,9 @@ extern Atom Xatom_wm_delete_window;
 extern Atom Xatom_wm_configure_denied; /* When our config request is denied */
 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.  */
@@ -226,6 +230,8 @@ Lisp_Object Qvisibility;
 Lisp_Object Qwindow_id;
 Lisp_Object Qx_frame_parameter;
 Lisp_Object Qx_resource_name;
+Lisp_Object Quser_position;
+Lisp_Object Quser_size;
 
 /* The below are defined in frame.c. */
 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
@@ -311,6 +317,38 @@ x_any_window_to_frame (wdesc)
     }
   return 0;
 }
+
+/* Return the frame whose principal (outermost) window is WDESC.
+   If WDESC is some other (smaller) window, we return 0.  */
+
+struct frame *
+x_top_window_to_frame (wdesc)
+     int wdesc;
+{
+  Lisp_Object tail, frame;
+  struct frame *f;
+  struct x_display *x;
+
+  for (tail = Vframe_list; XGCTYPE (tail) == Lisp_Cons;
+       tail = XCONS (tail)->cdr)
+    {
+      frame = XCONS (tail)->car;
+      if (XGCTYPE (frame) != Lisp_Frame)
+        continue;
+      f = XFRAME (frame);
+      if (f->display.nothing == 1) 
+       return 0;
+      x = f->display.x;
+      /* This frame matches if the window is its topmost widget.  */
+      if (wdesc == XtWindow (x->widget))
+       return f;
+      /* Match if the window is this frame's menubar.  */
+      if (x->menubar_widget 
+         && wdesc == XtWindow (x->menubar_widget))
+       return f;
+    }
+  return 0;
+}
 #endif /* USE_X_TOOLKIT */
 
 \f
@@ -460,9 +498,10 @@ x_set_frame_parameters (f, alist)
        left = val;
       else
        {
-         register Lisp_Object param_index = Fget (prop, Qx_frame_parameter);
-         register Lisp_Object old_value = get_frame_param (f, prop);
+         register Lisp_Object param_index, old_value;
 
+         param_index = Fget (prop, Qx_frame_parameter);
+         old_value = get_frame_param (f, prop);
          store_frame_param (f, prop, val);
          if (XTYPE (param_index) == Lisp_Int
              && XINT (param_index) >= 0
@@ -508,6 +547,47 @@ x_set_frame_parameters (f, alist)
   }
 }
 
+/* Store the positions of frame F into XPTR and YPTR.
+   These are the positions of the containing window manager window,
+   not Emacs's own window.  */
+
+void
+x_real_positions (f, xptr, yptr)
+     FRAME_PTR f;
+     int *xptr, *yptr;
+{
+  int win_x = 0, win_y = 0;
+  Window child;
+
+  /* Find the position of the outside upper-left corner of
+     the inner window, with respect to the outer window.  */
+  if (f->display.x->parent_desc != ROOT_WINDOW)
+    {
+      BLOCK_INPUT;
+      XTranslateCoordinates (x_current_display,
+                              
+                            /* From-window, to-window.  */
+#ifdef USE_X_TOOLKIT
+                            XtWindow (f->display.x->widget),
+#else
+                            f->display.x->window_desc,
+#endif
+                            f->display.x->parent_desc,
+
+                            /* From-position, to-position.  */
+                            0, 0, &win_x, &win_y,
+
+                            /* Child of win.  */
+                            &child);
+      UNBLOCK_INPUT;
+
+      win_x += f->display.x->border_width;
+      win_y += f->display.x->border_width;
+    }
+  *xptr = f->display.x->left_pos - win_x;
+  *yptr = f->display.x->top_pos - win_y;
+}
+
 /* Insert a description of internally-recorded parameters of frame X
    into the parameter alist *ALISTPTR that is to be given to the user.
    Only parameters that are specific to the X window system
@@ -529,6 +609,7 @@ x_report_frame_params (f, alistptr)
   sprintf (buf, "%d", FRAME_X_WINDOW (f));
   store_in_alist (alistptr, Qwindow_id,
                   build_string (buf));
+  FRAME_SAMPLE_VISIBILITY (f);
   store_in_alist (alistptr, Qvisibility,
                  (FRAME_VISIBLE_P (f) ? Qt
                   : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
@@ -669,7 +750,7 @@ x_set_mouse_color (f, arg, oldval)
      struct frame *f;
      Lisp_Object arg, oldval;
 {
-  Cursor cursor, nontext_cursor, mode_cursor;
+  Cursor cursor, nontext_cursor, mode_cursor, cross_cursor;
   int mask_color;
 
   if (!EQ (Qnil, arg))
@@ -713,6 +794,16 @@ x_set_mouse_color (f, arg, oldval)
     }
   else
     mode_cursor = XCreateFontCursor (x_current_display, XC_xterm);
+  x_check_errors ("bad modeline pointer cursor: %s");
+
+  if (!EQ (Qnil, Vx_cross_pointer_shape))
+    {
+      CHECK_NUMBER (Vx_cross_pointer_shape, 0);
+      cross_cursor = XCreateFontCursor (x_current_display,
+                                          XINT (Vx_cross_pointer_shape));
+    }
+  else
+    cross_cursor = XCreateFontCursor (x_current_display, XC_crosshair);
 
   /* Check and report errors with the above calls.  */
   x_check_errors ("can't set cursor shape: %s");
@@ -737,6 +828,8 @@ x_set_mouse_color (f, arg, oldval)
                    &fore_color, &back_color);
     XRecolorCursor (x_current_display, mode_cursor,
                    &fore_color, &back_color);
+    XRecolorCursor (x_current_display, cross_cursor,
+                    &fore_color, &back_color);
   }
 #else /* X10 */
   cursor = XCreateCursor (16, 16, MouseCursor, MouseMask,
@@ -764,6 +857,10 @@ x_set_mouse_color (f, arg, oldval)
       && f->display.x->modeline_cursor != 0)
       XFreeCursor (XDISPLAY f->display.x->modeline_cursor);
   f->display.x->modeline_cursor = mode_cursor;
+  if (cross_cursor != f->display.x->cross_cursor
+      && f->display.x->cross_cursor != 0)
+      XFreeCursor (XDISPLAY f->display.x->cross_cursor);
+  f->display.x->cross_cursor = cross_cursor;
 #endif /* HAVE_X11 */
 
   XFlushQueue ();
@@ -786,7 +883,7 @@ x_set_cursor_color (f, arg, oldval)
   /* Make sure that the cursor color differs from the background color.  */
   if (f->display.x->cursor_pixel == f->display.x->background_pixel)
     {
-      f->display.x->cursor_pixel == f->display.x->mouse_pixel;
+      f->display.x->cursor_pixel = f->display.x->mouse_pixel;
       if (f->display.x->cursor_pixel == fore_pixel)
        fore_pixel = f->display.x->background_pixel;
     }
@@ -1432,12 +1529,13 @@ x_get_arg (alist, param, attribute, class, type)
              /* As a special case, we map the values `true' and `on'
                 to Qt, and `false' and `off' to Qnil.  */
              {
-               Lisp_Object lower = Fdowncase (tem);
-               if (!strcmp (XSTRING (tem)->data, "on")
-                   || !strcmp (XSTRING (tem)->data, "true"))
+               Lisp_Object lower;
+               lower = Fdowncase (tem);
+               if (!strcmp (XSTRING (lower)->data, "on")
+                   || !strcmp (XSTRING (lower)->data, "true"))
                  return Qt;
-               else if (!strcmp (XSTRING (tem)->data, "off")
-                     || !strcmp (XSTRING (tem)->data, "false"))
+               else if (!strcmp (XSTRING (lower)->data, "off")
+                     || !strcmp (XSTRING (lower)->data, "false"))
                  return Qnil;
                else
                  return Fintern (tem, Qnil);
@@ -1480,62 +1578,63 @@ x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
 \f
 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
        "Parse an X-style geometry string STRING.\n\
-Returns an alist of the form ((top . TOP), (left . LEFT) ... ).")
+Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
+The properties returned may include `top', `left', `height', and `width'.\n\
+The value of `left' or `top' may be an integer or `-'.\n\
+`-' means \"minus zero\".")
      (string)
      Lisp_Object string;
 {
   int geometry, x, y;
   unsigned int width, height;
-  Lisp_Object values[4];
+  Lisp_Object result;
 
   CHECK_STRING (string, 0);
 
   geometry = XParseGeometry ((char *) XSTRING (string)->data,
                             &x, &y, &width, &height);
 
-  switch (geometry & 0xf)      /* Mask out {X,Y}Negative */
+#if 0
+  if (!!(geometry & XValue) != !!(geometry & YValue))
+    error ("Must specify both x and y position, or neither");
+#endif
+
+  result = Qnil;
+  if (geometry & XValue)
     {
-    case (XValue | YValue):
-      /* What's one pixel among friends?
-        Perhaps fix this some day by returning symbol `extreme-top'... */
-      if (x == 0 && (geometry & XNegative))
-       x = -1;
-      if (y == 0 && (geometry & YNegative))
-       y = -1;
-      values[0] = Fcons (Qleft, make_number (x));
-      values[1] = Fcons (Qtop, make_number (y));
-      return Flist (2, values);
-      break;
-
-    case (WidthValue | HeightValue):
-      values[0] = Fcons (Qwidth, make_number (width));
-      values[1] = Fcons (Qheight, make_number (height));
-      return Flist (2, values);
-      break;
-
-    case (XValue | YValue | WidthValue | HeightValue):
+      Lisp_Object element;
+
       if (x == 0 && (geometry & XNegative))
-       x = -1;
+       element = Fcons (Qleft, Qminus);
+      else
+       element = Fcons (Qleft, make_number (x));
+      result = Fcons (element, result);
+    }
+
+  if (geometry & YValue)
+    {
+      Lisp_Object element;
+
       if (y == 0 && (geometry & YNegative))
-       y = -1;
-      values[0] = Fcons (Qwidth, make_number (width));
-      values[1] = Fcons (Qheight, make_number (height));
-      values[2] = Fcons (Qleft, make_number (x));
-      values[3] = Fcons (Qtop, make_number (y));
-      return Flist (4, values);
-      break;
-
-    case 0:
-       return Qnil;
-      
-    default:
-      error ("Must specify x and y value, and/or width and height");
+       element = Fcons (Qtop, Qminus);
+      else
+       element = Fcons (Qtop, make_number (y));
+      result = Fcons (element, result);
     }
+
+  if (geometry & WidthValue)
+    result = Fcons (Fcons (Qwidth, make_number (width)), result);
+  if (geometry & HeightValue)
+    result = Fcons (Fcons (Qheight, make_number (height)), result);
+
+  return result;
 }
 
 #ifdef HAVE_X11
 /* Calculate the desired size and position of this window,
-   or set rubber-band prompting if none. */
+   and return the flags saying which aspects were specified.
+
+   This function does not make the coordinates positive.  */
 
 #define DEFAULT_ROWS 40
 #define DEFAULT_COLS 80
@@ -1545,7 +1644,7 @@ x_figure_window_size (f, parms)
      struct frame *f;
      Lisp_Object parms;
 {
-  register Lisp_Object tem0, tem1;
+  register Lisp_Object tem0, tem1, tem2;
   int height, width, left, top;
   register int geometry;
   long window_prompting = 0;
@@ -1562,16 +1661,24 @@ x_figure_window_size (f, parms)
 
   tem0 = x_get_arg (parms, Qheight, 0, 0, number);
   tem1 = x_get_arg (parms, Qwidth, 0, 0, number);
-  if (! EQ (tem0, Qunbound) && ! EQ (tem1, Qunbound))
+  tem2 = x_get_arg (parms, Quser_size, 0, 0, number);
+  if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
     {
-      CHECK_NUMBER (tem0, 0);
-      CHECK_NUMBER (tem1, 0);
-      f->height = XINT (tem0);
-      f->width = XINT (tem1);
-      window_prompting |= USSize;
+      if (!EQ (tem0, Qunbound))
+       {
+         CHECK_NUMBER (tem0, 0);
+         f->height = XINT (tem0);
+       }
+      if (!EQ (tem1, Qunbound))
+       {
+         CHECK_NUMBER (tem1, 0);
+         f->width = XINT (tem1);
+       }
+      if (!NILP (tem2) && !EQ (tem2, Qunbound))
+       window_prompting |= USSize;
+      else
+       window_prompting |= PSize;
     }
-  else if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
-    error ("Must specify *both* height and width");
 
   f->display.x->vertical_scroll_bar_extra
     = (FRAME_HAS_VERTICAL_SCROLL_BARS (f)
@@ -1582,48 +1689,45 @@ x_figure_window_size (f, parms)
 
   tem0 = x_get_arg (parms, Qtop, 0, 0, number);
   tem1 = x_get_arg (parms, Qleft, 0, 0, number);
-  if (! EQ (tem0, Qunbound) && ! EQ (tem1, Qunbound))
+  tem2 = x_get_arg (parms, Quser_position, 0, 0, number);
+  if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
     {
-      CHECK_NUMBER (tem0, 0);
-      CHECK_NUMBER (tem1, 0);
-      f->display.x->top_pos = XINT (tem0);
-      f->display.x->left_pos = XINT (tem1);
-      x_calc_absolute_position (f);
-      window_prompting |= USPosition;
-    }
-  else if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
-    error ("Must specify *both* top and left corners");
+      if (EQ (tem0, Qminus))
+       {
+         f->display.x->top_pos = 0;
+         window_prompting |= YNegative;
+       }
+      else if (EQ (tem0, Qunbound))
+       f->display.x->top_pos = 0;
+      else
+       {
+         CHECK_NUMBER (tem0, 0);
+         f->display.x->top_pos = XINT (tem0);
+         if (f->display.x->top_pos < 0)
+           window_prompting |= YNegative;
+       }
 
-#if 0 /* PPosition and PSize mean "specified explicitly,
-        by the program rather than by the user".  So it is wrong to
-        set them if nothing was specified.  */
-  switch (window_prompting)
-    {
-    case USSize | USPosition:
-      return window_prompting;
-      break;
-
-    case USSize:               /* Got the size, need the position. */
-      window_prompting |= PPosition;
-      return window_prompting;
-      break;
-         
-    case USPosition:           /* Got the position, need the size. */
-      window_prompting |= PSize;
-      return window_prompting;
-      break;
-         
-    case 0:                    /* Got nothing, take both from geometry. */
-      window_prompting |= PPosition | PSize;
-      return window_prompting;
-      break;
-         
-    default:
-      /* Somehow a bit got set in window_prompting that we didn't
-        put there.  */
-      abort ();
+      if (EQ (tem1, Qminus))
+       {
+         f->display.x->left_pos = 0;
+         window_prompting |= XNegative;
+       }
+      else if (EQ (tem1, Qunbound))
+       f->display.x->left_pos = 0;
+      else
+       {
+         CHECK_NUMBER (tem1, 0);
+         f->display.x->left_pos = XINT (tem1);
+         if (f->display.x->left_pos < 0)
+           window_prompting |= XNegative;
+       }
+
+      if (!NILP (tem2))
+       window_prompting |= USPosition;
+      else
+       window_prompting |= PPosition;
     }
-#endif
+
   return window_prompting;
 }
 
@@ -1693,17 +1797,20 @@ hack_wm_protocols (widget)
 }
 #endif
 \f
-/* Create and set up the X window or widget for frame F.  */
+#ifdef USE_X_TOOLKIT
+
+/* Create and set up the X widget for frame F.  */
 
 static void
-x_window (f)
+x_window (f, window_prompting, minibuffer_only)
      struct frame *f;
+     long window_prompting;
+     int minibuffer_only;
 {
   XClassHint class_hints;
   XSetWindowAttributes attributes;
   unsigned long attribute_mask;
 
-#ifdef USE_X_TOOLKIT
   Widget shell_widget;
   Widget pane_widget;
   Widget screen_widget;
@@ -1714,19 +1821,18 @@ x_window (f)
   BLOCK_INPUT;
 
   if (STRINGP (f->name))
-     name = (char*) XSTRING (f->name)->data;
+    name = (char*) XSTRING (f->name)->data;
   else
     name = "emacs";
 
   ac = 0;
   XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
   XtSetArg (al[ac], XtNinput, 1); ac++;
-  XtSetArg (al[ac], XtNx, f->display.x->left_pos); ac++;
-  XtSetArg (al[ac], XtNy, f->display.x->top_pos); ac++;
   shell_widget = XtCreatePopupShell ("shell",
                                     topLevelShellWidgetClass,
                                     Xt_app_shell, al, ac);
 
+  f->display.x->widget = shell_widget;
   /* maybe_set_screen_title_format (shell_widget); */
 
 
@@ -1736,9 +1842,13 @@ x_window (f)
                                panedWidgetClass,
                                shell_widget, al, ac);
 
+  f->display.x->column_widget = pane_widget;
+
+  if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
+    initialize_frame_menubar (f);
+
   /* mappedWhenManaged to false tells to the paned window to not map/unmap 
-   * the emacs screen when changing menubar.  This reduces flickering a lot.
-   */
+     the emacs screen when changing menubar.  This reduces flickering.  */
 
   ac = 0;
   XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
@@ -1751,10 +1861,50 @@ x_window (f)
                                  pane_widget, al, ac);
  
   f->display.x->edit_widget = screen_widget;
-  f->display.x->widget = shell_widget;
-  f->display.x->column_widget = pane_widget;
  
+  if (f->display.x->menubar_widget)
+    XtManageChild (f->display.x->menubar_widget);
   XtManageChild (screen_widget); 
+
+  /* Do some needed geometry management.  */
+  {
+    int len;
+    char *tem, shell_position[32];
+    Arg al[2];
+    int ac = 0;
+    int menubar_size 
+      = (f->display.x->menubar_widget
+        ? (f->display.x->menubar_widget->core.height
+           + f->display.x->menubar_widget->core.border_width)
+        : 0);
+
+    if (window_prompting & USPosition)
+      {
+       int left = f->display.x->left_pos;
+       int xneg = window_prompting & XNegative;
+       int top = f->display.x->top_pos;
+       int yneg = window_prompting & YNegative;
+       if (left < 0)
+         left = -left;
+       if (top < 0)
+         top = -top;
+       sprintf (shell_position, "=%dx%d%c%d%c%d", PIXEL_WIDTH (f), 
+                PIXEL_HEIGHT (f) + menubar_size,
+                (xneg ? '-' : '+'), left,
+                (yneg ? '-' : '+'), top);
+      }
+    else
+      sprintf (shell_position, "=%dx%d", PIXEL_WIDTH (f), 
+              PIXEL_HEIGHT (f) + menubar_size);
+    len = strlen (shell_position) + 1;
+    tem = (char *) xmalloc (len);
+    strncpy (tem, shell_position, len);
+    XtSetArg (al[ac], XtNgeometry, tem); ac++;
+    XtSetValues (shell_widget, al, ac);
+  }
+
+  x_calc_absolute_position (f);
+
   XtManageChild (pane_widget);
   XtRealizeWidget (shell_widget);
 
@@ -1765,6 +1915,10 @@ x_window (f)
   class_hints.res_class = EMACS_CLASS;
   XSetClassHint (x_current_display, XtWindow (shell_widget), &class_hints);
 
+  f->display.x->wm_hints.input = True;
+  f->display.x->wm_hints.flags |= InputHint;
+  XSetWMHints (x_current_display, FRAME_X_WINDOW (f), &f->display.x->wm_hints);
+
   hack_wm_protocols (shell_widget);
 
   /* Do a stupid property change to force the server to generate a
@@ -1783,8 +1937,40 @@ x_window (f)
 
   XtMapWidget (screen_widget);
 
+  /* x_set_name normally ignores requests to set the name if the
+     requested name is the same as the current name.  This is the one
+     place where that assumption isn't correct; f->name is set, but
+     the X server hasn't been told.  */
+  {
+    Lisp_Object name;
+    int explicit = f->explicit_name;
+
+    f->explicit_name = 0;
+    name = f->name;
+    f->name = Qnil;
+    x_set_name (f, name, explicit);
+  }
+
+  XDefineCursor (XDISPLAY FRAME_X_WINDOW (f),
+                f->display.x->text_cursor);
+
+  UNBLOCK_INPUT;
+
+  if (FRAME_X_WINDOW (f) == 0)
+    error ("Unable to create window");
+}
+
 #else /* not USE_X_TOOLKIT */
 
+/* Create and set up the X window for frame F.  */
+
+x_window (f)
+     struct frame *f;
+
+{
+  XClassHint class_hints;
+  XSetWindowAttributes attributes;
+  unsigned long attribute_mask;
 
   attributes.background_pixel = f->display.x->background_pixel;
   attributes.border_pixel = f->display.x->border_pixel;
@@ -1826,18 +2012,18 @@ x_window (f)
   XSetWMProtocols (x_current_display, FRAME_X_WINDOW (f),
                   &Xatom_wm_delete_window, 1);
 
-#endif /* not USE_X_TOOLKIT */
 
   /* x_set_name normally ignores requests to set the name if the
      requested name is the same as the current name.  This is the one
      place where that assumption isn't correct; f->name is set, but
      the X server hasn't been told.  */
   {
-    Lisp_Object name = f->name;
+    Lisp_Object name;
     int explicit = f->explicit_name;
 
-    f->name = Qnil;
     f->explicit_name = 0;
+    name = f->name;
+    f->name = Qnil;
     x_set_name (f, name, explicit);
   }
 
@@ -1850,6 +2036,8 @@ x_window (f)
     error ("Unable to create window");
 }
 
+#endif /* not USE_X_TOOLKIT */
+
 /* Handle the icon stuff for this window.  Perhaps later we might
    want an x_set_icon_position which can be called interactively as
    well. */
@@ -1974,7 +2162,7 @@ be shared by the new frame.")
 {
 #ifdef HAVE_X11
   struct frame *f;
-  Lisp_Object frame, tem, tem0, tem1;
+  Lisp_Object frame, tem;
   Lisp_Object name;
   int minibuffer_only = 0;
   long window_prompting = 0;
@@ -2090,10 +2278,34 @@ 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),
+                      "menuBarLines", "MenuBarLines", number);
+
   f->display.x->parent_desc = ROOT_WINDOW;
   window_prompting = x_figure_window_size (f, parms);
 
+  if (window_prompting & XNegative)
+    {
+      if (window_prompting & YNegative)
+       f->display.x->win_gravity = SouthEastGravity;
+      else
+       f->display.x->win_gravity = NorthEastGravity;
+    }
+  else
+    {
+      if (window_prompting & YNegative)
+       f->display.x->win_gravity = SouthWestGravity;
+      else
+       f->display.x->win_gravity = NorthWestGravity;
+    }
+
+  f->display.x->size_hint_flags = window_prompting;
+
+#ifdef USE_X_TOOLKIT
+  x_window (f, window_prompting, minibuffer_only);
+#else
   x_window (f);
+#endif
   x_icon (f, parms);
   x_make_gc (f);
   init_frame_faces (f);
@@ -2118,14 +2330,12 @@ be shared by the new frame.")
   f->height = f->width = 0;
   change_frame_size (f, height, width, 1, 0);
 
-  x_default_parameter (f, parms, Qmenu_bar_lines, make_number (0),
-                      "menuBarLines", "MenuBarLines", number);
-
-  tem0 = x_get_arg (parms, Qleft, 0, 0, number);
-  tem1 = x_get_arg (parms, Qtop, 0, 0, number);
+/* With the toolkit, the geometry management is done in x_window.  */
+#ifndef USE_X_TOOLKIT
   BLOCK_INPUT;
-  x_wm_set_size_hint (f, window_prompting, 1, XINT (tem0), XINT (tem1));
+  x_wm_set_size_hint (f, window_prompting, 0);
   UNBLOCK_INPUT;
+#endif /* USE_X_TOOLKIT */
 
   tem = x_get_arg (parms, Qunsplittable, 0, 0, boolean);
   f->no_split = minibuffer_only || EQ (tem, Qt);
@@ -2136,16 +2346,12 @@ be shared by the new frame.")
      or making it visible won't work.  */
   Vframe_list = Fcons (frame, Vframe_list);
 
-#ifdef USE_X_TOOLKIT
-  /* Compute the size of the menubar and display it.  */
-  initialize_frame_menubar (f);
-#endif /* USE_X_TOOLKIT */
-
   /* Make the window appear on the frame and enable display,
      unless the caller says not to.  */
   {
-    Lisp_Object visibility = x_get_arg (parms, Qvisibility, 0, 0, symbol);
+    Lisp_Object visibility;
 
+    visibility = x_get_arg (parms, Qvisibility, 0, 0, symbol);
     if (EQ (visibility, Qunbound))
       visibility = Qt;
 
@@ -2384,8 +2590,9 @@ be shared by the new frame.")
 
   /* Make the window appear on the frame and enable display.  */
   {
-    Lisp_Object visibility = x_get_arg (parms, Qvisibility, 0, 0, symbol);
+    Lisp_Object visibility;
 
+    visibility = x_get_arg (parms, Qvisibility, 0, 0, symbol);
     if (EQ (visibility, Qunbound))
       visibility = Qt;
 
@@ -2490,7 +2697,7 @@ x_rubber_band (f, x, y, width, height, geo, str, hscroll, vscroll)
                             + (hscroll ? HSCROLL_HEIGHT : 0)),
                            width, height, f->display.x->font,
                            FONT_WIDTH (f->display.x->font),
-                           FONT_HEIGHT (f->display.x->font));
+                           f->display.x->line_height);
   XFreePixmap (frame.border);
   XFreePixmap (frame.background);
 
@@ -2536,8 +2743,8 @@ FACE is a face name - a symbol.\n\
 The return value is a list of strings, suitable as arguments to\n\
 set-face-font.\n\
 \n\
-The list does not include fonts Emacs can't use (i.e.  proportional\n\
-fonts), even if they match PATTERN and FACE.")
+Fonts Emacs can't use (i.e. proportional fonts) may or may not be excluded\n\
+even if they match PATTERN and FACE.")
   (pattern, face, frame)
     Lisp_Object pattern, face, frame;
 {
@@ -2559,7 +2766,13 @@ fonts), even if they match PATTERN and FACE.")
   else
     {
       FRAME_PTR f = NILP (frame) ? selected_frame : XFRAME (frame);
-      int face_id = face_name_id_number (f, face);
+      int face_id;
+
+      /* Don't die if we get called with a terminal frame.  */
+      if (! FRAME_X_P (f))
+       error ("non-X frame used in `x-list-fonts'");
+
+      face_id = face_name_id_number (f, face);
 
       if (face_id < 0 || face_id >= FRAME_N_PARAM_FACES (f)
          || FRAME_PARAM_FACES (f) [face_id] == 0)
@@ -2862,7 +3075,7 @@ x_char_width (f)
 x_char_height (f)
      register struct frame *f;
 {
-  return FONT_HEIGHT (f->display.x->font);
+  return f->display.x->line_height;
 }
 \f
 #if 0  /* These no longer seem like the right way to do things.  */
@@ -2881,7 +3094,7 @@ x_rectangle (f, gc, left_char, top_char, chars, lines)
   int height;
   int left = (left_char * FONT_WIDTH (f->display.x->font)
                    + f->display.x->internal_border_width);
-  int top = (top_char *  FONT_HEIGHT (f->display.x->font)
+  int top = (top_char * f->display.x->line_height
                   + f->display.x->internal_border_width);
 
   if (chars < 0)
@@ -2889,9 +3102,9 @@ x_rectangle (f, gc, left_char, top_char, chars, lines)
   else
     width = FONT_WIDTH (f->display.x->font) * chars;
   if (lines < 0)
-    height = FONT_HEIGHT (f->display.x->font) / 2;
+    height = f->display.x->line_height / 2;
   else
-    height = FONT_HEIGHT (f->display.x->font) * lines;
+    height = f->display.x->line_height * lines;
 
   XDrawRectangle (x_current_display, FRAME_X_WINDOW (f),
                  gc, left, top, width, height);
@@ -3009,7 +3222,7 @@ outline_region (f, gc, top_x, top_y, bottom_x, bottom_y)
 {
   register int ibw = f->display.x->internal_border_width;
   register int font_w = FONT_WIDTH (f->display.x->font);
-  register int font_h = FONT_HEIGHT (f->display.x->font);
+  register int font_h = f->display.x->line_height;
   int y = top_y;
   int x = line_len (y);
   XPoint *pixel_points
@@ -3346,7 +3559,7 @@ DEFUN ("x-horizontal-line", Fx_horizontal_line, Sx_horizontal_line, 1, 1, "e",
   XGCValues gc_values;
 #endif
   register int previous_y;
-  register int line = (x_mouse_y + 1) * FONT_HEIGHT (f->display.x->font)
+  register int line = (x_mouse_y + 1) * f->display.x->line_height
     + f->display.x->internal_border_width;
   register int left = f->display.x->internal_border_width
     + (w->left
@@ -3385,7 +3598,7 @@ DEFUN ("x-horizontal-line", Fx_horizontal_line, Sx_horizontal_line, 1, 1, "e",
          && x_mouse_y < XINT (w->top) + XINT (w->height) - 1)
        {
          previous_y = x_mouse_y;
-         line = (x_mouse_y + 1) * FONT_HEIGHT (f->display.x->font)
+         line = (x_mouse_y + 1) * f->display.x->line_height
            + f->display.x->internal_border_width;
          XDrawLine (x_current_display, FRAME_X_WINDOW (f),
                     line_gc, left, line, right, line);
@@ -3936,6 +4149,7 @@ Optional second arg XRM_STRING is a string of resources in xrdb format.")
                                            "WM_CONFIGURE_DENIED", False);
   Xatom_wm_window_moved =  XInternAtom (x_current_display, "WM_MOVED",
                                        False);
+  Xatom_editres_name =  XInternAtom (x_current_display, "Editres", False);
   UNBLOCK_INPUT;
 #else /* not HAVE_X11 */
   XFASTINT (Vwindow_system_version) = 10;
@@ -4062,6 +4276,10 @@ syms_of_xfns ()
   staticpro (&Qx_frame_parameter);
   Qx_resource_name = intern ("x-resource-name");
   staticpro (&Qx_resource_name);
+  Quser_position = intern ("user-position");
+  staticpro (&Quser_position);
+  Quser_size = intern ("user-size");
+  staticpro (&Quser_size);
   /* This is the end of symbol initialization.  */
 
   Fput (Qundefined_color, Qerror_conditions,
@@ -4102,6 +4320,8 @@ switches, if present.");
 #endif
   Vx_mode_pointer_shape = Qnil;
 
+  Vx_cross_pointer_shape = Qnil;
+
   DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
               "A string indicating the foreground color of the cursor box.");
   Vx_cursor_fore_pixel = Qnil;