* xterm.h (struct x_output): For 'black_relief' and 'white_relief'
[bpt/emacs.git] / src / xfns.c
index e86f71f..695a72a 100644 (file)
@@ -22,10 +22,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <math.h>
 #include <unistd.h>
 
-/* This makes the fields of a Display accessible, in Xlib header files.  */
-
-#define XLIB_ILLEGAL_ACCESS
-
 #include "lisp.h"
 #include "xterm.h"
 #include "frame.h"
@@ -46,8 +42,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "termchar.h"
 #include "font.h"
 
-#ifdef HAVE_X_WINDOWS
-
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -157,7 +151,7 @@ check_x_display_info (Lisp_Object object)
       struct frame *sf = XFRAME (selected_frame);
 
       if (FRAME_X_P (sf) && FRAME_LIVE_P (sf))
-       dpyinfo = FRAME_X_DISPLAY_INFO (sf);
+       dpyinfo = FRAME_DISPLAY_INFO (sf);
       else if (x_display_list != 0)
        dpyinfo = x_display_list;
       else
@@ -176,200 +170,19 @@ check_x_display_info (Lisp_Object object)
     dpyinfo = x_display_info_for_name (object);
   else
     {
-      FRAME_PTR f = decode_window_system_frame (object);
-      dpyinfo = FRAME_X_DISPLAY_INFO (f);
+      struct frame *f = decode_window_system_frame (object);
+      dpyinfo = FRAME_DISPLAY_INFO (f);
     }
 
   return dpyinfo;
 }
 
-\f
-/* Return the Emacs frame-object corresponding to an X window.
-   It could be the frame's main window or an icon window.  */
-
-/* This function can be called during GC, so use GC_xxx type test macros.  */
-
-struct frame *
-x_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
-{
-  Lisp_Object tail, frame;
-  struct frame *f;
-
-  if (wdesc == None)
-    return NULL;
-
-  FOR_EACH_FRAME (tail, frame)
-    {
-      f = XFRAME (frame);
-      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
-       continue;
-      if (f->output_data.x->hourglass_window == wdesc)
-       return f;
-#ifdef USE_X_TOOLKIT
-      if ((f->output_data.x->edit_widget
-          && XtWindow (f->output_data.x->edit_widget) == wdesc)
-         /* A tooltip frame?  */
-         || (!f->output_data.x->edit_widget
-             && FRAME_X_WINDOW (f) == wdesc)
-          || f->output_data.x->icon_desc == wdesc)
-        return f;
-#else /* not USE_X_TOOLKIT */
-#ifdef USE_GTK
-      if (f->output_data.x->edit_widget)
-      {
-        GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
-        struct x_output *x = f->output_data.x;
-        if (gwdesc != 0 && gwdesc == x->edit_widget)
-          return f;
-      }
-#endif /* USE_GTK */
-      if (FRAME_X_WINDOW (f) == wdesc
-          || f->output_data.x->icon_desc == wdesc)
-        return f;
-#endif /* not USE_X_TOOLKIT */
-    }
-  return 0;
-}
-
-#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
-/* Like x_window_to_frame but also compares the window with the widget's
-   windows.  */
-
-struct frame *
-x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
-{
-  Lisp_Object tail, frame;
-  struct frame *f, *found = NULL;
-  struct x_output *x;
-
-  if (wdesc == None)
-    return NULL;
-
-  FOR_EACH_FRAME (tail, frame)
-    {
-      if (found)
-        break;
-      f = XFRAME (frame);
-      if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
-       {
-         /* This frame matches if the window is any of its widgets.  */
-         x = f->output_data.x;
-         if (x->hourglass_window == wdesc)
-           found = f;
-         else if (x->widget)
-           {
-#ifdef USE_GTK
-              GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
-              if (gwdesc != 0
-                  && gtk_widget_get_toplevel (gwdesc) == x->widget)
-                found = f;
-#else
-             if (wdesc == XtWindow (x->widget)
-                 || wdesc == XtWindow (x->column_widget)
-                 || wdesc == XtWindow (x->edit_widget))
-               found = f;
-             /* Match if the window is this frame's menubar.  */
-             else if (lw_window_is_in_menubar (wdesc, x->menubar_widget))
-               found = f;
-#endif
-           }
-         else if (FRAME_X_WINDOW (f) == wdesc)
-           /* A tooltip frame.  */
-           found = f;
-       }
-    }
-
-  return found;
-}
-
-/* Likewise, but consider only the menu bar widget.  */
-
-struct frame *
-x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event)
-{
-  Window wdesc = event->xany.window;
-  Lisp_Object tail, frame;
-  struct frame *f;
-  struct x_output *x;
-
-  if (wdesc == None)
-    return NULL;
-
-  FOR_EACH_FRAME (tail, frame)
-    {
-      f = XFRAME (frame);
-      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
-       continue;
-      x = f->output_data.x;
-#ifdef USE_GTK
-      if (x->menubar_widget && xg_event_is_for_menubar (f, event))
-        return f;
-#else
-      /* Match if the window is this frame's menubar.  */
-      if (x->menubar_widget
-         && lw_window_is_in_menubar (wdesc, x->menubar_widget))
-       return f;
-#endif
-    }
-  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 (struct x_display_info *dpyinfo, int wdesc)
-{
-  Lisp_Object tail, frame;
-  struct frame *f;
-  struct x_output *x;
-
-  if (wdesc == None)
-    return NULL;
-
-  FOR_EACH_FRAME (tail, frame)
-    {
-      f = XFRAME (frame);
-      if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
-       continue;
-      x = f->output_data.x;
-
-      if (x->widget)
-       {
-         /* This frame matches if the window is its topmost widget.  */
-#ifdef USE_GTK
-          GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
-          if (gwdesc == x->widget)
-            return f;
-#else
-         if (wdesc == XtWindow (x->widget))
-           return f;
-#if 0 /* I don't know why it did this,
-        but it seems logically wrong,
-        and it causes trouble for MapNotify events.  */
-         /* Match if the window is this frame's menubar.  */
-         if (x->menubar_widget
-             && wdesc == XtWindow (x->menubar_widget))
-           return f;
-#endif
-#endif
-       }
-      else if (FRAME_X_WINDOW (f) == wdesc)
-       /* Tooltip frame.  */
-       return f;
-    }
-  return 0;
-}
-#endif /* USE_X_TOOLKIT || USE_GTK */
-
-\f
-
 /* Store the screen 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 (FRAME_PTR f, int *xptr, int *yptr)
+x_real_positions (struct frame *f, int *xptr, int *yptr)
 {
   int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0);
   int real_x = 0, real_y = 0;
@@ -378,7 +191,7 @@ x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
   Atom actual_type;
   unsigned long actual_size, bytes_remaining;
   int rc, actual_format;
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   long max_len = 400;
   Display *dpy = FRAME_X_DISPLAY (f);
   unsigned char *tmp_data = NULL;
@@ -441,7 +254,7 @@ x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
       XTranslateCoordinates (FRAME_X_DISPLAY (f),
 
                             /* From-window, to-window.  */
-                            FRAME_X_DISPLAY_INFO (f)->root_window,
+                            FRAME_DISPLAY_INFO (f)->root_window,
                              FRAME_X_WINDOW (f),
 
                             /* From-position, to-position.  */
@@ -460,7 +273,7 @@ x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
           XTranslateCoordinates (FRAME_X_DISPLAY (f),
 
                                  /* From-window, to-window.  */
-                                 FRAME_X_DISPLAY_INFO (f)->root_window,
+                                 FRAME_DISPLAY_INFO (f)->root_window,
                                  FRAME_OUTER_WINDOW (f),
 
                                  /* From-position, to-position.  */
@@ -565,7 +378,7 @@ x_defined_color (struct frame *f, const char *color_name,
    Signal an error if color can't be allocated.  */
 
 static int
-x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color)
+x_decode_color (struct frame *f, Lisp_Object color_name, int mono_color)
 {
   XColor cdef;
 
@@ -581,7 +394,7 @@ x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color)
 #endif
 
   /* Return MONO_COLOR for monochrome frames.  */
-  if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
+  if (FRAME_DISPLAY_INFO (f)->n_planes == 1)
     return mono_color;
 
   /* x_defined_color is responsible for coping with failures
@@ -626,7 +439,7 @@ x_set_tool_bar_position (struct frame *f,
    may be any format that GdkPixbuf knows about, i.e. not just bitmaps.  */
 
 int
-xg_set_icon (FRAME_PTR f, Lisp_Object file)
+xg_set_icon (struct frame *f, Lisp_Object file)
 {
   int result = 0;
   Lisp_Object found;
@@ -660,7 +473,7 @@ xg_set_icon (FRAME_PTR f, Lisp_Object file)
 }
 
 int
-xg_set_icon_from_xpm_data (FRAME_PTR f, const char **data)
+xg_set_icon_from_xpm_data (struct frame *f, const char **data)
 {
   GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data);
 
@@ -774,7 +587,7 @@ make_invisible_cursor (struct frame *f)
   Cursor c = 0;
 
   x_catch_errors (dpy);
-  pix = XCreateBitmapFromData (dpy, FRAME_X_DISPLAY_INFO (f)->root_window,
+  pix = XCreateBitmapFromData (dpy, FRAME_DISPLAY_INFO (f)->root_window,
                                no_data, 1, 1);
   if (! x_had_errors_p (dpy) && pix != None)
     {
@@ -899,8 +712,8 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     XDefineCursor (dpy, FRAME_X_WINDOW (f),
                    f->output_data.x->current_cursor = cursor);
 
-  if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor == 0)
-    FRAME_X_DISPLAY_INFO (f)->invisible_cursor = make_invisible_cursor (f);
+  if (FRAME_DISPLAY_INFO (f)->invisible_cursor == 0)
+    FRAME_DISPLAY_INFO (f)->invisible_cursor = make_invisible_cursor (f);
 
   if (cursor != x->text_cursor
       && x->text_cursor != 0)
@@ -1035,7 +848,7 @@ x_set_border_pixel (struct frame *f, int pix)
    Note: this is done in two routines because of the way X10 works.
 
    Note: under X11, this is normally the province of the window manager,
-   and so emacs' border colors may be overridden.  */
+   and so emacs's border colors may be overridden.  */
 
 static void
 x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
@@ -1050,14 +863,11 @@ x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
 
 static void
-x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
+x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   set_frame_cursor_types (f, arg);
-
-  /* Make sure the cursor gets redrawn.  */
-  cursor_type_changed = 1;
 }
-\f
+
 static void
 x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
@@ -1189,7 +999,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 
          block_input ();
          x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                       0, y, width, height, False);
+                       0, y, width, height);
          unblock_input ();
        }
 
@@ -1200,7 +1010,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 
          block_input ();
          x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                       0, y, width, height, False);
+                       0, y, width, height);
          unblock_input ();
        }
 
@@ -1208,7 +1018,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
        clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
     }
 #endif /* not USE_X_TOOLKIT && not USE_GTK */
-  adjust_glyphs (f);
+  adjust_frame_glyphs (f);
   run_window_configuration_change_hook (f);
 }
 
@@ -1222,8 +1032,11 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 void
 x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
-  int delta, nlines, root_height;
+  int nlines;
+#if ! defined (USE_GTK)
+  int delta, root_height;
   Lisp_Object root_window;
+#endif
 
   /* Treat tool bars like menu bars.  */
   if (FRAME_MINIBUF_ONLY_P (f))
@@ -1236,6 +1049,7 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
     nlines = 0;
 
 #ifdef USE_GTK
+
   FRAME_TOOL_BAR_LINES (f) = 0;
   if (nlines)
     {
@@ -1252,8 +1066,7 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
       FRAME_EXTERNAL_TOOL_BAR (f) = 0;
     }
 
-  return;
-#endif
+#else /* !USE_GTK */
 
      /* Make sure we redisplay all windows in this frame.  */
   ++windows_or_buffers_changed;
@@ -1271,7 +1084,7 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 
   FRAME_TOOL_BAR_LINES (f) = nlines;
   resize_frame_windows (f, FRAME_LINES (f), 0);
-  adjust_glyphs (f);
+  adjust_frame_glyphs (f);
 
   /* We also have to make sure that the internal border at the top of
      the frame, below the menu bar or tool bar, is redrawn when the
@@ -1298,8 +1111,8 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
       if (height > 0 && width > 0)
        {
           block_input ();
-          x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                        0, y, width, height, False);
+         x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+                       0, y, width, height);
           unblock_input ();
         }
 
@@ -1308,7 +1121,7 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
     }
 
     run_window_configuration_change_hook (f);
-
+#endif /* USE_GTK */
 }
 
 
@@ -1449,7 +1262,7 @@ x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp,
    icon name to NAME.  */
 
 static void
-x_set_name_internal (FRAME_PTR f, Lisp_Object name)
+x_set_name_internal (struct frame *f, Lisp_Object name)
 {
   if (FRAME_X_WINDOW (f))
     {
@@ -1493,7 +1306,7 @@ x_set_name_internal (FRAME_PTR f, Lisp_Object name)
        text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp,
                                    &do_free_text_value);
        text.encoding = (stringp ? XA_STRING
-                        : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
+                        : FRAME_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
        text.format = 8;
        text.nitems = bytes;
        if (text.nitems != bytes)
@@ -1510,7 +1323,7 @@ x_set_name_internal (FRAME_PTR f, Lisp_Object name)
            icon.value = x_encode_text (f->icon_name, coding_system, 0,
                                        &bytes, &stringp, &do_free_icon_value);
            icon.encoding = (stringp ? XA_STRING
-                            : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
+                            : FRAME_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
            icon.format = 8;
            icon.nitems = bytes;
            if (icon.nitems != bytes)
@@ -1525,8 +1338,8 @@ x_set_name_internal (FRAME_PTR f, Lisp_Object name)
 #else /* not USE_GTK */
        XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
        XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
-                        FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_name,
-                        FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
+                        FRAME_DISPLAY_INFO (f)->Xatom_net_wm_name,
+                        FRAME_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
                         8, PropModeReplace,
                         SDATA (encoded_name),
                         SBYTES (encoded_name));
@@ -1534,8 +1347,8 @@ x_set_name_internal (FRAME_PTR f, Lisp_Object name)
 
        XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
        XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
-                        FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_icon_name,
-                        FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
+                        FRAME_DISPLAY_INFO (f)->Xatom_net_wm_icon_name,
+                        FRAME_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
                         8, PropModeReplace,
                         SDATA (encoded_icon_name),
                         SBYTES (encoded_icon_name));
@@ -1582,10 +1395,10 @@ x_set_name (struct frame *f, Lisp_Object name, int explicit)
     {
       /* Check for no change needed in this very common case
         before we do any consing.  */
-      if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
+      if (!strcmp (FRAME_DISPLAY_INFO (f)->x_id_name,
                   SSDATA (f->name)))
        return;
-      name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
+      name = build_string (FRAME_DISPLAY_INFO (f)->x_id_name);
     }
   else
     CHECK_STRING (name);
@@ -1608,7 +1421,7 @@ x_set_name (struct frame *f, Lisp_Object name, int explicit)
    specified a name for the frame; the name will override any set by the
    redisplay code.  */
 static void
-x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
+x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   x_set_name (f, arg, 1);
 }
@@ -1617,7 +1430,7 @@ x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
    name; names set this way will never override names set by the user's
    lisp code.  */
 void
-x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
+x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   x_set_name (f, arg, 0);
 }
@@ -1655,9 +1468,8 @@ x_set_scroll_bar_default_width (struct frame *f)
   int minw = 16;
 #endif
   /* A minimum width of 14 doesn't look good for toolkit scroll bars.  */
-  int width = minw + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM;
-  FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid;
-  FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width;
+  FRAME_CONFIG_SCROLL_BAR_COLS (f) = (minw + wid - 1) / wid;
+  FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = minw;
 #else
   /* Make the actual width at least 14 pixels and a multiple of a
      character width.  */
@@ -1681,7 +1493,7 @@ x_default_scroll_bar_color_parameter (struct frame *f,
                                      const char *xprop, const char *xclass,
                                      int foreground_p)
 {
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Lisp_Object tem;
 
   tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING);
@@ -1730,7 +1542,7 @@ x_default_scroll_bar_color_parameter (struct frame *f,
    for example, but Xt doesn't).  */
 
 static void
-hack_wm_protocols (FRAME_PTR f, Widget widget)
+hack_wm_protocols (struct frame *f, Widget widget)
 {
   Display *dpy = XtDisplay (widget);
   Window w = XtWindow (widget);
@@ -1747,7 +1559,7 @@ hack_wm_protocols (FRAME_PTR f, Widget widget)
     unsigned long bytes_after;
 
     if ((XGetWindowProperty (dpy, w,
-                            FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
+                            FRAME_DISPLAY_INFO (f)->Xatom_wm_protocols,
                             (long)0, (long)100, False, XA_ATOM,
                             &type, &format, &nitems, &bytes_after,
                             &catoms)
@@ -1759,13 +1571,13 @@ hack_wm_protocols (FRAME_PTR f, Widget widget)
          {
            nitems--;
            if (atoms[nitems]
-               == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window)
+               == FRAME_DISPLAY_INFO (f)->Xatom_wm_delete_window)
              need_delete = 0;
            else if (atoms[nitems]
-                    == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus)
+                    == FRAME_DISPLAY_INFO (f)->Xatom_wm_take_focus)
              need_focus = 0;
            else if (atoms[nitems]
-                    == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself)
+                    == FRAME_DISPLAY_INFO (f)->Xatom_wm_save_yourself)
              need_save = 0;
          }
       }
@@ -1776,13 +1588,13 @@ hack_wm_protocols (FRAME_PTR f, Widget widget)
     Atom props [10];
     int count = 0;
     if (need_delete)
-      props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
+      props[count++] = FRAME_DISPLAY_INFO (f)->Xatom_wm_delete_window;
     if (need_focus)
-      props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus;
+      props[count++] = FRAME_DISPLAY_INFO (f)->Xatom_wm_take_focus;
     if (need_save)
-      props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
+      props[count++] = FRAME_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
     if (count)
-      XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
+      XChangeProperty (dpy, w, FRAME_DISPLAY_INFO (f)->Xatom_wm_protocols,
                       XA_ATOM, 32, PropModeAppend,
                       (unsigned char *) props, count);
   }
@@ -1977,7 +1789,7 @@ xic_create_xfontset (struct frame *f)
       struct frame *cf = XFRAME (frame);
 
       if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
-          && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
+          && FRAME_DISPLAY_INFO (cf) == FRAME_DISPLAY_INFO (f)
          && FRAME_FONT (f)
          && FRAME_FONT (f)->pixel_size == pixel_size)
         {
@@ -2076,7 +1888,7 @@ xic_free_xfontset (struct frame *f)
     {
       struct frame *cf = XFRAME (frame);
       if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
-          && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
+          && FRAME_DISPLAY_INFO (cf) == FRAME_DISPLAY_INFO (f)
           && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
         {
           shared_p = 1;
@@ -2088,9 +1900,6 @@ xic_free_xfontset (struct frame *f)
     /* The fontset is not used anymore.  It is safe to free it.  */
     XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
 
-  if (FRAME_XIC_BASE_FONTNAME (f))
-    xfree (FRAME_XIC_BASE_FONTNAME (f));
-  FRAME_XIC_BASE_FONTNAME (f) = NULL;
   FRAME_XIC_FONTSET (f) = NULL;
 }
 
@@ -2316,12 +2125,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
      for the window manager, so GC relocation won't bother it.
 
      Elsewhere we specify the window name for the window manager.  */
-
-  {
-    char *str = SSDATA (Vx_resource_name);
-    f->namebuf = xmalloc (strlen (str) + 1);
-    strcpy (f->namebuf, str);
-  }
+  f->namebuf = xstrdup (SSDATA (Vx_resource_name));
 
   ac = 0;
   XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
@@ -2329,7 +2133,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
   XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
   XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++;
   XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
-  XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
+  XtSetArg (al[ac], XtNdepth, FRAME_DISPLAY_INFO (f)->n_planes); ac++;
   XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
   shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS,
                                   applicationShellWidgetClass,
@@ -2339,16 +2143,12 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
   /* maybe_set_screen_title_format (shell_widget); */
 
   pane_widget = lw_create_widget ("main", "pane", widget_id_tick++,
-                                 (widget_value *) NULL,
-                                 shell_widget, False,
-                                 (lw_callback) NULL,
-                                 (lw_callback) NULL,
-                                 (lw_callback) NULL,
-                                 (lw_callback) NULL);
+                                 NULL, shell_widget, False,
+                                 NULL, NULL, NULL, NULL);
 
   ac = 0;
   XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
-  XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
+  XtSetArg (al[ac], XtNdepth, FRAME_DISPLAY_INFO (f)->n_planes); ac++;
   XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
   XtSetArg (al[ac], XtNborderWidth, 0); ac++;
   XtSetValues (pane_widget, al, ac);
@@ -2364,7 +2164,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
   XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
   XtSetArg (al[ac], XtNemacsFrame, f); ac++;
   XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
-  XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
+  XtSetArg (al[ac], XtNdepth, FRAME_DISPLAY_INFO (f)->n_planes); ac++;
   XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
   XtSetArg (al[ac], XtNborderWidth, 0); ac++;
   frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget,
@@ -2490,9 +2290,8 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
      be initialized to something relevant to the time we created the window.
      */
   XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
-                  FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
-                  XA_ATOM, 32, PropModeAppend,
-                  (unsigned char*) NULL, 0);
+                  FRAME_DISPLAY_INFO (f)->Xatom_wm_protocols,
+                  XA_ATOM, 32, PropModeAppend, NULL, 0);
 
   /* Make all the standard events reach the Emacs frame.  */
   attributes.event_mask = STANDARD_EVENT_SET;
@@ -2541,7 +2340,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
 #else /* not USE_X_TOOLKIT */
 #ifdef USE_GTK
 static void
-x_window (FRAME_PTR f)
+x_window (struct frame *f)
 {
   if (! xg_create_frame_widgets (f))
     error ("Unable to create window");
@@ -2651,8 +2450,8 @@ x_window (struct frame *f)
   /* Request "save yourself" and "delete window" commands from wm.  */
   {
     Atom protocols[2];
-    protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
-    protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
+    protocols[0] = FRAME_DISPLAY_INFO (f)->Xatom_wm_delete_window;
+    protocols[1] = FRAME_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
     XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2);
   }
 
@@ -2712,7 +2511,7 @@ x_icon (struct frame *f, Lisp_Object parms)
 {
   Lisp_Object icon_x, icon_y;
 #if 0
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
 #endif
 
   /* Set the position of the icon.  Note that twm groups all
@@ -2791,16 +2590,12 @@ x_make_gc (struct frame *f)
                  | GCFillStyle | GCLineWidth),
                 &gc_values);
 
-  /* Reliefs.  */
-  f->output_data.x->white_relief.gc = 0;
-  f->output_data.x->black_relief.gc = 0;
-
   /* Create the gray border tile used when the pointer is not in
      the frame.  Since this depends on the frame's pixel values,
      this must be done on a per-frame basis.  */
   f->output_data.x->border_tile
     = (XCreatePixmapFromBitmapData
-       (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
+       (FRAME_X_DISPLAY (f), FRAME_DISPLAY_INFO (f)->root_window,
        gray_bits, gray_width, gray_height,
        FRAME_FOREGROUND_PIXEL (f),
        FRAME_BACKGROUND_PIXEL (f),
@@ -2866,7 +2661,7 @@ unwind_create_frame (Lisp_Object frame)
   if (NILP (Fmemq (frame, Vframe_list)))
     {
 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
-      struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+      struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
 #endif
 
       x_free_frame_resources (f);
@@ -2898,7 +2693,7 @@ unwind_create_frame_1 (Lisp_Object val)
 static void
 x_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
                                       RES_TYPE_STRING);
   Lisp_Object font = Qnil;
@@ -3085,6 +2880,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   f->output_data.x->scroll_bar_top_shadow_pixel = -1;
   f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
 #endif /* USE_TOOLKIT_SCROLL_BARS */
+  f->output_data.x->white_relief.pixel = -1;
+  f->output_data.x->black_relief.pixel = -1;
 
   fset_icon_name (f,
                  x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
@@ -3092,9 +2889,9 @@ This function is an internal primitive--use `make-frame' instead.  */)
   if (! STRINGP (f->icon_name))
     fset_icon_name (f, Qnil);
 
-  FRAME_X_DISPLAY_INFO (f) = dpyinfo;
+  FRAME_DISPLAY_INFO (f) = dpyinfo;
 
-  /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe.  */
+  /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe.  */
   record_unwind_protect (do_unwind_create_frame, frame);
 
   /* These colors will be set anyway later, but it's important
@@ -3139,7 +2936,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
     }
   else
     {
-      f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
+      f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
       f->output_data.x->explicit_parent = 0;
     }
 
@@ -3310,7 +3107,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
 
   /* Now consider the frame official.  */
   f->terminal->reference_count++;
-  FRAME_X_DISPLAY_INFO (f)->reference_count++;
+  FRAME_DISPLAY_INFO (f)->reference_count++;
   Vframe_list = Fcons (frame, Vframe_list);
 
   /* We need to do this after creating the X window, so that the
@@ -3435,7 +3232,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
 Lisp_Object
 x_get_focus_frame (struct frame *frame)
 {
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
   Lisp_Object xfocus;
   if (! dpyinfo->x_focus_frame)
     return Qnil;
@@ -3454,12 +3251,9 @@ x_get_focus_frame (struct frame *frame)
    policy.  But I think it's okay to use when it's clearly done
    following a user-command.  */
 
-DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
-       doc: /* Set the input focus to FRAME.
-FRAME nil means use the selected frame.  */)
-  (Lisp_Object frame)
+void
+x_focus_frame (struct frame *f)
 {
-  struct frame *f = decode_window_system_frame (frame);
   Display *dpy = FRAME_X_DISPLAY (f);
 
   block_input ();
@@ -3481,8 +3275,6 @@ FRAME nil means use the selected frame.  */)
 
   x_uncatch_errors ();
   unblock_input ();
-
-  return Qnil;
 }
 
 \f
@@ -3492,7 +3284,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
   (Lisp_Object color, Lisp_Object frame)
 {
   XColor foo;
-  FRAME_PTR f = decode_window_system_frame (frame);
+  struct frame *f = decode_window_system_frame (frame);
 
   CHECK_STRING (color);
 
@@ -3507,7 +3299,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
   (Lisp_Object color, Lisp_Object frame)
 {
   XColor foo;
-  FRAME_PTR f = decode_window_system_frame (frame);
+  struct frame *f = decode_window_system_frame (frame);
 
   CHECK_STRING (color);
 
@@ -3963,7 +3755,7 @@ x_make_monitor_attribute_list (struct MonitorInfo *monitors,
     {
       struct frame *f = XFRAME (frame);
 
-      if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo
+      if (FRAME_X_P (f) && FRAME_DISPLAY_INFO (f) == dpyinfo
          && !EQ (frame, tip_frame))
        {
          int i = x_get_monitor_for_frame (f, monitors, n_monitors);
@@ -4021,7 +3813,7 @@ x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo)
                        / x_display_pixel_width (dpyinfo));
   mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen)
                         / x_display_pixel_height (dpyinfo));
-  monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors));
+  monitors = xzalloc (n_monitors * sizeof *monitors);
   for (i = 0; i < n_monitors; ++i)
     {
       struct MonitorInfo *mi = &monitors[i];
@@ -4081,7 +3873,7 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo)
       return Qnil;
     }
   n_monitors = resources->noutput;
-  monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors));
+  monitors = xzalloc (n_monitors * sizeof *monitors);
 
 #ifdef HAVE_XRRGETOUTPUTPRIMARY
   pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window);
@@ -4159,6 +3951,8 @@ x_get_monitor_attributes (struct x_display_info *dpyinfo)
   Lisp_Object attributes_list = Qnil;
   Display *dpy = dpyinfo->display;
 
+  (void) dpy; /* Suppress unused variable warning.  */
+
 #ifdef HAVE_XRANDR
   int xrr_event_base, xrr_error_base;
   bool xrr_ok = false;
@@ -4237,13 +4031,13 @@ Internal use only, use `display-monitor-attributes-list' instead.  */)
 #endif
   n_monitors = gdk_screen_get_n_monitors (gscreen);
   monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
-  monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors));
+  monitors = xzalloc (n_monitors * sizeof *monitors);
 
   FOR_EACH_FRAME (rest, frame)
     {
       struct frame *f = XFRAME (frame);
 
-      if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo
+      if (FRAME_X_P (f) && FRAME_DISPLAY_INFO (f) == dpyinfo
          && !EQ (frame, tip_frame))
        {
          GdkWindow *gwin = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
@@ -4450,33 +4244,20 @@ select_visual (struct x_display_info *dpyinfo)
 static struct x_display_info *
 x_display_info_for_name (Lisp_Object name)
 {
-  Lisp_Object names;
   struct x_display_info *dpyinfo;
 
   CHECK_STRING (name);
 
-#if 0
-  if (! EQ (Vinitial_window_system, intern ("x")))
-    error ("Not using X Windows"); /* That doesn't stop us anymore. */
-#endif
-
-  for (dpyinfo = x_display_list, names = x_display_name_list;
-       dpyinfo;
-       dpyinfo = dpyinfo->next, names = XCDR (names))
-    {
-      Lisp_Object tem;
-      tem = Fstring_equal (XCAR (XCAR (names)), name);
-      if (!NILP (tem))
-       return dpyinfo;
-    }
+  for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
+    if (!NILP (Fstring_equal (XCAR (dpyinfo->name_list_element), name)))
+      return dpyinfo;
 
   /* Use this general default value to start with.  */
   Vx_resource_name = Vinvocation_name;
 
   validate_x_resource_name ();
 
-  dpyinfo = x_term_init (name, (char *)0,
-                        SSDATA (Vx_resource_name));
+  dpyinfo = x_term_init (name, 0, SSDATA (Vx_resource_name));
 
   if (dpyinfo == 0)
     error ("Cannot connect to X server %s", SDATA (name));
@@ -4504,15 +4285,7 @@ terminate Emacs if we can't open the connection.
   if (! NILP (xrm_string))
     CHECK_STRING (xrm_string);
 
-#if 0
-  if (! EQ (Vinitial_window_system, intern ("x")))
-    error ("Not using X Windows"); /* That doesn't stop us anymore. */
-#endif
-
-  if (! NILP (xrm_string))
-    xrm_option = SSDATA (xrm_string);
-  else
-    xrm_option = (char *) 0;
+  xrm_option = NILP (xrm_string) ? 0 : SSDATA (xrm_string);
 
   validate_x_resource_name ();
 
@@ -4560,11 +4333,11 @@ DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
        doc: /* Return the list of display names that Emacs has connections to.  */)
   (void)
 {
-  Lisp_Object tail, result;
+  Lisp_Object result = Qnil;
+  struct x_display_info *xdi;
 
-  result = Qnil;
-  for (tail = x_display_name_list; CONSP (tail); tail = XCDR (tail))
-    result = Fcons (XCAR (XCAR (tail)), result);
+  for (xdi = x_display_list; xdi; xdi = xdi->next)
+    result = Fcons (XCAR (xdi->name_list_element), result);
 
   return result;
 }
@@ -4593,7 +4366,7 @@ If TERMINAL is omitted or nil, that stands for the selected frame's display.  */
 /* Wait for responses to all X commands issued so far for frame F.  */
 
 void
-x_sync (FRAME_PTR f)
+x_sync (struct frame *f)
 {
   block_input ();
   XSync (FRAME_X_DISPLAY (f), False);
@@ -4758,7 +4531,7 @@ no value of TYPE (always string in the MS Windows case).  */)
     {
       CONS_TO_INTEGER (source, Window, target_window);
       if (! target_window)
-       target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
+       target_window = FRAME_DISPLAY_INFO (f)->root_window;
     }
 
   block_input ();
@@ -5053,9 +4826,12 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
   f->output_data.x->scroll_bar_top_shadow_pixel = -1;
   f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
 #endif /* USE_TOOLKIT_SCROLL_BARS */
+  f->output_data.x->white_relief.pixel = -1;
+  f->output_data.x->black_relief.pixel = -1;
+
   fset_icon_name (f, Qnil);
-  FRAME_X_DISPLAY_INFO (f) = dpyinfo;
-  f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
+  FRAME_DISPLAY_INFO (f) = dpyinfo;
+  f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
   f->output_data.x->explicit_parent = 0;
 
   /* These colors will be set anyway later, but it's important
@@ -5169,14 +4945,14 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
      happen.  */
   init_frame_faces (f);
 
-  f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
+  f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
 
   x_figure_window_size (f, parms, 0);
 
   {
     XSetWindowAttributes attrs;
     unsigned long mask;
-    Atom type = FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip;
+    Atom type = FRAME_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip;
 
     block_input ();
     mask = CWBackPixel | CWOverrideRedirect | CWEventMask;
@@ -5194,7 +4970,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
     tip_window
       = FRAME_X_WINDOW (f)
       = XCreateWindow (FRAME_X_DISPLAY (f),
-                      FRAME_X_DISPLAY_INFO (f)->root_window,
+                      FRAME_DISPLAY_INFO (f)->root_window,
                       /* x, y, width, height */
                       0, 0, 1, 1,
                       /* Border.  */
@@ -5202,7 +4978,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
                       CopyFromParent, InputOutput, CopyFromParent,
                       mask, &attrs);
     XChangeProperty (FRAME_X_DISPLAY (f), tip_window,
-                     FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type,
+                     FRAME_DISPLAY_INFO (f)->Xatom_net_window_type,
                      XA_ATOM, 32, PropModeReplace,
                      (unsigned char *)&type, 1);
     unblock_input ();
@@ -5237,10 +5013,10 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
   {
     Lisp_Object disptype;
 
-    if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
+    if (FRAME_DISPLAY_INFO (f)->n_planes == 1)
       disptype = intern ("mono");
-    else if (FRAME_X_DISPLAY_INFO (f)->visual->class == GrayScale
-             || FRAME_X_DISPLAY_INFO (f)->visual->class == StaticGray)
+    else if (FRAME_DISPLAY_INFO (f)->visual->class == GrayScale
+             || FRAME_DISPLAY_INFO (f)->visual->class == StaticGray)
       disptype = intern ("grayscale");
     else
       disptype = intern ("color");
@@ -5274,7 +5050,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
 
   /* Now that the frame will be official, it counts as a reference to
      its display and terminal.  */
-  FRAME_X_DISPLAY_INFO (f)->reference_count++;
+  FRAME_DISPLAY_INFO (f)->reference_count++;
   f->terminal->reference_count++;
 
   /* It is now ok to make the frame official even if we get an error
@@ -5318,7 +5094,7 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object
   if (!INTEGERP (left) || !INTEGERP (top))
     {
       block_input ();
-      XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
+      XQueryPointer (FRAME_X_DISPLAY (f), FRAME_DISPLAY_INFO (f)->root_window,
                     &root, &child, root_x, root_y, &win_x, &win_y, &pmask);
       unblock_input ();
     }
@@ -5328,7 +5104,7 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object
   else if (*root_y + XINT (dy) <= 0)
     *root_y = 0; /* Can happen for negative dy */
   else if (*root_y + XINT (dy) + height
-          <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f)))
+          <= x_display_pixel_height (FRAME_DISPLAY_INFO (f)))
     /* It fits below the pointer */
     *root_y += XINT (dy);
   else if (height + XINT (dy) <= *root_y)
@@ -5343,7 +5119,7 @@ compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object
   else if (*root_x + XINT (dx) <= 0)
     *root_x = 0; /* Can happen for negative dx */
   else if (*root_x + XINT (dx) + width
-          <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f)))
+          <= x_display_pixel_width (FRAME_DISPLAY_INFO (f)))
     /* It fits to the right of the pointer.  */
     *root_x += XINT (dx);
   else if (width + XINT (dx) <= *root_x)
@@ -5492,7 +5268,7 @@ Text larger than the specified size is clipped.  */)
 
   /* Create a frame for the tooltip, and record it in the global
      variable tip_frame.  */
-  frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string);
+  frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms, string);
   f = XFRAME (frame);
 
   /* Set up the frame's root window.  */
@@ -5514,7 +5290,7 @@ Text larger than the specified size is clipped.  */)
     }
 
   FRAME_TOTAL_COLS (f) = w->total_cols;
-  adjust_glyphs (f);
+  adjust_frame_glyphs (f);
   w->pseudo_window_p = 1;
 
   /* Display the tooltip text in a temporary buffer.  */
@@ -5582,7 +5358,7 @@ Text larger than the specified size is clipped.  */)
       width /= WINDOW_FRAME_COLUMN_WIDTH (w);
       w->total_cols = width;
       FRAME_TOTAL_COLS (f) = width;
-      adjust_glyphs (f);
+      adjust_frame_glyphs (f);
       clear_glyph_matrix (w->desired_matrix);
       clear_glyph_matrix (w->current_matrix);
       try_window (FRAME_ROOT_WINDOW (f), pos, 0);
@@ -5692,7 +5468,7 @@ Value is t if tooltip was open, nil otherwise.  */)
        struct frame *f = SELECTED_FRAME ();
        w = f->output_data.x->menubar_widget;
 
-       if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
+       if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f)->screen)
            && w != NULL)
          {
            block_input ();
@@ -5736,8 +5512,8 @@ DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog,
 static void
 file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data)
 {
-  int *result = (int *) client_data;
-  XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
+  int *result = client_data;
+  XmAnyCallbackStruct *cb = call_data;
   *result = cb->reason;
 }
 
@@ -5750,7 +5526,7 @@ file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data)
 static void
 file_dialog_unmap_cb (Widget widget, XtPointer client_data, XtPointer call_data)
 {
-  int *result = (int *) client_data;
+  int *result = client_data;
   *result = XmCR_CANCEL;
 }
 
@@ -5777,7 +5553,8 @@ or directory must exist.
 This function is only defined on NS, MS Windows, and X Windows with the
 Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.  */)
-  (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
+  (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename,
+   Lisp_Object mustmatch, Lisp_Object only_dir_p)
 {
   int result;
   struct frame *f = SELECTED_FRAME ();
@@ -5950,7 +5727,7 @@ Motif or Gtk toolkits.  With the Motif toolkit, ONLY-DIR-P is ignored.
 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.  */)
   (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
 {
-  FRAME_PTR f = SELECTED_FRAME ();
+  struct frame *f = SELECTED_FRAME ();
   char *fn;
   Lisp_Object file = Qnil;
   Lisp_Object decoded_file;
@@ -6013,7 +5790,7 @@ FRAME is the frame on which to pop up the font chooser.  If omitted or
 nil, it defaults to the selected frame. */)
   (Lisp_Object frame, Lisp_Object ignored)
 {
-  FRAME_PTR f = decode_window_system_frame (frame);
+  struct frame *f = decode_window_system_frame (frame);
   Lisp_Object font;
   Lisp_Object font_param;
   char *default_name = NULL;
@@ -6323,7 +6100,8 @@ Otherwise use Emacs own tooltip implementation.
 When using Gtk+ tooltips, the tooltip face is not used.  */);
   x_gtk_use_system_tooltips = 1;
 
-  Fprovide (intern_c_string ("x"), Qnil);
+  /* Tell Emacs about this window system.  */
+  Fprovide (Qx, Qnil);
 
 #ifdef USE_X_TOOLKIT
   Fprovide (intern_c_string ("x-toolkit"), Qnil);
@@ -6384,7 +6162,6 @@ When using Gtk+ tooltips, the tooltip face is not used.  */);
   defsubr (&Sx_close_connection);
   defsubr (&Sx_display_list);
   defsubr (&Sx_synchronize);
-  defsubr (&Sx_focus_frame);
   defsubr (&Sx_backspace_delete_keys_p);
 
   defsubr (&Sx_show_tip);
@@ -6406,5 +6183,3 @@ When using Gtk+ tooltips, the tooltip face is not used.  */);
   defsubr (&Sx_select_font);
 #endif
 }
-
-#endif /* HAVE_X_WINDOWS */