]> code.delx.au - gnu-emacs/blobdiff - src/xterm.c
Merge from emacs-23
[gnu-emacs] / src / xterm.c
index 22019e2279b9ced2d9c5f51e83acac6c71116b7d..4c0493891e324eec19b707b4c251b9b76edbf5e7 100644 (file)
@@ -1,7 +1,8 @@
 /* X Communication module for terminals which understand the X protocol.
-   Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-                 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-                 Free Software Foundation, Inc.
+
+Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+  2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -22,11 +23,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Xt features made by Fred Pierresteguy.  */
 
 #include <config.h>
-
-/* On 4.3 these lose if they come after xterm.h.  */
-/* Putting these at the beginning seems to be standard for other .c files.  */
 #include <signal.h>
-
 #include <stdio.h>
 #include <setjmp.h>
 
@@ -50,15 +47,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/types.h>
 #endif /* makedev */
 
-#ifdef BSD_SYSTEM
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
-#endif /* ! defined (BSD_SYSTEM) */
+#endif /* ! defined (HAVE_SYS_IOCTL_H) */
 
 #include "systime.h"
 
-#ifndef INCLUDED_FCNTL
 #include <fcntl.h>
-#endif
 #include <ctype.h>
 #include <errno.h>
 #include <setjmp.h>
@@ -106,13 +101,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif
 
 #ifdef USE_LUCID
-extern int xlwmenu_window_p P_ ((Widget w, Window window));
-extern void xlwmenu_redisplay P_ ((Widget));
-#endif
-
-#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
-
-extern void free_frame_menubar P_ ((struct frame *));
+#include "../lwlib/xlwmenu.h"
 #endif
 
 #ifdef USE_X_TOOLKIT
@@ -296,25 +285,6 @@ static int input_signal_count;
 
 static int x_noop_count;
 
-/* Initial values of argv and argc.  */
-
-extern char **initial_argv;
-extern int initial_argc;
-
-extern Lisp_Object Vcommand_line_args, Vsystem_name;
-
-/* Tells if a window manager is present or not.  */
-
-extern Lisp_Object Vx_no_window_manager;
-
-extern Lisp_Object Qeql;
-
-extern int errno;
-
-/* A mask of extra modifier bits to put into every keyboard char.  */
-
-extern EMACS_INT extra_keyboard_modifiers;
-
 /* The keysyms to use for the various modifiers.  */
 
 Lisp_Object Vx_alt_keysym, Vx_hyper_keysym, Vx_meta_keysym, Vx_super_keysym;
@@ -332,65 +302,66 @@ static Lisp_Object xg_default_icon_file;
 Lisp_Object Qx_gtk_map_stock;
 #endif
 
+/* Some functions take this as char *, not const char *.  */
+static char emacs_class[] = EMACS_CLASS;
+
 /* Used in x_flush.  */
 
-extern Lisp_Object Vinhibit_redisplay;
-
-extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
-extern int x_bitmap_mask P_ ((FRAME_PTR, int));
-
-static int x_alloc_nearest_color_1 P_ ((Display *, Colormap, XColor *));
-static void x_set_window_size_1 P_ ((struct frame *, int, int, int));
-static const XColor *x_color_cells P_ ((Display *, int *));
-static void x_update_window_end P_ ((struct window *, int, int));
-
-static int x_io_error_quitter P_ ((Display *));
-static struct terminal *x_create_terminal P_ ((struct x_display_info *));
-void x_delete_terminal P_ ((struct terminal *));
-static void x_update_end P_ ((struct frame *));
-static void XTframe_up_to_date P_ ((struct frame *));
-static void XTset_terminal_modes P_ ((struct terminal *));
-static void XTreset_terminal_modes P_ ((struct terminal *));
-static void x_clear_frame P_ ((struct frame *));
-static void frame_highlight P_ ((struct frame *));
-static void frame_unhighlight P_ ((struct frame *));
-static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *));
-static void  x_focus_changed P_ ((int, int, struct x_display_info *,
-                                 struct frame *, struct input_event *));
-static void x_detect_focus_change P_ ((struct x_display_info *,
-                                       XEvent *, struct input_event *));
-static void XTframe_rehighlight P_ ((struct frame *));
-static void x_frame_rehighlight P_ ((struct x_display_info *));
-static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *));
-static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int,
-                                  enum text_cursor_kinds));
-
-static void x_clip_to_row P_ ((struct window *, struct glyph_row *, int, GC));
-static void x_flush P_ ((struct frame *f));
-static void x_update_begin P_ ((struct frame *));
-static void x_update_window_begin P_ ((struct window *));
-static void x_after_update_window_line P_ ((struct glyph_row *));
-static struct scroll_bar *x_window_to_scroll_bar P_ ((Display *, Window));
-static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
-                                           enum scroll_bar_part *,
-                                           Lisp_Object *, Lisp_Object *,
-                                           unsigned long *));
-static void x_handle_net_wm_state P_ ((struct frame *, XPropertyEvent *));
-static void x_check_fullscreen P_ ((struct frame *));
-static void x_check_expected_move P_ ((struct frame *, int, int));
-static void x_sync_with_move P_ ((struct frame *, int, int, int));
-static int handle_one_xevent P_ ((struct x_display_info *, XEvent *,
-                                 int *, struct input_event *));
+extern XrmDatabase x_load_resources (Display *, const char *, const char *,
+                                    const char *);
+extern int x_bitmap_mask (FRAME_PTR, int);
+
+static int x_alloc_nearest_color_1 (Display *, Colormap, XColor *);
+static void x_set_window_size_1 (struct frame *, int, int, int);
+static const XColor *x_color_cells (Display *, int *);
+static void x_update_window_end (struct window *, int, int);
+
+static int x_io_error_quitter (Display *);
+static struct terminal *x_create_terminal (struct x_display_info *);
+void x_delete_terminal (struct terminal *);
+static void x_update_end (struct frame *);
+static void XTframe_up_to_date (struct frame *);
+static void XTset_terminal_modes (struct terminal *);
+static void XTreset_terminal_modes (struct terminal *);
+static void x_clear_frame (struct frame *);
+static void frame_highlight (struct frame *);
+static void frame_unhighlight (struct frame *);
+static void x_new_focus_frame (struct x_display_info *, struct frame *);
+static void  x_focus_changed (int, int, struct x_display_info *,
+                              struct frame *, struct input_event *);
+static void x_detect_focus_change (struct x_display_info *,
+                                   XEvent *, struct input_event *);
+static void XTframe_rehighlight (struct frame *);
+static void x_frame_rehighlight (struct x_display_info *);
+static void x_draw_hollow_cursor (struct window *, struct glyph_row *);
+static void x_draw_bar_cursor (struct window *, struct glyph_row *, int,
+                               enum text_cursor_kinds);
+
+static void x_clip_to_row (struct window *, struct glyph_row *, int, GC);
+static void x_flush (struct frame *f);
+static void x_update_begin (struct frame *);
+static void x_update_window_begin (struct window *);
+static void x_after_update_window_line (struct glyph_row *);
+static struct scroll_bar *x_window_to_scroll_bar (Display *, Window);
+static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
+                                        enum scroll_bar_part *,
+                                        Lisp_Object *, Lisp_Object *,
+                                        unsigned long *);
+static void x_handle_net_wm_state (struct frame *, XPropertyEvent *);
+static void x_check_fullscreen (struct frame *);
+static void x_check_expected_move (struct frame *, int, int);
+static void x_sync_with_move (struct frame *, int, int, int);
+static int handle_one_xevent (struct x_display_info *, XEvent *,
+                              int *, struct input_event *);
 /* Don't declare this NO_RETURN because we want no
    interference with debugging failing X calls.  */
-static SIGTYPE x_connection_closed P_ ((Display *, char *));
+static SIGTYPE x_connection_closed (Display *, const char *);
 
 
 /* Flush display of frame F, or of all frames if F is null.  */
 
 static void
-x_flush (f)
-     struct frame *f;
+x_flush (struct frame *f)
 {
   /* Don't call XFlush when it is not safe to redisplay; the X
      connection may be broken.  */
@@ -459,8 +430,7 @@ record_event (locus, type)
 /* Return the struct x_display_info corresponding to DPY.  */
 
 struct x_display_info *
-x_display_info_for_display (dpy)
-     Display *dpy;
+x_display_info_for_display (Display *dpy)
 {
   struct x_display_info *dpyinfo;
 
@@ -475,8 +445,7 @@ x_display_info_for_display (dpy)
 #define OPACITY "_NET_WM_WINDOW_OPACITY"
 
 void
-x_set_frame_alpha (f)
-     struct frame *f;
+x_set_frame_alpha (struct frame *f)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Display *dpy = FRAME_X_DISPLAY (f);
@@ -488,7 +457,7 @@ x_set_frame_alpha (f)
   if (FRAME_X_DISPLAY_INFO (f)->root_window != FRAME_X_OUTPUT (f)->parent_desc)
     /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
        we must treat the former instead of the latter. */
-    win = FRAME_X_OUTPUT(f)->parent_desc;
+    win = FRAME_X_OUTPUT (f)->parent_desc;
 
   if (dpyinfo->x_highlight_frame == f)
     alpha = f->alpha[0];
@@ -517,10 +486,10 @@ x_set_frame_alpha (f)
     unsigned long n, left;
 
     x_catch_errors (dpy);
-    rc = XGetWindowProperty(dpy, win, XInternAtom(dpy, OPACITY, False),
-                           0L, 1L, False, XA_CARDINAL,
-                           &actual, &format, &n, &left,
-                           &data);
+    rc = XGetWindowProperty (dpy, win, XInternAtom(dpy, OPACITY, False),
+                            0L, 1L, False, XA_CARDINAL,
+                            &actual, &format, &n, &left,
+                            &data);
 
     if (rc == Success && actual != None)
       if (*(unsigned long *)data == opac)
@@ -542,15 +511,13 @@ x_set_frame_alpha (f)
 }
 
 int
-x_display_pixel_height (dpyinfo)
-     struct x_display_info *dpyinfo;
+x_display_pixel_height (struct x_display_info *dpyinfo)
 {
   return HeightOfScreen (dpyinfo->screen);
 }
 
 int
-x_display_pixel_width (dpyinfo)
-     struct x_display_info *dpyinfo;
+x_display_pixel_width (struct x_display_info *dpyinfo)
 {
   return WidthOfScreen (dpyinfo->screen);
 }
@@ -567,8 +534,7 @@ x_display_pixel_width (dpyinfo)
    because all interesting stuff is done on a window basis.  */
 
 static void
-x_update_begin (f)
-     struct frame *f;
+x_update_begin (struct frame *f)
 {
   /* Nothing to do.  */
 }
@@ -579,26 +545,25 @@ x_update_begin (f)
    position of W.  */
 
 static void
-x_update_window_begin (w)
-     struct window *w;
+x_update_window_begin (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
-  struct x_display_info *display_info = FRAME_X_DISPLAY_INFO (f);
+  Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
 
   updated_window = w;
   set_output_cursor (&w->cursor);
 
   BLOCK_INPUT;
 
-  if (f == display_info->mouse_face_mouse_frame)
+  if (f == hlinfo->mouse_face_mouse_frame)
     {
       /* Don't do highlighting for mouse motion during the update.  */
-      display_info->mouse_face_defer = 1;
+      hlinfo->mouse_face_defer = 1;
 
       /* If F needs to be redrawn, simply forget about any prior mouse
         highlighting.  */
       if (FRAME_GARBAGED_P (f))
-       display_info->mouse_face_window = Qnil;
+       hlinfo->mouse_face_window = Qnil;
     }
 
   UNBLOCK_INPUT;
@@ -608,9 +573,7 @@ x_update_window_begin (w)
 /* Draw a vertical window border from (x,y0) to (x,y1)  */
 
 static void
-x_draw_vertical_window_border (w, x, y0, y1)
-     struct window *w;
-     int x, y0, y1;
+x_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   struct face *face;
@@ -638,11 +601,9 @@ x_draw_vertical_window_border (w, x, y0, y1)
    here.  */
 
 static void
-x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
-     struct window *w;
-     int cursor_on_p, mouse_face_overwritten_p;
+x_update_window_end (struct window *w, int cursor_on_p, int mouse_face_overwritten_p)
 {
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (w->frame));
+  Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
 
   if (!w->pseudo_window_p)
     {
@@ -663,9 +624,9 @@ x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
      XTframe_up_to_date to redisplay the mouse highlight.  */
   if (mouse_face_overwritten_p)
     {
-      dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
-      dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
-      dpyinfo->mouse_face_window = Qnil;
+      hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
+      hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
+      hlinfo->mouse_face_window = Qnil;
     }
 
   updated_window = NULL;
@@ -676,11 +637,10 @@ x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
    update_end.  */
 
 static void
-x_update_end (f)
-     struct frame *f;
+x_update_end (struct frame *f)
 {
   /* Mouse highlight may be displayed again.  */
-  FRAME_X_DISPLAY_INFO (f)->mouse_face_defer = 0;
+  MOUSE_HL_INFO (f)->mouse_face_defer = 0;
 
 #ifndef XFlush
   BLOCK_INPUT;
@@ -695,22 +655,21 @@ x_update_end (f)
    updated_window is not available here.  */
 
 static void
-XTframe_up_to_date (f)
-     struct frame *f;
+XTframe_up_to_date (struct frame *f)
 {
   if (FRAME_X_P (f))
     {
-      struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+      Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
 
-      if (dpyinfo->mouse_face_deferred_gc
-         || f == dpyinfo->mouse_face_mouse_frame)
+      if (hlinfo->mouse_face_deferred_gc
+         || f == hlinfo->mouse_face_mouse_frame)
        {
          BLOCK_INPUT;
-         if (dpyinfo->mouse_face_mouse_frame)
-           note_mouse_highlight (dpyinfo->mouse_face_mouse_frame,
-                                 dpyinfo->mouse_face_mouse_x,
-                                 dpyinfo->mouse_face_mouse_y);
-         dpyinfo->mouse_face_deferred_gc = 0;
+         if (hlinfo->mouse_face_mouse_frame)
+           note_mouse_highlight (hlinfo->mouse_face_mouse_frame,
+                                 hlinfo->mouse_face_mouse_x,
+                                 hlinfo->mouse_face_mouse_y);
+         hlinfo->mouse_face_deferred_gc = 0;
          UNBLOCK_INPUT;
        }
     }
@@ -725,8 +684,7 @@ XTframe_up_to_date (f)
    between bitmaps to be drawn between current row and DESIRED_ROW.  */
 
 static void
-x_after_update_window_line (desired_row)
-     struct glyph_row *desired_row;
+x_after_update_window_line (struct glyph_row *desired_row)
 {
   struct window *w = updated_window;
   struct frame *f;
@@ -764,10 +722,7 @@ x_after_update_window_line (desired_row)
 }
 
 static void
-x_draw_fringe_bitmap (w, row, p)
-     struct window *w;
-     struct glyph_row *row;
-     struct draw_fringe_bitmap_params *p;
+x_draw_fringe_bitmap (struct window *w, struct glyph_row *row, struct draw_fringe_bitmap_params *p)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   Display *display = FRAME_X_DISPLAY (f);
@@ -920,37 +875,37 @@ XTreset_terminal_modes (struct terminal *terminal)
 
 
 
-static void x_set_glyph_string_clipping P_ ((struct glyph_string *));
-static void x_set_glyph_string_gc P_ ((struct glyph_string *));
-static void x_draw_glyph_string_background P_ ((struct glyph_string *,
-                                               int));
-static void x_draw_glyph_string_foreground P_ ((struct glyph_string *));
-static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *));
-static void x_draw_glyph_string_box P_ ((struct glyph_string *));
-static void x_draw_glyph_string  P_ ((struct glyph_string *));
-static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *));
-static void x_set_cursor_gc P_ ((struct glyph_string *));
-static void x_set_mode_line_face_gc P_ ((struct glyph_string *));
-static void x_set_mouse_face_gc P_ ((struct glyph_string *));
-static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap,
-                                     unsigned long *, double, int));
-static void x_setup_relief_color P_ ((struct frame *, struct relief *,
-                                     double, int, unsigned long));
-static void x_setup_relief_colors P_ ((struct glyph_string *));
-static void x_draw_image_glyph_string P_ ((struct glyph_string *));
-static void x_draw_image_relief P_ ((struct glyph_string *));
-static void x_draw_image_foreground P_ ((struct glyph_string *));
-static void x_draw_image_foreground_1 P_ ((struct glyph_string *, Pixmap));
-static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int,
-                                          int, int, int));
-static void x_draw_relief_rect P_ ((struct frame *, int, int, int, int,
-                                   int, int, int, int, int, int,
-                                   XRectangle *));
-static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int,
-                                int, int, int, XRectangle *));
+static void x_set_glyph_string_clipping (struct glyph_string *);
+static void x_set_glyph_string_gc (struct glyph_string *);
+static void x_draw_glyph_string_background (struct glyph_string *,
+                                            int);
+static void x_draw_glyph_string_foreground (struct glyph_string *);
+static void x_draw_composite_glyph_string_foreground (struct glyph_string *);
+static void x_draw_glyph_string_box (struct glyph_string *);
+static void x_draw_glyph_string  (struct glyph_string *);
+static void x_compute_glyph_string_overhangs (struct glyph_string *);
+static void x_set_cursor_gc (struct glyph_string *);
+static void x_set_mode_line_face_gc (struct glyph_string *);
+static void x_set_mouse_face_gc (struct glyph_string *);
+static int x_alloc_lighter_color (struct frame *, Display *, Colormap,
+                                  unsigned long *, double, int);
+static void x_setup_relief_color (struct frame *, struct relief *,
+                                  double, int, unsigned long);
+static void x_setup_relief_colors (struct glyph_string *);
+static void x_draw_image_glyph_string (struct glyph_string *);
+static void x_draw_image_relief (struct glyph_string *);
+static void x_draw_image_foreground (struct glyph_string *);
+static void x_draw_image_foreground_1 (struct glyph_string *, Pixmap);
+static void x_clear_glyph_string_rect (struct glyph_string *, int,
+                                       int, int, int);
+static void x_draw_relief_rect (struct frame *, int, int, int, int,
+                                int, int, int, int, int, int,
+                                XRectangle *);
+static void x_draw_box_rect (struct glyph_string *, int, int, int, int,
+                             int, int, int, XRectangle *);
 
 #if GLYPH_DEBUG
-static void x_check_font P_ ((struct frame *, struct font *));
+static void x_check_font (struct frame *, struct font *);
 #endif
 
 
@@ -958,8 +913,7 @@ static void x_check_font P_ ((struct frame *, struct font *));
    face.  */
 
 static void
-x_set_cursor_gc (s)
-     struct glyph_string *s;
+x_set_cursor_gc (struct glyph_string *s)
 {
   if (s->font == FRAME_FONT (s->f)
       && s->face->background == FRAME_BACKGROUND_PIXEL (s->f)
@@ -1010,14 +964,13 @@ x_set_cursor_gc (s)
 /* Set up S->gc of glyph string S for drawing text in mouse face.  */
 
 static void
-x_set_mouse_face_gc (s)
-     struct glyph_string *s;
+x_set_mouse_face_gc (struct glyph_string *s)
 {
   int face_id;
   struct face *face;
 
   /* What face has to be used last for the mouse face?  */
-  face_id = FRAME_X_DISPLAY_INFO (s->f)->mouse_face_face_id;
+  face_id = MOUSE_HL_INFO (s->f)->mouse_face_face_id;
   face = FACE_FROM_ID (s->f, face_id);
   if (face == NULL)
     face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
@@ -1062,8 +1015,7 @@ x_set_mouse_face_gc (s)
    matrix was built, so there isn't much to do, here.  */
 
 static INLINE void
-x_set_mode_line_face_gc (s)
-     struct glyph_string *s;
+x_set_mode_line_face_gc (struct glyph_string *s)
 {
   s->gc = s->face->gc;
 }
@@ -1074,8 +1026,7 @@ x_set_mode_line_face_gc (s)
    pattern.  */
 
 static INLINE void
-x_set_glyph_string_gc (s)
-     struct glyph_string *s;
+x_set_glyph_string_gc (struct glyph_string *s)
 {
   PREPARE_FACE_FOR_DISPLAY (s->f, s->face);
 
@@ -1120,8 +1071,7 @@ x_set_glyph_string_gc (s)
    line or menu if we don't have X toolkit support.  */
 
 static INLINE void
-x_set_glyph_string_clipping (s)
-     struct glyph_string *s;
+x_set_glyph_string_clipping (struct glyph_string *s)
 {
   XRectangle *r = s->clip;
   int n = get_glyph_string_clip_rects (s, r, 2);
@@ -1137,8 +1087,7 @@ x_set_glyph_string_clipping (s)
    the area of SRC.  */
 
 static void
-x_set_glyph_string_clipping_exactly (src, dst)
-     struct glyph_string *src, *dst;
+x_set_glyph_string_clipping_exactly (struct glyph_string *src, struct glyph_string *dst)
 {
   XRectangle r;
 
@@ -1156,8 +1105,7 @@ x_set_glyph_string_clipping_exactly (src, dst)
    Compute left and right overhang of glyph string S.  */
 
 static void
-x_compute_glyph_string_overhangs (s)
-     struct glyph_string *s;
+x_compute_glyph_string_overhangs (struct glyph_string *s)
 {
   if (s->cmp == NULL
       && (s->first_glyph->type == CHAR_GLYPH
@@ -1196,9 +1144,7 @@ x_compute_glyph_string_overhangs (s)
 /* Fill rectangle X, Y, W, H with background color of glyph string S.  */
 
 static INLINE void
-x_clear_glyph_string_rect (s, x, y, w, h)
-     struct glyph_string *s;
-     int x, y, w, h;
+x_clear_glyph_string_rect (struct glyph_string *s, int x, int y, int w, int h)
 {
   XGCValues xgcv;
   XGetGCValues (s->display, s->gc, GCForeground | GCBackground, &xgcv);
@@ -1215,9 +1161,7 @@ x_clear_glyph_string_rect (s, x, y, w, h)
    contains the first component of a composition.  */
 
 static void
-x_draw_glyph_string_background (s, force_p)
-     struct glyph_string *s;
-     int force_p;
+x_draw_glyph_string_background (struct glyph_string *s, int force_p)
 {
   /* Nothing to do if background has already been drawn or if it
      shouldn't be drawn in the first place.  */
@@ -1253,8 +1197,7 @@ x_draw_glyph_string_background (s, force_p)
 /* Draw the foreground of glyph string S.  */
 
 static void
-x_draw_glyph_string_foreground (s)
-     struct glyph_string *s;
+x_draw_glyph_string_foreground (struct glyph_string *s)
 {
   int i, x;
 
@@ -1302,8 +1245,7 @@ x_draw_glyph_string_foreground (s)
 /* Draw the foreground of composite glyph string S.  */
 
 static void
-x_draw_composite_glyph_string_foreground (s)
-     struct glyph_string *s;
+x_draw_composite_glyph_string_foreground (struct glyph_string *s)
 {
   int i, j, x;
   struct font *font = s->font;
@@ -1388,21 +1330,97 @@ x_draw_composite_glyph_string_foreground (s)
 }
 
 
+/* Draw the foreground of glyph string S for glyphless characters.  */
+
+static void
+x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
+{
+  struct glyph *glyph = s->first_glyph;
+  XChar2b char2b[8];
+  int x, i, j;
+
+  /* If first glyph of S has a left box line, start drawing the text
+     of S to the right of that box line.  */
+  if (s->face && s->face->box != FACE_NO_BOX
+      && s->first_glyph->left_box_line_p)
+    x = s->x + eabs (s->face->box_line_width);
+  else
+    x = s->x;
+
+  s->char2b = char2b;
+
+  for (i = 0; i < s->nchars; i++, glyph++)
+    {
+      char buf[7], *str = NULL;
+      int len = glyph->u.glyphless.len;
+
+      if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_ACRONYM)
+       {
+         if (len > 0
+             && CHAR_TABLE_P (Vglyphless_char_display)
+             && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display))
+                 >= 1))
+           {
+             Lisp_Object acronym
+               = (! glyph->u.glyphless.for_no_font
+                  ? CHAR_TABLE_REF (Vglyphless_char_display,
+                                    glyph->u.glyphless.ch)
+                  : XCHAR_TABLE (Vglyphless_char_display)->extras[0]);
+             if (STRINGP (acronym))
+               str = (char *) SDATA (acronym);
+           }
+       }
+      else if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEXA_CODE)
+       {
+         sprintf ((char *) buf, "%0*X",
+                  glyph->u.glyphless.ch < 0x10000 ? 4 : 6,
+                  glyph->u.glyphless.ch);
+         str = buf;
+       }
+
+      if (str)
+       {
+         int upper_len = (len + 1) / 2;
+         unsigned code;
+
+         /* It is assured that all LEN characters in STR is ASCII.  */
+         for (j = 0; j < len; j++)
+           {
+             code = s->font->driver->encode_char (s->font, str[j]);
+             STORE_XCHAR2B (char2b + j, code >> 8, code & 0xFF);
+           }
+         s->font->driver->draw (s, 0, upper_len,
+                                x + glyph->slice.glyphless.upper_xoff,
+                                s->ybase + glyph->slice.glyphless.upper_yoff,
+                                0);
+         s->font->driver->draw (s, upper_len, len,
+                                x + glyph->slice.glyphless.lower_xoff,
+                                s->ybase + glyph->slice.glyphless.lower_yoff,
+                                0);
+       }
+      if (glyph->u.glyphless.method != GLYPHLESS_DISPLAY_THIN_SPACE)
+       XDrawRectangle (s->display, s->window, s->gc,
+                       x, s->ybase - glyph->ascent,
+                       glyph->pixel_width - 1,
+                       glyph->ascent + glyph->descent - 1);
+      x += glyph->pixel_width;
+   }
+}
+
 #ifdef USE_X_TOOLKIT
 
-static struct frame *x_frame_of_widget P_ ((Widget));
-static Boolean cvt_string_to_pixel P_ ((Display *, XrmValue *, Cardinal *,
-                                       XrmValue *, XrmValue *, XtPointer *));
-static void cvt_pixel_dtor P_ ((XtAppContext, XrmValue *, XtPointer,
-                               XrmValue *, Cardinal *));
+static struct frame *x_frame_of_widget (Widget);
+static Boolean cvt_string_to_pixel (Display *, XrmValue *, Cardinal *,
+                                    XrmValue *, XrmValue *, XtPointer *);
+static void cvt_pixel_dtor (XtAppContext, XrmValue *, XtPointer,
+                            XrmValue *, Cardinal *);
 
 
 /* Return the frame on which widget WIDGET is used.. Abort if frame
    cannot be determined.  */
 
 static struct frame *
-x_frame_of_widget (widget)
-     Widget widget;
+x_frame_of_widget (Widget widget)
 {
   struct x_display_info *dpyinfo;
   Lisp_Object tail;
@@ -1438,10 +1456,7 @@ x_frame_of_widget (widget)
    if successful.  This is called from lwlib.  */
 
 int
-x_alloc_nearest_color_for_widget (widget, cmap, color)
-     Widget widget;
-     Colormap cmap;
-     XColor *color;
+x_alloc_nearest_color_for_widget (Widget widget, Colormap cmap, XColor *color)
 {
   struct frame *f = x_frame_of_widget (widget);
   return x_alloc_nearest_color (f, cmap, color);
@@ -1456,13 +1471,8 @@ x_alloc_nearest_color_for_widget (widget, cmap, color)
    Value is non-zero if successful.  */
 
 int
-x_alloc_lighter_color_for_widget (widget, display, cmap, pixel, factor, delta)
-     Widget widget;
-     Display *display;
-     Colormap cmap;
-     unsigned long *pixel;
-     double factor;
-     int delta;
+x_alloc_lighter_color_for_widget (Widget widget, Display *display, Colormap cmap,
+                                 unsigned long *pixel, double factor, int delta)
 {
   struct frame *f = x_frame_of_widget (widget);
   return x_alloc_lighter_color (f, display, cmap, pixel, factor, delta);
@@ -1505,12 +1515,9 @@ static Pixel cvt_string_to_pixel_value;
    Value is True if successful, False otherwise.  */
 
 static Boolean
-cvt_string_to_pixel (dpy, args, nargs, from, to, closure_ret)
-     Display *dpy;
-     XrmValue *args;
-     Cardinal *nargs;
-     XrmValue *from, *to;
-     XtPointer *closure_ret;
+cvt_string_to_pixel (Display *dpy, XrmValue *args, Cardinal *nargs,
+                    XrmValue *from, XrmValue *to,
+                    XtPointer *closure_ret)
 {
   Screen *screen;
   Colormap cmap;
@@ -1594,12 +1601,8 @@ cvt_string_to_pixel (dpy, args, nargs, from, to, closure_ret)
    ARGS and NARGS are like for cvt_string_to_pixel.  */
 
 static void
-cvt_pixel_dtor (app, to, closure, args, nargs)
-    XtAppContext app;
-    XrmValuePtr to;
-    XtPointer closure;
-    XrmValuePtr args;
-    Cardinal *nargs;
+cvt_pixel_dtor (XtAppContext app, XrmValuePtr to, XtPointer closure, XrmValuePtr args,
+               Cardinal *nargs)
 {
   if (*nargs != 2)
     {
@@ -1628,9 +1631,7 @@ cvt_pixel_dtor (app, to, closure, args, nargs)
    say a 24-bit TrueColor map.  */
 
 static const XColor *
-x_color_cells (dpy, ncells)
-     Display *dpy;
-     int *ncells;
+x_color_cells (Display *dpy, int *ncells)
 {
   struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
 
@@ -1661,10 +1662,7 @@ x_color_cells (dpy, ncells)
    colors in COLORS.  Use cached information, if available.  */
 
 void
-x_query_colors (f, colors, ncolors)
-     struct frame *f;
-     XColor *colors;
-     int ncolors;
+x_query_colors (struct frame *f, XColor *colors, int ncolors)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
 
@@ -1688,9 +1686,7 @@ x_query_colors (f, colors, ncolors)
    COLOR.  Use cached information, if available.  */
 
 void
-x_query_color (f, color)
-     struct frame *f;
-     XColor *color;
+x_query_color (struct frame *f, XColor *color)
 {
   x_query_colors (f, color, 1);
 }
@@ -1702,10 +1698,7 @@ x_query_color (f, color)
    allocated.  */
 
 static int
-x_alloc_nearest_color_1 (dpy, cmap, color)
-     Display *dpy;
-     Colormap cmap;
-     XColor *color;
+x_alloc_nearest_color_1 (Display *dpy, Colormap cmap, XColor *color)
 {
   int rc;
 
@@ -1775,10 +1768,7 @@ x_alloc_nearest_color_1 (dpy, cmap, color)
    allocated.  */
 
 int
-x_alloc_nearest_color (f, cmap, color)
-     struct frame *f;
-     Colormap cmap;
-     XColor *color;
+x_alloc_nearest_color (struct frame *f, Colormap cmap, XColor *color)
 {
   gamma_correct (f, color);
   return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f), cmap, color);
@@ -1790,9 +1780,7 @@ x_alloc_nearest_color (f, cmap, color)
    get color reference counts right.  */
 
 unsigned long
-x_copy_color (f, pixel)
-     struct frame *f;
-     unsigned long pixel;
+x_copy_color (struct frame *f, long unsigned int pixel)
 {
   XColor color;
 
@@ -1813,10 +1801,7 @@ x_copy_color (f, pixel)
    get color reference counts right.  */
 
 unsigned long
-x_copy_dpy_color (dpy, cmap, pixel)
-     Display *dpy;
-     Colormap cmap;
-     unsigned long pixel;
+x_copy_dpy_color (Display *dpy, Colormap cmap, long unsigned int pixel)
 {
   XColor color;
 
@@ -1854,13 +1839,7 @@ x_copy_dpy_color (dpy, cmap, pixel)
    Value is non-zero if successful.  */
 
 static int
-x_alloc_lighter_color (f, display, cmap, pixel, factor, delta)
-     struct frame *f;
-     Display *display;
-     Colormap cmap;
-     unsigned long *pixel;
-     double factor;
-     int delta;
+x_alloc_lighter_color (struct frame *f, Display *display, Colormap cmap, long unsigned int *pixel, double factor, int delta)
 {
   XColor color, new;
   long bright;
@@ -1936,12 +1915,7 @@ x_alloc_lighter_color (f, display, cmap, pixel, factor, delta)
    be allocated, use DEFAULT_PIXEL, instead.  */
 
 static void
-x_setup_relief_color (f, relief, factor, delta, default_pixel)
-     struct frame *f;
-     struct relief *relief;
-     double factor;
-     int delta;
-     unsigned long default_pixel;
+x_setup_relief_color (struct frame *f, struct relief *relief, double factor, int delta, long unsigned int default_pixel)
 {
   XGCValues xgcv;
   struct x_output *di = f->output_data.x;
@@ -1989,8 +1963,7 @@ x_setup_relief_color (f, relief, factor, delta, default_pixel)
 /* Set up colors for the relief lines around glyph string S.  */
 
 static void
-x_setup_relief_colors (s)
-     struct glyph_string *s;
+x_setup_relief_colors (struct glyph_string *s)
 {
   struct x_output *di = s->f->output_data.x;
   unsigned long color;
@@ -2031,12 +2004,10 @@ x_setup_relief_colors (s)
    when drawing.  */
 
 static void
-x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
-                   raised_p, top_p, bot_p, left_p, right_p, clip_rect)
-     struct frame *f;
-     int left_x, top_y, right_x, bottom_y, width;
-     int top_p, bot_p, left_p, right_p, raised_p;
-     XRectangle *clip_rect;
+x_draw_relief_rect (struct frame *f,
+                   int left_x, int top_y, int right_x, int bottom_y, int width,
+                   int raised_p, int top_p, int bot_p, int left_p, int right_p,
+                   XRectangle *clip_rect)
 {
   Display *dpy = FRAME_X_DISPLAY (f);
   Window window = FRAME_X_WINDOW (f);
@@ -2049,18 +2020,38 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
     gc = f->output_data.x->black_relief.gc;
   XSetClipRectangles (dpy, gc, 0, 0, clip_rect, 1, Unsorted);
 
+  /* This code is more complicated than it has to be, because of two
+     minor hacks to make the boxes look nicer: (i) if width > 1, draw
+     the outermost line using the black relief.  (ii) Omit the four
+     corner pixels.  */
+
   /* Top.  */
   if (top_p)
-    for (i = 0; i < width; ++i)
-      XDrawLine (dpy, window, gc,
-                left_x + i * left_p, top_y + i,
-                right_x + 1 - i * right_p, top_y + i);
+    {
+      if (width == 1)
+       XDrawLine (dpy, window, gc,
+                  left_x  + (left_p  ? 1 : 0), top_y,
+                  right_x + (right_p ? 0 : 1), top_y);
+
+      for (i = 1; i < width; ++i)
+       XDrawLine (dpy, window, gc,
+                  left_x  + i * left_p, top_y + i,
+                  right_x + 1 - i * right_p, top_y + i);
+    }
 
   /* Left.  */
   if (left_p)
-    for (i = 0; i < width; ++i)
-      XDrawLine (dpy, window, gc,
-                left_x + i, top_y + i, left_x + i, bottom_y - i + 1);
+    {
+      if (width == 1)
+       XDrawLine (dpy, window, gc, left_x, top_y + 1, left_x, bottom_y);
+
+      XClearArea (dpy, window, left_x, top_y, 1, 1, False);
+      XClearArea (dpy, window, left_x, bottom_y, 1, 1, False);
+
+      for (i = (width > 1 ? 1 : 0); i < width; ++i)
+       XDrawLine (dpy, window, gc,
+                  left_x + i, top_y + i, left_x + i, bottom_y - i + 1);
+    }
 
   XSetClipMask (dpy, gc, None);
   if (raised_p)
@@ -2069,18 +2060,40 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
     gc = f->output_data.x->white_relief.gc;
   XSetClipRectangles (dpy, gc, 0, 0, clip_rect, 1, Unsorted);
 
+  if (width > 1)
+    {
+      /* Outermost top line.  */
+      if (top_p)
+       XDrawLine (dpy, window, gc,
+                  left_x  + (left_p  ? 1 : 0), top_y,
+                  right_x + (right_p ? 0 : 1), top_y);
+
+      /* Outermost left line.  */
+      if (left_p)
+       XDrawLine (dpy, window, gc, left_x, top_y + 1, left_x, bottom_y);
+    }
+
   /* Bottom.  */
   if (bot_p)
-    for (i = 0; i < width; ++i)
+    {
       XDrawLine (dpy, window, gc,
-                left_x + i * left_p, bottom_y - i,
-                right_x + 1 - i * right_p, bottom_y - i);
+                left_x  + (left_p  ? 1 : 0), bottom_y,
+                right_x + (right_p ? 0 : 1), bottom_y);
+      for (i = 1; i < width; ++i)
+       XDrawLine (dpy, window, gc,
+                  left_x  + i * left_p, bottom_y - i,
+                  right_x + 1 - i * right_p, bottom_y - i);
+    }
 
   /* Right.  */
   if (right_p)
-    for (i = 0; i < width; ++i)
-      XDrawLine (dpy, window, gc,
-                right_x - i, top_y + i + 1, right_x - i, bottom_y - i);
+    {
+      XClearArea (dpy, window, right_x, top_y, 1, 1, False);
+      XClearArea (dpy, window, right_x, bottom_y, 1, 1, False);
+      for (i = 0; i < width; ++i)
+       XDrawLine (dpy, window, gc,
+                  right_x - i, top_y + i + 1, right_x - i, bottom_y - i);
+    }
 
   XSetClipMask (dpy, gc, None);
 }
@@ -2094,11 +2107,9 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width,
    rectangle to use when drawing.  */
 
 static void
-x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width,
-                left_p, right_p, clip_rect)
-     struct glyph_string *s;
-     int left_x, top_y, right_x, bottom_y, width, left_p, right_p;
-     XRectangle *clip_rect;
+x_draw_box_rect (struct glyph_string *s,
+                int left_x, int top_y, int right_x, int bottom_y, int width,
+                int left_p, int right_p, XRectangle *clip_rect)
 {
   XGCValues xgcv;
 
@@ -2132,8 +2143,7 @@ x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width,
 /* Draw a box around glyph string S.  */
 
 static void
-x_draw_glyph_string_box (s)
-     struct glyph_string *s;
+x_draw_glyph_string_box (struct glyph_string *s)
 {
   int width, left_x, right_x, top_y, bottom_y, last_x, raised_p;
   int left_p, right_p;
@@ -2184,8 +2194,7 @@ x_draw_glyph_string_box (s)
 /* Draw foreground of image glyph string S.  */
 
 static void
-x_draw_image_foreground (s)
-     struct glyph_string *s;
+x_draw_image_foreground (struct glyph_string *s)
 {
   int x = s->x;
   int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
@@ -2275,10 +2284,9 @@ x_draw_image_foreground (s)
 /* Draw a relief around the image glyph string S.  */
 
 static void
-x_draw_image_relief (s)
-     struct glyph_string *s;
+x_draw_image_relief (struct glyph_string *s)
 {
-  int x0, y0, x1, y1, thick, raised_p;
+  int x0, y0, x1, y1, thick, raised_p, extra;
   XRectangle r;
   int x = s->x;
   int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
@@ -2309,10 +2317,13 @@ x_draw_image_relief (s)
       raised_p = s->img->relief > 0;
     }
 
-  x0 = x - thick;
-  y0 = y - thick;
-  x1 = x + s->slice.width + thick - 1;
-  y1 = y + s->slice.height + thick - 1;
+  extra = s->face->id == TOOL_BAR_FACE_ID
+    ? XINT (Vtool_bar_button_margin) : 0;
+
+  x0 = x - thick - extra;
+  y0 = y - thick - extra;
+  x1 = x + s->slice.width + thick - 1 + extra;
+  y1 = y + s->slice.height + thick - 1 + extra;
 
   x_setup_relief_colors (s);
   get_glyph_string_clip_rect (s, &r);
@@ -2328,9 +2339,7 @@ x_draw_image_relief (s)
 /* Draw the foreground of image glyph string S to PIXMAP.  */
 
 static void
-x_draw_image_foreground_1 (s, pixmap)
-     struct glyph_string *s;
-     Pixmap pixmap;
+x_draw_image_foreground_1 (struct glyph_string *s, Pixmap pixmap)
 {
   int x = 0;
   int y = s->ybase - s->y - image_ascent (s->img, s->face, &s->slice);
@@ -2406,9 +2415,7 @@ x_draw_image_foreground_1 (s, pixmap)
    give the rectangle to draw.  */
 
 static void
-x_draw_glyph_string_bg_rect (s, x, y, w, h)
-     struct glyph_string *s;
-     int x, y, w, h;
+x_draw_glyph_string_bg_rect (struct glyph_string *s, int x, int y, int w, int h)
 {
   if (s->stippled_p)
     {
@@ -2437,8 +2444,7 @@ x_draw_glyph_string_bg_rect (s, x, y, w, h)
  */
 
 static void
-x_draw_image_glyph_string (s)
-     struct glyph_string *s;
+x_draw_image_glyph_string (struct glyph_string *s)
 {
   int box_line_hwidth = eabs (s->face->box_line_width);
   int box_line_vwidth = max (s->face->box_line_width, 0);
@@ -2542,25 +2548,41 @@ x_draw_image_glyph_string (s)
 /* Draw stretch glyph string S.  */
 
 static void
-x_draw_stretch_glyph_string (s)
-     struct glyph_string *s;
+x_draw_stretch_glyph_string (struct glyph_string *s)
 {
   xassert (s->first_glyph->type == STRETCH_GLYPH);
 
   if (s->hl == DRAW_CURSOR
       && !x_stretch_cursor_p)
     {
-      /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
-        as wide as the stretch glyph.  */
+      /* If `x-stretch-cursor' is nil, don't draw a block cursor as
+        wide as the stretch glyph.  */
       int width, background_width = s->background_width;
-      int x = s->x, left_x = window_box_left_offset (s->w, TEXT_AREA);
+      int x = s->x;
 
-      if (x < left_x)
+      if (!s->row->reversed_p)
        {
-         background_width -= left_x - x;
-         x = left_x;
+         int left_x = window_box_left_offset (s->w, TEXT_AREA);
+
+         if (x < left_x)
+           {
+             background_width -= left_x - x;
+             x = left_x;
+           }
+       }
+      else
+       {
+         /* In R2L rows, draw the cursor on the right edge of the
+            stretch glyph.  */
+         int right_x = window_box_right_offset (s->w, TEXT_AREA);
+
+         if (x + background_width > right_x)
+           background_width -= x - right_x;
+         x += background_width;
        }
       width = min (FRAME_COLUMN_WIDTH (s->f), background_width);
+      if (s->row->reversed_p)
+       x -= width;
 
       /* Draw cursor.  */
       x_draw_glyph_string_bg_rect (s, x, s->y, width, s->height);
@@ -2573,7 +2595,10 @@ x_draw_stretch_glyph_string (s)
          XRectangle r;
          GC gc;
 
-         x += width;
+         if (!s->row->reversed_p)
+           x += width;
+         else
+           x = s->x;
          if (s->row->mouse_face_p
              && cursor_in_mouse_face_p (s->w))
            {
@@ -2626,8 +2651,7 @@ x_draw_stretch_glyph_string (s)
 /* Draw glyph string S.  */
 
 static void
-x_draw_glyph_string (s)
-     struct glyph_string *s;
+x_draw_glyph_string (struct glyph_string *s)
 {
   int relief_drawn_p = 0;
 
@@ -2709,6 +2733,14 @@ x_draw_glyph_string (s)
       x_draw_composite_glyph_string_foreground (s);
       break;
 
+    case GLYPHLESS_GLYPH:
+      if (s->for_overlaps)
+       s->background_filled_p = 1;
+      else
+       x_draw_glyph_string_background (s, 1);
+      x_draw_glyphless_glyph_string_foreground (s);
+      break;
+
     default:
       abort ();
     }
@@ -2881,9 +2913,7 @@ x_draw_glyph_string (s)
 /* Shift display to make room for inserted glyphs.   */
 
 void
-x_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
-     struct frame *f;
-     int x, y, width, height, shift_by;
+x_shift_glyphs_for_insert (struct frame *f, int x, int y, int width, int height, int shift_by)
 {
   XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), FRAME_X_WINDOW (f),
             f->output_data.x->normal_gc,
@@ -2895,9 +2925,7 @@ x_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
    for X frames.  */
 
 static void
-x_delete_glyphs (f, n)
-     struct frame *f;
-     register int n;
+x_delete_glyphs (struct frame *f, register int n)
 {
   abort ();
 }
@@ -2907,12 +2935,7 @@ x_delete_glyphs (f, n)
    If they are <= 0, this is probably an error.  */
 
 void
-x_clear_area (dpy, window, x, y, width, height, exposures)
-     Display *dpy;
-     Window window;
-     int x, y;
-     int width, height;
-     int exposures;
+x_clear_area (Display *dpy, Window window, int x, int y, int width, int height, int exposures)
 {
   xassert (width > 0 && height > 0);
   XClearArea (dpy, window, x, y, width, height, exposures);
@@ -2942,9 +2965,10 @@ x_clear_frame (struct frame *f)
 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
   /* Make sure scroll bars are redrawn.  As they aren't redrawn by
      redisplay, do it here.  */
-  gtk_widget_queue_draw (FRAME_GTK_WIDGET (f));
+  if (FRAME_GTK_WIDGET (f))
+    gtk_widget_queue_draw (FRAME_GTK_WIDGET (f));
 #endif
-  
+
   XFlush (FRAME_X_DISPLAY (f));
 
   UNBLOCK_INPUT;
@@ -2964,8 +2988,7 @@ x_clear_frame (struct frame *f)
    *RESULT.  Return 1 if the difference is negative, otherwise 0.  */
 
 static int
-timeval_subtract (result, x, y)
-     struct timeval *result, x, y;
+timeval_subtract (struct timeval *result, struct timeval x, struct timeval y)
 {
   /* Perform the carry for the later subtraction by updating y.  This
      is safer because on some systems the tv_sec member is unsigned.  */
@@ -2994,8 +3017,7 @@ timeval_subtract (result, x, y)
 }
 
 void
-XTflash (f)
-     struct frame *f;
+XTflash (struct frame *f)
 {
   BLOCK_INPUT;
 
@@ -3003,18 +3025,16 @@ XTflash (f)
 #ifdef USE_GTK
     /* Use Gdk routines to draw.  This way, we won't draw over scroll bars
        when the scroll bars and the edit widget share the same X window.  */
+    GdkWindow *window = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
     GdkGCValues vals;
     GdkGC *gc;
     vals.foreground.pixel = (FRAME_FOREGROUND_PIXEL (f)
                              ^ FRAME_BACKGROUND_PIXEL (f));
     vals.function = GDK_XOR;
-    gc = gdk_gc_new_with_values (FRAME_GTK_WIDGET (f)->window,
-                                 &vals,
-                                 GDK_GC_FUNCTION
-                                 | GDK_GC_FOREGROUND);
+    gc = gdk_gc_new_with_values (window,
+                                 &vals, GDK_GC_FUNCTION | GDK_GC_FOREGROUND);
 #define XFillRectangle(d, win, gc, x, y, w, h) \
-    gdk_draw_rectangle (FRAME_GTK_WIDGET (f)->window, \
-                        gc, TRUE, x, y, w, h)
+    gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
 #else
     GC gc;
 
@@ -3152,12 +3172,10 @@ XTflash (f)
 
 
 static void
-XTtoggle_invisible_pointer (f, invisible)
-     FRAME_PTR f;
-     int invisible;
+XTtoggle_invisible_pointer (FRAME_PTR f, int invisible)
 {
   BLOCK_INPUT;
-  if (invisible) 
+  if (invisible)
     {
       if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor != 0)
         XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -3174,10 +3192,8 @@ XTtoggle_invisible_pointer (f, invisible)
 /* Make audible bell.  */
 
 void
-XTring_bell ()
+XTring_bell (struct frame *f)
 {
-  struct frame *f = SELECTED_FRAME ();
-
   if (FRAME_X_DISPLAY (f))
     {
 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
@@ -3201,8 +3217,7 @@ XTring_bell ()
    that is bounded by calls to x_update_begin and x_update_end.  */
 
 static void
-XTset_terminal_window (n)
-     register int n;
+XTset_terminal_window (struct frame *f, int n)
 {
   /* This function intentionally left blank.  */
 }
@@ -3217,9 +3232,7 @@ XTset_terminal_window (n)
    lines or deleting -N lines at vertical position VPOS.  */
 
 static void
-x_ins_del_lines (f, vpos, n)
-     struct frame *f;
-     int vpos, n;
+x_ins_del_lines (struct frame *f, int vpos, int n)
 {
   abort ();
 }
@@ -3228,9 +3241,7 @@ x_ins_del_lines (f, vpos, n)
 /* Scroll part of the display as described by RUN.  */
 
 static void
-x_scroll_run (w, run)
-     struct window *w;
-     struct run *run;
+x_scroll_run (struct window *w, struct run *run)
 {
   struct frame *f = XFRAME (w->frame);
   int x, y, width, height, from_y, to_y, bottom_y;
@@ -3287,8 +3298,7 @@ x_scroll_run (w, run)
 
 \f
 static void
-frame_highlight (f)
-     struct frame *f;
+frame_highlight (struct frame *f)
 {
   /* We used to only do this if Vx_no_window_manager was non-nil, but
      the ICCCM (section 4.1.6) says that the window's border pixmap
@@ -3303,8 +3313,7 @@ frame_highlight (f)
 }
 
 static void
-frame_unhighlight (f)
-     struct frame *f;
+frame_unhighlight (struct frame *f)
 {
   /* We used to only do this if Vx_no_window_manager was non-nil, but
      the ICCCM (section 4.1.6) says that the window's border pixmap
@@ -3325,9 +3334,7 @@ frame_unhighlight (f)
    Lisp code can tell when the switch took place by examining the events.  */
 
 static void
-x_new_focus_frame (dpyinfo, frame)
-     struct x_display_info *dpyinfo;
-     struct frame *frame;
+x_new_focus_frame (struct x_display_info *dpyinfo, struct frame *frame)
 {
   struct frame *old_focus = dpyinfo->x_focus_frame;
 
@@ -3354,12 +3361,7 @@ x_new_focus_frame (dpyinfo, frame)
    a FOCUS_IN_EVENT into *BUFP.  */
 
 static void
-x_focus_changed (type, state, dpyinfo, frame, bufp)
-     int type;
-     int state;
-     struct x_display_info *dpyinfo;
-     struct frame *frame;
-     struct input_event *bufp;
+x_focus_changed (int type, int state, struct x_display_info *dpyinfo, struct frame *frame, struct input_event *bufp)
 {
   if (type == FocusIn)
     {
@@ -3411,10 +3413,7 @@ x_focus_changed (type, state, dpyinfo, frame, bufp)
    Returns FOCUS_IN_EVENT event in *BUFP. */
 
 static void
-x_detect_focus_change (dpyinfo, event, bufp)
-     struct x_display_info *dpyinfo;
-     XEvent *event;
-     struct input_event *bufp;
+x_detect_focus_change (struct x_display_info *dpyinfo, XEvent *event, struct input_event *bufp)
 {
   struct frame *frame;
 
@@ -3463,8 +3462,7 @@ x_detect_focus_change (dpyinfo, event, bufp)
 /* Handle an event saying the mouse has moved out of an Emacs frame.  */
 
 void
-x_mouse_leave (dpyinfo)
-     struct x_display_info *dpyinfo;
+x_mouse_leave (struct x_display_info *dpyinfo)
 {
   x_new_focus_frame (dpyinfo, dpyinfo->x_focus_event_frame);
 }
@@ -3478,15 +3476,13 @@ x_mouse_leave (dpyinfo)
    the appropriate X display info.  */
 
 static void
-XTframe_rehighlight (frame)
-     struct frame *frame;
+XTframe_rehighlight (struct frame *frame)
 {
   x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame));
 }
 
 static void
-x_frame_rehighlight (dpyinfo)
-     struct x_display_info *dpyinfo;
+x_frame_rehighlight (struct x_display_info *dpyinfo)
 {
   struct frame *old_highlight = dpyinfo->x_highlight_frame;
 
@@ -3520,8 +3516,7 @@ x_frame_rehighlight (dpyinfo)
 
 /* Initialize mode_switch_bit and modifier_meaning.  */
 static void
-x_find_modifier_meanings (dpyinfo)
-     struct x_display_info *dpyinfo;
+x_find_modifier_meanings (struct x_display_info *dpyinfo)
 {
   int min_code, max_code;
   KeySym *syms;
@@ -3632,9 +3627,7 @@ x_find_modifier_meanings (dpyinfo)
    Emacs uses.  */
 
 unsigned int
-x_x_to_emacs_modifiers (dpyinfo, state)
-     struct x_display_info *dpyinfo;
-     unsigned int state;
+x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, unsigned int state)
 {
   EMACS_UINT mod_meta = meta_modifier;
   EMACS_UINT mod_alt  = alt_modifier;
@@ -3661,9 +3654,7 @@ x_x_to_emacs_modifiers (dpyinfo, state)
 }
 
 static unsigned int
-x_emacs_to_x_modifiers (dpyinfo, state)
-     struct x_display_info *dpyinfo;
-     unsigned int state;
+x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, unsigned int state)
 {
   EMACS_UINT mod_meta = meta_modifier;
   EMACS_UINT mod_alt  = alt_modifier;
@@ -3693,8 +3684,7 @@ x_emacs_to_x_modifiers (dpyinfo, state)
 /* Convert a keysym to its name.  */
 
 char *
-x_get_keysym_name (keysym)
-     KeySym keysym;
+x_get_keysym_name (int keysym)
 {
   char *value;
 
@@ -3715,10 +3705,7 @@ x_get_keysym_name (keysym)
    the mouse.  */
 
 static Lisp_Object
-construct_mouse_click (result, event, f)
-     struct input_event *result;
-     XButtonEvent *event;
-     struct frame *f;
+construct_mouse_click (struct input_event *result, XButtonEvent *event, struct frame *f)
 {
   /* Make the event type NO_EVENT; we'll change that when we decide
      otherwise.  */
@@ -3751,9 +3738,7 @@ static XMotionEvent last_mouse_motion_event;
 static Lisp_Object last_mouse_motion_frame;
 
 static int
-note_mouse_movement (frame, event)
-     FRAME_PTR frame;
-     XMotionEvent *event;
+note_mouse_movement (FRAME_PTR frame, XMotionEvent *event)
 {
   last_mouse_movement_time = event->time;
   last_mouse_motion_event = *event;
@@ -3797,7 +3782,7 @@ note_mouse_movement (frame, event)
  ************************************************************************/
 
 static void
-redo_mouse_highlight ()
+redo_mouse_highlight (void)
 {
   if (!NILP (last_mouse_motion_frame)
       && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame)))
@@ -3829,13 +3814,7 @@ redo_mouse_highlight ()
    movement.  */
 
 static void
-XTmouse_position (fp, insist, bar_window, part, x, y, time)
-     FRAME_PTR *fp;
-     int insist;
-     Lisp_Object *bar_window;
-     enum scroll_bar_part *part;
-     Lisp_Object *x, *y;
-     unsigned long *time;
+XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, long unsigned int *time)
 {
   FRAME_PTR f1;
 
@@ -4037,9 +4016,7 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
    bits.  */
 
 static struct scroll_bar *
-x_window_to_scroll_bar (display, window_id)
-     Display *display;
-     Window window_id;
+x_window_to_scroll_bar (Display *display, Window window_id)
 {
   Lisp_Object tail;
 
@@ -4084,8 +4061,7 @@ x_window_to_scroll_bar (display, window_id)
    if WINDOW is not part of a menu bar.  */
 
 static Widget
-x_window_to_menu_bar (window)
-     Window window;
+x_window_to_menu_bar (Window window)
 {
   Lisp_Object tail;
 
@@ -4113,12 +4089,12 @@ x_window_to_menu_bar (window)
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
 
-static void x_scroll_bar_to_input_event P_ ((XEvent *, struct input_event *));
-static void x_send_scroll_bar_event P_ ((Lisp_Object, int, int, int));
-static void x_create_toolkit_scroll_bar P_ ((struct frame *,
-                                            struct scroll_bar *));
-static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *,
-                                               int, int, int));
+static void x_scroll_bar_to_input_event (XEvent *, struct input_event *);
+static void x_send_scroll_bar_event (Lisp_Object, int, int, int);
+static void x_create_toolkit_scroll_bar (struct frame *,
+                                         struct scroll_bar *);
+static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar *,
+                                            int, int, int);
 
 
 /* Lisp window being scrolled.  Set when starting to interact with
@@ -4152,17 +4128,11 @@ static Boolean xaw3d_pick_top;
    a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so.  */
 
 static void
-xt_action_hook (widget, client_data, action_name, event, params,
-               num_params)
-     Widget widget;
-     XtPointer client_data;
-     String action_name;
-     XEvent *event;
-     String *params;
-     Cardinal *num_params;
+xt_action_hook (Widget widget, XtPointer client_data, String action_name,
+               XEvent *event, String *params, Cardinal *num_params)
 {
   int scroll_bar_p;
-  char *end_action;
+  const char *end_action;
 
 #ifdef USE_MOTIF
   scroll_bar_p = XmIsScrollBar (widget);
@@ -4210,9 +4180,7 @@ static int scroll_bar_windows_size;
    amount to scroll of a whole of WHOLE.  */
 
 static void
-x_send_scroll_bar_event (window, part, portion, whole)
-     Lisp_Object window;
-     int part, portion, whole;
+x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole)
 {
   XEvent event;
   XClientMessageEvent *ev = (XClientMessageEvent *) &event;
@@ -4245,7 +4213,7 @@ x_send_scroll_bar_event (window, part, portion, whole)
 
       scroll_bar_windows = (struct window **) xrealloc (scroll_bar_windows,
                                                        nbytes);
-      bzero (&scroll_bar_windows[i], nbytes - old_nbytes);
+      memset (&scroll_bar_windows[i], 0, nbytes - old_nbytes);
       scroll_bar_windows_size = new_size;
     }
 
@@ -4274,9 +4242,7 @@ x_send_scroll_bar_event (window, part, portion, whole)
    in *IEVENT.  */
 
 static void
-x_scroll_bar_to_input_event (event, ievent)
-     XEvent *event;
-     struct input_event *ievent;
+x_scroll_bar_to_input_event (XEvent *event, struct input_event *ievent)
 {
   XClientMessageEvent *ev = (XClientMessageEvent *) event;
   Lisp_Object window;
@@ -4317,9 +4283,7 @@ x_scroll_bar_to_input_event (event, ievent)
    CALL_DATA is a pointer to a XmScrollBarCallbackStruct.  */
 
 static void
-xm_scroll_callback (widget, client_data, call_data)
-     Widget widget;
-     XtPointer client_data, call_data;
+xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
 {
   struct scroll_bar *bar = (struct scroll_bar *) client_data;
   XmScrollBarCallbackStruct *cs = (XmScrollBarCallbackStruct *) call_data;
@@ -4414,7 +4378,8 @@ xg_scroll_callback (GtkRange     *range,
           && FRAME_X_DISPLAY_INFO (f)->grabbed < (1 << 4))
         {
           part = scroll_bar_handle;
-          whole = adj->upper - adj->page_size;
+          whole = gtk_adjustment_get_upper (adj) -
+            gtk_adjustment_get_page_size (adj);
           portion = min ((int)position, whole);
           bar->dragging = make_number ((int)portion);
         }
@@ -4475,9 +4440,7 @@ xg_end_scroll_callback (GtkWidget *widget,
    the thumb is.  */
 
 static void
-xaw_jump_callback (widget, client_data, call_data)
-     Widget widget;
-     XtPointer client_data, call_data;
+xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
 {
   struct scroll_bar *bar = (struct scroll_bar *) client_data;
   float top = *(float *) call_data;
@@ -4519,9 +4482,7 @@ xaw_jump_callback (widget, client_data, call_data)
    Values < height of scroll bar mean line-wise movement.  */
 
 static void
-xaw_scroll_callback (widget, client_data, call_data)
-     Widget widget;
-     XtPointer client_data, call_data;
+xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
 {
   struct scroll_bar *bar = (struct scroll_bar *) client_data;
   /* The position really is stored cast to a pointer.  */
@@ -4559,11 +4520,9 @@ xaw_scroll_callback (widget, client_data, call_data)
 
 #ifdef USE_GTK
 static void
-x_create_toolkit_scroll_bar (f, bar)
-     struct frame *f;
-     struct scroll_bar *bar;
+x_create_toolkit_scroll_bar (struct frame *f, struct scroll_bar *bar)
 {
-  char *scroll_bar_name = SCROLL_BAR_NAME;
+  const char *scroll_bar_name = SCROLL_BAR_NAME;
 
   BLOCK_INPUT;
   xg_create_scroll_bar (f, bar, G_CALLBACK (xg_scroll_callback),
@@ -4575,9 +4534,7 @@ x_create_toolkit_scroll_bar (f, bar)
 #else /* not USE_GTK */
 
 static void
-x_create_toolkit_scroll_bar (f, bar)
-     struct frame *f;
-     struct scroll_bar *bar;
+x_create_toolkit_scroll_bar (struct frame *f, struct scroll_bar *bar)
 {
   Window xwindow;
   Widget widget;
@@ -4670,7 +4627,7 @@ x_create_toolkit_scroll_bar (f, bar)
   if (f->output_data.x->scroll_bar_top_shadow_pixel == -1)
     {
       pixel = f->output_data.x->scroll_bar_background_pixel;
-      if (pixel != -1) 
+      if (pixel != -1)
         {
           if (!x_alloc_lighter_color (f, FRAME_X_DISPLAY (f),
                                       FRAME_X_COLORMAP (f),
@@ -4682,7 +4639,7 @@ x_create_toolkit_scroll_bar (f, bar)
   if (f->output_data.x->scroll_bar_bottom_shadow_pixel == -1)
     {
       pixel = f->output_data.x->scroll_bar_background_pixel;
-      if (pixel != -1) 
+      if (pixel != -1)
         {
           if (!x_alloc_lighter_color (f, FRAME_X_DISPLAY (f),
                                       FRAME_X_COLORMAP (f),
@@ -4698,8 +4655,11 @@ x_create_toolkit_scroll_bar (f, bar)
       || f->output_data.x->scroll_bar_bottom_shadow_pixel == -1)
     /* We tried to allocate a color for the top/bottom shadow, and
        failed, so tell Xaw3d to use dithering instead.   */
+    /* But only if we have a small colormap.  Xaw3d can allocate nice
+       colors itself.  */
     {
-      XtSetArg (av[ac], XtNbeNiceToColormap, True);
+      XtSetArg (av[ac], XtNbeNiceToColormap,
+                DefaultDepthOfScreen (FRAME_X_SCREEN (f)) < 16);
       ++ac;
     }
   else
@@ -4777,18 +4737,15 @@ x_create_toolkit_scroll_bar (f, bar)
 
 #ifdef USE_GTK
 static void
-x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
-     struct scroll_bar *bar;
-     int portion, position, whole;
+x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int position, int whole)
 {
   xg_set_toolkit_scroll_bar_thumb (bar, portion, position, whole);
 }
 
 #else /* not USE_GTK */
 static void
-x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
-     struct scroll_bar *bar;
-     int portion, position, whole;
+x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int position,
+                               int whole)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   Widget widget = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar);
@@ -4903,9 +4860,7 @@ x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
    scroll bar. */
 
 static struct scroll_bar *
-x_scroll_bar_create (w, top, left, width, height)
-     struct window *w;
-     int top, left, width, height;
+x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
 {
   struct frame *f = XFRAME (w->frame);
   struct scroll_bar *bar
@@ -4984,7 +4939,6 @@ x_scroll_bar_create (w, top, left, width, height)
                              left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
                              width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
                              max (height, 1));
-    xg_show_scroll_bar (bar->x_window);
 #else /* not USE_GTK */
     Widget scroll_bar = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar);
     XtConfigureWidget (scroll_bar,
@@ -5020,10 +4974,7 @@ x_scroll_bar_create (w, top, left, width, height)
    to move to the very end of the buffer.  */
 
 static void
-x_scroll_bar_set_handle (bar, start, end, rebuild)
-     struct scroll_bar *bar;
-     int start, end;
-     int rebuild;
+x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild)
 {
   int dragging = ! NILP (bar->dragging);
   Window w = bar->x_window;
@@ -5121,8 +5072,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild)
    nil.  */
 
 static void
-x_scroll_bar_remove (bar)
-     struct scroll_bar *bar;
+x_scroll_bar_remove (struct scroll_bar *bar)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   BLOCK_INPUT;
@@ -5150,9 +5100,7 @@ x_scroll_bar_remove (bar)
    create one.  */
 
 static void
-XTset_vertical_scroll_bar (w, portion, whole, position)
-     struct window *w;
-     int portion, whole, position;
+XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int position)
 {
   struct frame *f = XFRAME (w->frame);
   struct scroll_bar *bar;
@@ -5369,8 +5317,7 @@ XTset_vertical_scroll_bar (w, portion, whole, position)
    `*redeem_scroll_bar_hook' is applied to its window before the judgment.  */
 
 static void
-XTcondemn_scroll_bars (frame)
-     FRAME_PTR frame;
+XTcondemn_scroll_bars (FRAME_PTR frame)
 {
   /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS.  */
   while (! NILP (FRAME_SCROLL_BARS (frame)))
@@ -5391,8 +5338,7 @@ XTcondemn_scroll_bars (frame)
    Note that WINDOW isn't necessarily condemned at all.  */
 
 static void
-XTredeem_scroll_bar (window)
-     struct window *window;
+XTredeem_scroll_bar (struct window *window)
 {
   struct scroll_bar *bar;
   struct frame *f;
@@ -5437,8 +5383,7 @@ XTredeem_scroll_bar (window)
    last call to `*condemn_scroll_bars_hook'.  */
 
 static void
-XTjudge_scroll_bars (f)
-     FRAME_PTR f;
+XTjudge_scroll_bars (FRAME_PTR f)
 {
   Lisp_Object bar, next;
 
@@ -5471,9 +5416,7 @@ XTjudge_scroll_bars (f)
    mark bits.  */
 
 static void
-x_scroll_bar_expose (bar, event)
-     struct scroll_bar *bar;
-     XEvent *event;
+x_scroll_bar_expose (struct scroll_bar *bar, XEvent *event)
 {
   Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
@@ -5515,10 +5458,7 @@ x_scroll_bar_expose (bar, event)
 
 
 static void
-x_scroll_bar_handle_click (bar, event, emacs_event)
-     struct scroll_bar *bar;
-     XEvent *event;
-     struct input_event *emacs_event;
+x_scroll_bar_handle_click (struct scroll_bar *bar, XEvent *event, struct input_event *emacs_event)
 {
   if (! WINDOWP (bar->window))
     abort ();
@@ -5576,9 +5516,7 @@ x_scroll_bar_handle_click (bar, event, emacs_event)
    mark bits.  */
 
 static void
-x_scroll_bar_note_movement (bar, event)
-     struct scroll_bar *bar;
-     XEvent *event;
+x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
 {
   FRAME_PTR f = XFRAME (XWINDOW (bar->window)->frame);
 
@@ -5608,12 +5546,7 @@ x_scroll_bar_note_movement (bar, event)
    on the scroll bar.  */
 
 static void
-x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
-     FRAME_PTR *fp;
-     Lisp_Object *bar_window;
-     enum scroll_bar_part *part;
-     Lisp_Object *x, *y;
-     unsigned long *time;
+x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, long unsigned int *time)
 {
   struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
   Window w = bar->x_window;
@@ -5685,8 +5618,7 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
    redraw them.  */
 
 void
-x_scroll_bar_clear (f)
-     FRAME_PTR f;
+x_scroll_bar_clear (FRAME_PTR f)
 {
 #ifndef USE_TOOLKIT_SCROLL_BARS
   Lisp_Object bar;
@@ -5739,22 +5671,18 @@ struct x_display_info *XTread_socket_fake_io_error;
 
 static struct x_display_info *next_noop_dpyinfo;
 
-#define SET_SAVED_MENU_EVENT(size)                                     \
+#define SET_SAVED_BUTTON_EVENT                                          \
      do                                                                        \
        {                                                               \
         if (f->output_data.x->saved_menu_event == 0)                   \
            f->output_data.x->saved_menu_event                          \
             = (XEvent *) xmalloc (sizeof (XEvent));                    \
-         bcopy (&event, f->output_data.x->saved_menu_event, size);     \
+         *f->output_data.x->saved_menu_event = event;                   \
         inev.ie.kind = MENU_BAR_ACTIVATE_EVENT;                        \
         XSETFRAME (inev.ie.frame_or_window, f);                        \
        }                                                               \
      while (0)
 
-#define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
-#define SET_SAVED_KEY_EVENT    SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
-
-
 enum
 {
   X_EVENT_NORMAL,
@@ -5772,9 +5700,7 @@ enum
 
 #ifdef HAVE_X_I18N
 static int
-x_filter_event (dpyinfo, event)
-     struct x_display_info *dpyinfo;
-     XEvent *event;
+x_filter_event (struct x_display_info *dpyinfo, XEvent *event)
 {
   /* XFilterEvent returns non-zero if the input method has
    consumed the event.  We pass the frame's X window to
@@ -5797,10 +5723,7 @@ static struct input_event *current_hold_quit;
    It is invoked before the XEvent is translated to a GdkEvent,
    so we have a chance to act on the event before GTK. */
 static GdkFilterReturn
-event_handler_gdk (gxev, ev, data)
-     GdkXEvent *gxev;
-     GdkEvent *ev;
-     gpointer data;
+event_handler_gdk (GdkXEvent *gxev, GdkEvent *ev, gpointer data)
 {
   XEvent *xev = (XEvent *) gxev;
 
@@ -5853,11 +5776,7 @@ event_handler_gdk (gxev, ev, data)
    We return the number of characters stored into the buffer. */
 
 static int
-handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
-     struct x_display_info *dpyinfo;
-     XEvent *eventp;
-     int *finish;
-     struct input_event *hold_quit;
+handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventp, int *finish, struct input_event *hold_quit)
 {
   union {
     struct input_event ie;
@@ -5869,16 +5788,17 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
   struct frame *f = NULL;
   struct coding_system coding;
   XEvent event = *eventp;
+  Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
 
   *finish = X_EVENT_NORMAL;
 
   EVENT_INIT (inev.ie);
   inev.ie.kind = NO_EVENT;
   inev.ie.arg = Qnil;
-  
+
   if (pending_event_wait.eventtype == event.type)
     pending_event_wait.eventtype = 0; /* Indicates we got it.  */
-  
+
   switch (event.type)
     {
     case ClientMessage:
@@ -6318,12 +6238,12 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
 
       /* If mouse-highlight is an integer, input clears out
         mouse highlighting.  */
-      if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
+      if (!hlinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)
          && (f == 0
-             || !EQ (f->tool_bar_window, dpyinfo->mouse_face_window)))
+             || !EQ (f->tool_bar_window, hlinfo->mouse_face_window)))
         {
-          clear_mouse_face (dpyinfo);
-          dpyinfo->mouse_face_hidden = 1;
+          clear_mouse_face (hlinfo);
+          hlinfo->mouse_face_hidden = 1;
         }
 
 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
@@ -6391,7 +6311,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
              this enables ComposeCharacter to work whether or
              not it is combined with Meta.  */
           if (modifiers & dpyinfo->meta_mod_mask)
-            bzero (&compose_status, sizeof (compose_status));
+            memset (&compose_status, 0, sizeof (compose_status));
 
 #ifdef HAVE_X_I18N
           if (FRAME_XIC (f))
@@ -6439,7 +6359,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
           if (compose_status.chars_matched > 0 && nbytes == 0)
             break;
 
-          bzero (&compose_status, sizeof (compose_status));
+          memset (&compose_status, 0, sizeof (compose_status));
           orig_keysym = keysym;
 
          /* Common for all keysym input events.  */
@@ -6680,12 +6600,12 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
       f = x_top_window_to_frame (dpyinfo, event.xcrossing.window);
       if (f)
         {
-          if (f == dpyinfo->mouse_face_mouse_frame)
+          if (f == hlinfo->mouse_face_mouse_frame)
             {
               /* If we move outside the frame, then we're
                  certainly no longer on any text in the frame.  */
-              clear_mouse_face (dpyinfo);
-              dpyinfo->mouse_face_mouse_frame = 0;
+              clear_mouse_face (hlinfo);
+              hlinfo->mouse_face_mouse_frame = 0;
             }
 
           /* Generate a nil HELP_EVENT to cancel a help-echo.
@@ -6718,10 +6638,10 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
         else
           f = x_window_to_frame (dpyinfo, event.xmotion.window);
 
-        if (dpyinfo->mouse_face_hidden)
+        if (hlinfo->mouse_face_hidden)
           {
-            dpyinfo->mouse_face_hidden = 0;
-            clear_mouse_face (dpyinfo);
+            hlinfo->mouse_face_hidden = 0;
+            clear_mouse_face (hlinfo);
           }
 
 #ifdef USE_GTK
@@ -6776,7 +6696,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
 
             /* If we move outside the frame, then we're
                certainly no longer on any text in the frame.  */
-            clear_mouse_face (dpyinfo);
+            clear_mouse_face (hlinfo);
           }
 
         /* If the contents of the global variable help_echo_string
@@ -6798,7 +6718,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
                             event.xconfigure.height);
           f = 0;
         }
-#endif  
+#endif
       if (f)
         {
 #ifndef USE_X_TOOLKIT
@@ -6832,7 +6752,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
           /* GTK creates windows but doesn't map them.
              Only get real positions when mapped. */
           if (FRAME_GTK_OUTER_WIDGET (f)
-              && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f)))
+              && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f)))
 #endif
             {
              x_real_positions (f, &f->left_pos, &f->top_pos);
@@ -6853,7 +6773,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
            by the rest of Emacs, we put it here.  */
         int tool_bar_p = 0;
 
-        bzero (&compose_status, sizeof (compose_status));
+        memset (&compose_status, 0, sizeof (compose_status));
        last_mouse_glyph_frame = 0;
         last_user_time = event.xbutton.time;
 
@@ -6957,14 +6877,12 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
            Instead, save it away
            and we will pass it to Xt from kbd_buffer_get_event.
            That way, we can run some Lisp code first.  */
-        if (
+        if (! popup_activated ()
 #ifdef USE_GTK
-            ! popup_activated ()
             /* Gtk+ menus only react to the first three buttons. */
             && event.xbutton.button < 3
-            &&
 #endif
-            f && event.type == ButtonPress
+            && f && event.type == ButtonPress
             /* Verify the event is really within the menu bar
                and not just sent to it due to grabbing.  */
             && event.xbutton.x >= 0
@@ -6975,30 +6893,13 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
           {
             SET_SAVED_BUTTON_EVENT;
             XSETFRAME (last_mouse_press_frame, f);
-#ifdef USE_GTK
             *finish = X_EVENT_DROP;
-#endif
           }
         else if (event.type == ButtonPress)
           {
             last_mouse_press_frame = Qnil;
             goto OTHER;
           }
-
-#ifdef USE_MOTIF /* This should do not harm for Lucid,
-                   but I am trying to be cautious.  */
-        else if (event.type == ButtonRelease)
-          {
-            if (!NILP (last_mouse_press_frame))
-              {
-                f = XFRAME (last_mouse_press_frame);
-                if (f->output_data.x)
-                  SET_SAVED_BUTTON_EVENT;
-              }
-            else
-              goto OTHER;
-          }
-#endif /* USE_MOTIF */
         else
           goto OTHER;
 #endif /* USE_X_TOOLKIT || USE_GTK */
@@ -7084,9 +6985,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
 
    Returns the value handle_one_xevent sets in the finish argument.  */
 int
-x_dispatch_event (event, display)
-     XEvent *event;
-     Display *display;
+x_dispatch_event (XEvent *event, Display *display)
 {
   struct x_display_info *dpyinfo;
   int finish = X_EVENT_NORMAL;
@@ -7112,10 +7011,7 @@ x_dispatch_event (event, display)
    EXPECTED is nonzero if the caller knows input is available.  */
 
 static int
-XTread_socket (terminal, expected, hold_quit)
-     struct terminal *terminal;
-     int expected;
-     struct input_event *hold_quit;
+XTread_socket (struct terminal *terminal, int expected, struct input_event *hold_quit)
 {
   int count = 0;
   XEvent event;
@@ -7266,11 +7162,7 @@ XTread_socket (terminal, expected, hold_quit)
    mode lines must be clipped to the whole window.  */
 
 static void
-x_clip_to_row (w, row, area, gc)
-     struct window *w;
-     struct glyph_row *row;
-     int area;
-     GC gc;
+x_clip_to_row (struct window *w, struct glyph_row *row, int area, GC gc)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   XRectangle clip_rect;
@@ -7291,9 +7183,7 @@ x_clip_to_row (w, row, area, gc)
 /* Draw a hollow box cursor on window W in glyph row ROW.  */
 
 static void
-x_draw_hollow_cursor (w, row)
-     struct window *w;
-     struct glyph_row *row;
+x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
@@ -7338,11 +7228,7 @@ x_draw_hollow_cursor (w, row)
    --gerd.  */
 
 static void
-x_draw_bar_cursor (w, row, width, kind)
-     struct window *w;
-     struct glyph_row *row;
-     int width;
-     enum text_cursor_kinds kind;
+x_draw_bar_cursor (struct window *w, struct glyph_row *row, int width, enum text_cursor_kinds kind)
 {
   struct frame *f = XFRAME (w->frame);
   struct glyph *cursor_glyph;
@@ -7395,14 +7281,20 @@ x_draw_bar_cursor (w, row, width, kind)
 
       if (kind == BAR_CURSOR)
        {
+         int x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x);
+
          if (width < 0)
            width = FRAME_CURSOR_WIDTH (f);
          width = min (cursor_glyph->pixel_width, width);
 
          w->phys_cursor_width = width;
 
-         XFillRectangle (dpy, window, gc,
-                         WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x),
+         /* If the character under cursor is R2L, draw the bar cursor
+            on the right of its glyph, rather than on the left.  */
+         if ((cursor_glyph->resolved_level & 1) != 0)
+           x += cursor_glyph->pixel_width - width;
+
+         XFillRectangle (dpy, window, gc, x,
                          WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y),
                          width, row->height);
        }
@@ -7433,9 +7325,7 @@ x_draw_bar_cursor (w, row, width, kind)
 /* RIF: Define cursor CURSOR on frame F.  */
 
 static void
-x_define_frame_cursor (f, cursor)
-     struct frame *f;
-     Cursor cursor;
+x_define_frame_cursor (struct frame *f, Cursor cursor)
 {
   if (!f->pointer_invisible
       && f->output_data.x->current_cursor != cursor)
@@ -7447,9 +7337,7 @@ x_define_frame_cursor (f, cursor)
 /* RIF: Clear area on frame F.  */
 
 static void
-x_clear_frame_area (f, x, y, width, height)
-     struct frame *f;
-     int x, y, width, height;
+x_clear_frame_area (struct frame *f, int x, int y, int width, int height)
 {
   x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
                x, y, width, height, False);
@@ -7464,12 +7352,7 @@ x_clear_frame_area (f, x, y, width, height)
 /* RIF: Draw cursor on window W.  */
 
 static void
-x_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, active_p)
-     struct window *w;
-     struct glyph_row *glyph_row;
-     int x, y;
-     int cursor_type, cursor_width;
-     int on_p, active_p;
+x_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x, int y, int cursor_type, int cursor_width, int on_p, int active_p)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -7479,36 +7362,40 @@ x_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, activ
       w->phys_cursor_on_p = 1;
 
       if (glyph_row->exact_window_width_line_p
-         && w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA])
+         && (glyph_row->reversed_p
+             ? (w->phys_cursor.hpos < 0)
+             : (w->phys_cursor.hpos >= glyph_row->used[TEXT_AREA])))
        {
          glyph_row->cursor_in_fringe_p = 1;
-         draw_fringe_bitmap (w, glyph_row, 0);
+         draw_fringe_bitmap (w, glyph_row, glyph_row->reversed_p);
        }
       else
-      switch (cursor_type)
        {
-       case HOLLOW_BOX_CURSOR:
-         x_draw_hollow_cursor (w, glyph_row);
-         break;
+         switch (cursor_type)
+           {
+           case HOLLOW_BOX_CURSOR:
+             x_draw_hollow_cursor (w, glyph_row);
+             break;
 
-       case FILLED_BOX_CURSOR:
-         draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
-         break;
+           case FILLED_BOX_CURSOR:
+             draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
+             break;
 
-       case BAR_CURSOR:
-         x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
-         break;
+           case BAR_CURSOR:
+             x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
+             break;
 
-       case HBAR_CURSOR:
-         x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
-         break;
+           case HBAR_CURSOR:
+             x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
+             break;
 
-       case NO_CURSOR:
-         w->phys_cursor_width = 0;
-         break;
+           case NO_CURSOR:
+             w->phys_cursor_width = 0;
+             break;
 
-       default:
-         abort ();
+           default:
+             abort ();
+           }
        }
 
 #ifdef HAVE_X_I18N
@@ -7529,9 +7416,7 @@ x_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, activ
 /* Make the x-window of frame F use the gnu icon bitmap.  */
 
 int
-x_bitmap_icon (f, file)
-     struct frame *f;
-     Lisp_Object file;
+x_bitmap_icon (struct frame *f, Lisp_Object file)
 {
   int bitmap_id;
 
@@ -7608,9 +7493,7 @@ x_bitmap_icon (f, file)
    Use ICON_NAME as the text.  */
 
 int
-x_text_icon (f, icon_name)
-     struct frame *f;
-     char *icon_name;
+x_text_icon (struct frame *f, const char *icon_name)
 {
   if (FRAME_X_WINDOW (f) == 0)
     return 1;
@@ -7653,9 +7536,7 @@ static struct x_error_message_stack *x_error_message;
    x_catch_errors is in effect.  */
 
 static void
-x_error_catcher (display, error)
-     Display *display;
-     XErrorEvent *error;
+x_error_catcher (Display *display, XErrorEvent *error)
 {
   XGetErrorText (display, error->error_code,
                 x_error_message->string,
@@ -7675,11 +7556,10 @@ x_error_catcher (display, error)
 
    Calling x_uncatch_errors resumes the normal error handling.  */
 
-void x_check_errors ();
+void x_check_errors (Display *dpy, const char *format);
 
 void
-x_catch_errors (dpy)
-     Display *dpy;
+x_catch_errors (Display *dpy)
 {
   struct x_error_message_stack *data = xmalloc (sizeof (*data));
 
@@ -7696,7 +7576,7 @@ x_catch_errors (dpy)
    DPY should be the display that was passed to x_catch_errors.  */
 
 void
-x_uncatch_errors ()
+x_uncatch_errors (void)
 {
   struct x_error_message_stack *tmp;
 
@@ -7718,9 +7598,7 @@ x_uncatch_errors ()
    sprintf (a buffer, FORMAT, the x error message text) as the text.  */
 
 void
-x_check_errors (dpy, format)
-     Display *dpy;
-     char *format;
+x_check_errors (Display *dpy, const char *format)
 {
   /* Make sure to catch any errors incurred so far.  */
   XSync (dpy, False);
@@ -7728,7 +7606,7 @@ x_check_errors (dpy, format)
   if (x_error_message->string[0])
     {
       char string[X_ERROR_MESSAGE_SIZE];
-      bcopy (x_error_message->string, string, X_ERROR_MESSAGE_SIZE);
+      memcpy (string, x_error_message->string, X_ERROR_MESSAGE_SIZE);
       x_uncatch_errors ();
       error (format, string);
     }
@@ -7738,8 +7616,7 @@ x_check_errors (dpy, format)
    since we did x_catch_errors on DPY.  */
 
 int
-x_had_errors_p (dpy)
-     Display *dpy;
+x_had_errors_p (Display *dpy)
 {
   /* Make sure to catch any errors incurred so far.  */
   XSync (dpy, False);
@@ -7750,8 +7627,7 @@ x_had_errors_p (dpy)
 /* Forget about any errors we have had, since we did x_catch_errors on DPY.  */
 
 void
-x_clear_errors (dpy)
-     Display *dpy;
+x_clear_errors (Display *dpy)
 {
   x_error_message->string[0] = 0;
 }
@@ -7761,7 +7637,7 @@ x_clear_errors (dpy)
 /* Close off all unclosed x_catch_errors calls.  */
 
 void
-x_fully_uncatch_errors ()
+x_fully_uncatch_errors (void)
 {
   while (x_error_message)
     x_uncatch_errors ();
@@ -7771,14 +7647,14 @@ x_fully_uncatch_errors ()
 /* Nonzero if x_catch_errors has been done and not yet canceled.  */
 
 int
-x_catching_errors ()
+x_catching_errors (void)
 {
   return x_error_message != 0;
 }
 
 #if 0
 static unsigned int x_wire_count;
-x_trace_wire ()
+x_trace_wire (void)
 {
   fprintf (stderr, "Lib call: %d\n", ++x_wire_count);
 }
@@ -7792,8 +7668,8 @@ x_trace_wire ()
    which will do the appropriate cleanup for us.  */
 
 static SIGTYPE
-x_connection_signal (signalnum)        /* If we don't have an argument, */
-     int signalnum;            /* some compilers complain in signal calls.  */
+x_connection_signal (int signalnum)    /* If we don't have an argument, */
+                               /* some compilers complain in signal calls.  */
 {
 #ifdef USG
   /* USG systems forget handlers when they are used;
@@ -7816,7 +7692,7 @@ static char *error_msg;
    instead of dumping core when XtCloseDisplay fails.  */
 
 static void
-x_fatal_error_signal ()
+x_fatal_error_signal (void)
 {
   fprintf (stderr, "%s\n", error_msg);
   exit (70);
@@ -7826,9 +7702,7 @@ x_fatal_error_signal ()
    the text of an error message that lead to the connection loss.  */
 
 static SIGTYPE
-x_connection_closed (dpy, error_message)
-     Display *dpy;
-     char *error_message;
+x_connection_closed (Display *dpy, const char *error_message)
 {
   struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
   Lisp_Object frame, tail;
@@ -7901,7 +7775,6 @@ x_connection_closed (dpy, error_message)
         Closing the display is reported to lead to a bus error on
         OpenWindows in certain situations.  I suspect that is a bug
         in OpenWindows.  I don't know how to circumvent it here.  */
-      extern void (*fatal_error_signal_hook) P_ ((void));
       fatal_error_signal_hook = x_fatal_error_signal;
       XtCloseDisplay (dpy);
       fatal_error_signal_hook = NULL;
@@ -7942,8 +7815,8 @@ For details, see etc/PROBLEMS.\n",
   if (terminal_list == 0)
     {
       fprintf (stderr, "%s\n", error_msg);
-      shut_down_emacs (0, 0, Qnil);
-      exit (70);
+      Fkill_emacs (make_number (70));
+      /* NOTREACHED */
     }
 
   /* Ordinary stack unwind doesn't deal with these.  */
@@ -7963,15 +7836,13 @@ For details, see etc/PROBLEMS.\n",
 
 /* We specifically use it before defining it, so that gcc doesn't inline it,
    otherwise gdb doesn't know how to properly put a breakpoint on it.  */
-static void x_error_quitter P_ ((Display *, XErrorEvent *));
+static void x_error_quitter (Display *, XErrorEvent *);
 
 /* This is the first-level handler for X protocol errors.
    It calls x_error_quitter or x_error_catcher.  */
 
 static int
-x_error_handler (display, error)
-     Display *display;
-     XErrorEvent *error;
+x_error_handler (Display *display, XErrorEvent *error)
 {
   if (x_error_message)
     x_error_catcher (display, error);
@@ -7986,25 +7857,11 @@ x_error_handler (display, error)
 
 /* .gdbinit puts a breakpoint here, so make sure it is not inlined.  */
 
-#if __GNUC__ >= 3  /* On GCC 3.0 we might get a warning.  */
-#define NO_INLINE __attribute__((noinline))
-#else
-#define NO_INLINE
-#endif
-
-/* Some versions of GNU/Linux define noinline in their headers.  */
-
-#ifdef noinline
-#undef noinline
-#endif
-
 /* On older GCC versions, just putting x_error_quitter
    after x_error_handler prevents inlining into the former.  */
 
 static void NO_INLINE
-x_error_quitter (display, error)
-     Display *display;
-     XErrorEvent *error;
+x_error_quitter (Display *display, XErrorEvent *error)
 {
   char buf[256], buf1[356];
 
@@ -8029,8 +7886,7 @@ x_error_quitter (display, error)
    If that was the only one, it prints an error message and kills Emacs.  */
 
 static int
-x_io_error_quitter (display)
-     Display *display;
+x_io_error_quitter (Display *display)
 {
   char buf[256];
 
@@ -8047,10 +7903,7 @@ x_io_error_quitter (display)
    FONT-OBJECT.  */
 
 Lisp_Object
-x_new_font (f, font_object, fontset)
-     struct frame *f;
-     Lisp_Object font_object;
-     int fontset;
+x_new_font (struct frame *f, Lisp_Object font_object, int fontset)
 {
   struct font *font = XFONT_OBJECT (font_object);
 
@@ -8119,10 +7972,7 @@ x_new_font (f, font_object, fontset)
    pointer to the x_display_info structure corresponding to XIM.  */
 
 static void
-xim_destroy_callback (xim, client_data, call_data)
-     XIM xim;
-     XPointer client_data;
-     XPointer call_data;
+xim_destroy_callback (XIM xim, XPointer client_data, XPointer call_data)
 {
   struct x_display_info *dpyinfo = (struct x_display_info *) client_data;
   Lisp_Object frame, tail;
@@ -8150,16 +8000,14 @@ xim_destroy_callback (xim, client_data, call_data)
 
 #ifdef HAVE_X11R6
 /* This isn't prototyped in OSF 5.0 or 5.1a.  */
-extern char *XSetIMValues P_ ((XIM, ...));
+extern char *XSetIMValues (XIM, ...);
 #endif
 
 /* Open the connection to the XIM server on display DPYINFO.
    RESOURCE_NAME is the resource name Emacs uses.  */
 
 static void
-xim_open_dpy (dpyinfo, resource_name)
-     struct x_display_info *dpyinfo;
-     char *resource_name;
+xim_open_dpy (struct x_display_info *dpyinfo, char *resource_name)
 {
   XIM xim;
 
@@ -8169,7 +8017,7 @@ xim_open_dpy (dpyinfo, resource_name)
       if (dpyinfo->xim)
        XCloseIM (dpyinfo->xim);
       xim = XOpenIM (dpyinfo->display, dpyinfo->xrdb, resource_name,
-                    EMACS_CLASS);
+                    emacs_class);
       dpyinfo->xim = xim;
 
       if (xim)
@@ -8203,10 +8051,7 @@ xim_open_dpy (dpyinfo, resource_name)
    when the callback was registered.  */
 
 static void
-xim_instantiate_callback (display, client_data, call_data)
-     Display *display;
-     XPointer client_data;
-     XPointer call_data;
+xim_instantiate_callback (Display *display, XPointer client_data, XPointer call_data)
 {
   struct xim_inst_t *xim_inst = (struct xim_inst_t *) client_data;
   struct x_display_info *dpyinfo = xim_inst->dpyinfo;
@@ -8256,9 +8101,7 @@ xim_instantiate_callback (display, client_data, call_data)
    in the XIM instantiate callback function.  */
 
 static void
-xim_initialize (dpyinfo, resource_name)
-     struct x_display_info *dpyinfo;
-     char *resource_name;
+xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
 {
   dpyinfo->xim = NULL;
 #ifdef HAVE_XIM
@@ -8273,9 +8116,9 @@ xim_initialize (dpyinfo, resource_name)
       xim_inst->dpyinfo = dpyinfo;
       len = strlen (resource_name);
       xim_inst->resource_name = (char *) xmalloc (len + 1);
-      bcopy (resource_name, xim_inst->resource_name, len + 1);
+      memcpy (xim_inst->resource_name, resource_name, len + 1);
       XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb,
-                                     resource_name, EMACS_CLASS,
+                                     resource_name, emacs_class,
                                      xim_instantiate_callback,
                                      /* This is XPointer in XFree86
                                         but (XPointer *) on Tru64, at
@@ -8292,8 +8135,7 @@ xim_initialize (dpyinfo, resource_name)
 /* Close the connection to the XIM server on display DPYINFO. */
 
 static void
-xim_close_dpy (dpyinfo)
-     struct x_display_info *dpyinfo;
+xim_close_dpy (struct x_display_info *dpyinfo)
 {
 #ifdef HAVE_XIM
   if (use_xim)
@@ -8301,7 +8143,7 @@ xim_close_dpy (dpyinfo)
 #ifdef HAVE_X11R6_XIM
       if (dpyinfo->display)
        XUnregisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb,
-                                         NULL, EMACS_CLASS,
+                                         NULL, emacs_class,
                                          xim_instantiate_callback, NULL);
       xfree (dpyinfo->xim_callback_data->resource_name);
       xfree (dpyinfo->xim_callback_data);
@@ -8322,8 +8164,7 @@ xim_close_dpy (dpyinfo)
    from its current recorded position values and gravity.  */
 
 void
-x_calc_absolute_position (f)
-     struct frame *f;
+x_calc_absolute_position (struct frame *f)
 {
   int flags = f->size_hint_flags;
 
@@ -8375,10 +8216,7 @@ x_calc_absolute_position (f)
    which means, do adjust for borders but don't change the gravity.  */
 
 void
-x_set_offset (f, xoff, yoff, change_gravity)
-     struct frame *f;
-     register int xoff, yoff;
-     int change_gravity;
+x_set_offset (struct frame *f, register int xoff, register int yoff, int change_gravity)
 {
   int modified_top, modified_left;
 
@@ -8447,9 +8285,7 @@ x_set_offset (f, xoff, yoff, change_gravity)
    http://freedesktop.org/wiki/Specifications/wm-spec.  */
 
 static int
-wm_supports (f, atomname)
-     struct frame *f;
-     const char *atomname;
+wm_supports (struct frame *f, const char *atomname)
 {
   Atom actual_type;
   unsigned long actual_size, bytes_remaining;
@@ -8538,11 +8374,7 @@ wm_supports (f, atomname)
 }
 
 static void
-set_wm_state (frame, add, what, what2)
-     Lisp_Object frame;
-     int add;
-     const char *what;
-     const char *what2;
+set_wm_state (Lisp_Object frame, int add, const char *what, const char *what2)
 {
   const char *atom = "_NET_WM_STATE";
   Fx_send_client_event (frame, make_number (0), frame,
@@ -8560,9 +8392,7 @@ set_wm_state (frame, add, what, what2)
 }
 
 void
-x_set_sticky (f, new_value, old_value)
-     struct frame *f;
-     Lisp_Object new_value, old_value;
+x_set_sticky (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   Lisp_Object frame;
 
@@ -8640,8 +8470,7 @@ get_current_vm_state (struct frame *f,
 /* Do fullscreen as specified in extended window manager hints */
 
 static int
-do_ewmh_fullscreen (f)
-     struct frame *f;
+do_ewmh_fullscreen (struct frame *f)
 {
   int have_net_atom = wm_supports (f, "_NET_WM_STATE");
   Lisp_Object lval = get_frame_param (f, Qfullscreen);
@@ -8708,8 +8537,7 @@ do_ewmh_fullscreen (f)
 }
 
 static void
-XTfullscreen_hook (f)
-     FRAME_PTR f;
+XTfullscreen_hook (FRAME_PTR f)
 {
   if (f->async_visible)
     {
@@ -8722,9 +8550,7 @@ XTfullscreen_hook (f)
 
 
 static void
-x_handle_net_wm_state (f, event)
-     struct frame *f;
-     XPropertyEvent *event;
+x_handle_net_wm_state (struct frame *f, XPropertyEvent *event)
 {
   int value = FULLSCREEN_NONE;
   Lisp_Object lval;
@@ -8732,7 +8558,7 @@ x_handle_net_wm_state (f, event)
 
   get_current_vm_state (f, event->window, &value, &sticky);
   lval = Qnil;
-  switch (value) 
+  switch (value)
     {
     case FULLSCREEN_WIDTH:
       lval = Qfullwidth;
@@ -8747,7 +8573,7 @@ x_handle_net_wm_state (f, event)
       lval = Qmaximized;
       break;
     }
-      
+
   store_frame_param (f, Qfullscreen, lval);
   store_frame_param (f, Qsticky, sticky ? Qt : Qnil);
 }
@@ -8755,8 +8581,7 @@ x_handle_net_wm_state (f, event)
 /* Check if we need to resize the frame due to a fullscreen request.
    If so needed, resize the frame. */
 static void
-x_check_fullscreen (f)
-     struct frame *f;
+x_check_fullscreen (struct frame *f)
 {
   if (do_ewmh_fullscreen (f))
     return;
@@ -8783,7 +8608,7 @@ x_check_fullscreen (f)
         case FULLSCREEN_HEIGHT:
           height = x_display_pixel_height (dpyinfo);
         }
-      
+
       if (FRAME_COLS (f) != width || FRAME_LINES (f) != height)
         {
           change_frame_size (f, height, width, 0, 1, 0);
@@ -8802,10 +8627,7 @@ x_check_fullscreen (f)
    compensate by moving the window right and down by the proper amount.  */
 
 static void
-x_check_expected_move (f, expected_left, expected_top)
-     struct frame *f;
-     int expected_left;
-     int expected_top;
+x_check_expected_move (struct frame *f, int expected_left, int expected_top)
 {
   int current_left = 0, current_top = 0;
 
@@ -8850,9 +8672,7 @@ x_check_expected_move (f, expected_left, expected_top)
    of an exact comparison.  */
 
 static void
-x_sync_with_move (f, left, top, fuzzy)
-    struct frame *f;
-    int left, top, fuzzy;
+x_sync_with_move (struct frame *f, int left, int top, int fuzzy)
 {
   int count = 0;
 
@@ -8889,9 +8709,7 @@ x_sync_with_move (f, left, top, fuzzy)
 
 /* Wait for an event on frame F matching EVENTTYPE.  */
 void
-x_wait_for_event (f, eventtype)
-     struct frame *f;
-     int eventtype;
+x_wait_for_event (struct frame *f, int eventtype)
 {
   int level = interrupt_input_blocked;
 
@@ -8918,7 +8736,7 @@ x_wait_for_event (f, eventtype)
 
       FD_ZERO (&fds);
       FD_SET (fd, &fds);
-      
+
       EMACS_GET_TIME (time_now);
       EMACS_SUB_TIME (tmo, tmo_at, time_now);
 
@@ -8936,10 +8754,7 @@ x_wait_for_event (f, eventtype)
    size changes.  Otherwise we leave the window gravity unchanged.  */
 
 static void
-x_set_window_size_1 (f, change_gravity, cols, rows)
-     struct frame *f;
-     int change_gravity;
-     int cols, rows;
+x_set_window_size_1 (struct frame *f, int change_gravity, int cols, int rows)
 {
   int pixelwidth, pixelheight;
 
@@ -8947,13 +8762,12 @@ x_set_window_size_1 (f, change_gravity, cols, rows)
   f->scroll_bar_actual_width
     = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f)
        ? 0
-       : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
-       ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f)
-       : (FRAME_CONFIG_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)));
+       : FRAME_CONFIG_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f));
 
   compute_fringe_widths (f, 0);
 
-  pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols);
+  pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols)
+    + FRAME_TOOLBAR_WIDTH (f);
   pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows)
     + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f);
 
@@ -9004,17 +8818,14 @@ x_set_window_size_1 (f, change_gravity, cols, rows)
    Otherwise we leave the window gravity unchanged.  */
 
 void
-x_set_window_size (f, change_gravity, cols, rows)
-     struct frame *f;
-     int change_gravity;
-     int cols, rows;
+x_set_window_size (struct frame *f, int change_gravity, int cols, int rows)
 {
   BLOCK_INPUT;
 
   if (NILP (tip_frame) || XFRAME (tip_frame) != f)
     {
       int r, c;
-         
+
       /* When the frame is maximized/fullscreen or running under for
          example Xmonad, x_set_window_size_1 will be a no-op.
          In that case, the right thing to do is extend rows/cols to
@@ -9063,9 +8874,7 @@ x_set_window_size (f, change_gravity, cols, rows)
 /* Mouse warping.  */
 
 void
-x_set_mouse_position (f, x, y)
-     struct frame *f;
-     int x, y;
+x_set_mouse_position (struct frame *f, int x, int y)
 {
   int pix_x, pix_y;
 
@@ -9088,9 +8897,7 @@ x_set_mouse_position (f, x, y)
 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F.  */
 
 void
-x_set_mouse_pixel_position (f, pix_x, pix_y)
-     struct frame *f;
-     int pix_x, pix_y;
+x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
 {
   BLOCK_INPUT;
 
@@ -9102,8 +8909,7 @@ x_set_mouse_pixel_position (f, pix_x, pix_y)
 /* focus shifting, raising and lowering.  */
 
 void
-x_focus_on_frame (f)
-     struct frame *f;
+x_focus_on_frame (struct frame *f)
 {
 #if 0
   /* I don't think that the ICCCM allows programs to do things like this
@@ -9115,8 +8921,7 @@ x_focus_on_frame (f)
 }
 
 void
-x_unfocus_frame (f)
-     struct frame *f;
+x_unfocus_frame (struct frame *f)
 {
 #if 0
   /* Look at the remarks in x_focus_on_frame.  */
@@ -9129,8 +8934,7 @@ x_unfocus_frame (f)
 /* Raise frame F.  */
 
 void
-x_raise_frame (f)
-     struct frame *f;
+x_raise_frame (struct frame *f)
 {
   BLOCK_INPUT;
   if (f->async_visible)
@@ -9143,8 +8947,7 @@ x_raise_frame (f)
 /* Lower frame F.  */
 
 void
-x_lower_frame (f)
-     struct frame *f;
+x_lower_frame (struct frame *f)
 {
   if (f->async_visible)
     {
@@ -9158,8 +8961,7 @@ x_lower_frame (f)
 /* Activate frame with Extended Window Manager Hints */
 
 void
-x_ewmh_activate_frame (f)
-     FRAME_PTR f;
+x_ewmh_activate_frame (FRAME_PTR f)
 {
   /* See Window Manager Specification/Extended Window Manager Hints at
      http://freedesktop.org/wiki/Specifications/wm-spec  */
@@ -9179,9 +8981,7 @@ x_ewmh_activate_frame (f)
 }
 
 static void
-XTframe_raise_lower (f, raise_flag)
-     FRAME_PTR f;
-     int raise_flag;
+XTframe_raise_lower (FRAME_PTR f, int raise_flag)
 {
   if (raise_flag)
     x_raise_frame (f);
@@ -9192,9 +8992,7 @@ XTframe_raise_lower (f, raise_flag)
 /* XEmbed implementation.  */
 
 void
-xembed_set_info (f, flags)
-     struct frame *f;
-     enum xembed_info flags;
+xembed_set_info (struct frame *f, enum xembed_info flags)
 {
   Atom atom;
   unsigned long data[2];
@@ -9209,13 +9007,7 @@ xembed_set_info (f, flags)
 }
 
 void
-xembed_send_message (f, time, message, detail, data1, data2)
-     struct frame *f;
-     Time time;
-     enum xembed_message message;
-     long detail;
-     long data1;
-     long data2;
+xembed_send_message (struct frame *f, Time time, enum xembed_message message, long int detail, long int data1, long int data2)
 {
   XEvent event;
 
@@ -9244,8 +9036,7 @@ xembed_send_message (f, time, message, detail, data1, data2)
    finishes with it.  */
 
 void
-x_make_frame_visible (f)
-     struct frame *f;
+x_make_frame_visible (struct frame *f)
 {
   Lisp_Object type;
   int original_top, original_left;
@@ -9376,7 +9167,6 @@ x_make_frame_visible (f)
            /* It could be confusing if a real alarm arrives while
               processing the fake one.  Turn it off and let the
               handler reset it.  */
-           extern void poll_for_input_1 P_ ((void));
            int old_poll_suppress_count = poll_suppress_count;
            poll_suppress_count = 1;
            poll_for_input_1 ();
@@ -9408,8 +9198,7 @@ x_make_frame_visible (f)
 /* Make the frame visible (mapped and not iconified).  */
 
 void
-x_make_frame_invisible (f)
-     struct frame *f;
+x_make_frame_invisible (struct frame *f)
 {
   Window window;
 
@@ -9466,8 +9255,7 @@ x_make_frame_invisible (f)
 /* Change window state from mapped to iconified.  */
 
 void
-x_iconify_frame (f)
-     struct frame *f;
+x_iconify_frame (struct frame *f)
 {
   int result;
   Lisp_Object type;
@@ -9593,12 +9381,12 @@ x_iconify_frame (f)
 /* Free X resources of frame F.  */
 
 void
-x_free_frame_resources (f)
-     struct frame *f;
+x_free_frame_resources (struct frame *f)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Lisp_Object bar;
   struct scroll_bar *b;
+  Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
 
   BLOCK_INPUT;
 
@@ -9647,14 +9435,7 @@ x_free_frame_resources (f)
 #else  /* !USE_X_TOOLKIT */
 
 #ifdef USE_GTK
-      /* In the GTK version, tooltips are normal X
-         frames.  We must check and free both types. */
-      if (FRAME_GTK_OUTER_WIDGET (f))
-        {
-          gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f));
-          FRAME_X_WINDOW (f) = 0; /* Set to avoid XDestroyWindow below */
-          FRAME_GTK_OUTER_WIDGET (f) = 0;
-        }
+      xg_free_frame_widgets (f);
 #endif /* USE_GTK */
 
       if (FRAME_X_WINDOW (f))
@@ -9699,15 +9480,15 @@ x_free_frame_resources (f)
   if (f == dpyinfo->x_highlight_frame)
     dpyinfo->x_highlight_frame = 0;
 
-  if (f == dpyinfo->mouse_face_mouse_frame)
+  if (f == hlinfo->mouse_face_mouse_frame)
     {
-      dpyinfo->mouse_face_beg_row
-       = dpyinfo->mouse_face_beg_col = -1;
-      dpyinfo->mouse_face_end_row
-       = dpyinfo->mouse_face_end_col = -1;
-      dpyinfo->mouse_face_window = Qnil;
-      dpyinfo->mouse_face_deferred_gc = 0;
-      dpyinfo->mouse_face_mouse_frame = 0;
+      hlinfo->mouse_face_beg_row
+       = hlinfo->mouse_face_beg_col = -1;
+      hlinfo->mouse_face_end_row
+       = hlinfo->mouse_face_end_col = -1;
+      hlinfo->mouse_face_window = Qnil;
+      hlinfo->mouse_face_deferred_gc = 0;
+      hlinfo->mouse_face_mouse_frame = 0;
     }
 
   UNBLOCK_INPUT;
@@ -9717,8 +9498,7 @@ x_free_frame_resources (f)
 /* Destroy the X window of frame F.  */
 
 void
-x_destroy_window (f)
-     struct frame *f;
+x_destroy_window (struct frame *f)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
 
@@ -9742,10 +9522,7 @@ x_destroy_window (f)
 
 #ifndef USE_GTK
 void
-x_wm_set_size_hint (f, flags, user_position)
-     struct frame *f;
-     long flags;
-     int user_position;
+x_wm_set_size_hint (struct frame *f, long flags, int user_position)
 {
   XSizeHints size_hints;
   Window window = FRAME_OUTER_WINDOW (f);
@@ -9845,9 +9622,7 @@ x_wm_set_size_hint (f, flags, user_position)
 /* Used for IconicState or NormalState */
 
 void
-x_wm_set_window_state (f, state)
-     struct frame *f;
-     int state;
+x_wm_set_window_state (struct frame *f, int state)
 {
 #ifdef USE_X_TOOLKIT
   Arg al[1];
@@ -9865,9 +9640,7 @@ x_wm_set_window_state (f, state)
 }
 
 void
-x_wm_set_icon_pixmap (f, pixmap_id)
-     struct frame *f;
-     int pixmap_id;
+x_wm_set_icon_pixmap (struct frame *f, int pixmap_id)
 {
   Pixmap icon_pixmap, icon_mask;
 
@@ -9915,9 +9688,7 @@ x_wm_set_icon_pixmap (f, pixmap_id)
 }
 
 void
-x_wm_set_icon_position (f, icon_x, icon_y)
-     struct frame *f;
-     int icon_x, icon_y;
+x_wm_set_icon_position (struct frame *f, int icon_x, int icon_y)
 {
   Window window = FRAME_OUTER_WINDOW (f);
 
@@ -9939,9 +9710,7 @@ x_wm_set_icon_position (f, icon_x, icon_y)
    font table.  */
 
 static void
-x_check_font (f, font)
-     struct frame *f;
-     struct font *font;
+x_check_font (struct frame *f, struct font *font)
 {
   Lisp_Object frame;
 
@@ -9990,8 +9759,7 @@ static int x_session_initialized;
 /* Test whether two display-name strings agree up to the dot that separates
    the screen number from the server number.  */
 static int
-same_x_server (name1, name2)
-     const char *name1, *name2;
+same_x_server (const char *name1, const char *name2)
 {
   int seen_colon = 0;
   const unsigned char *system_name = SDATA (Vsystem_name);
@@ -10038,10 +9806,7 @@ same_x_server (name1, name2)
    get to the first bit.  With MASK 0x7e0, *BITS is set to 6, and *OFFSET
    to 5.  */
 static void
-get_bits_and_offset (mask, bits, offset)
-     unsigned long mask;
-     int *bits;
-     int *offset;
+get_bits_and_offset (long unsigned int mask, int *bits, int *offset)
 {
   int nr = 0;
   int off = 0;
@@ -10066,8 +9831,7 @@ get_bits_and_offset (mask, bits, offset)
    But don't permanently open it, just test its availability.  */
 
 int
-x_display_ok (display)
-    const char *display;
+x_display_ok (const char *display)
 {
     int dpy_ok = 1;
     Display *dpy;
@@ -10082,32 +9846,26 @@ x_display_ok (display)
 
 #ifdef USE_GTK
 static void
-my_log_handler (log_domain, log_level, message, user_data)
-     const gchar *log_domain;
-     GLogLevelFlags log_level;
-     const gchar *message;
-     gpointer user_data;
+my_log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
 {
   if (!strstr (message, "g_set_prgname"))
       fprintf (stderr, "%s-WARNING **: %s\n", log_domain, message);
 }
 #endif
-  
+
 /* Open a connection to X display DISPLAY_NAME, and return
    the structure that describes the open display.
    If we cannot contact the display, return null.  */
 
 struct x_display_info *
-x_term_init (display_name, xrm_option, resource_name)
-     Lisp_Object display_name;
-     char *xrm_option;
-     char *resource_name;
+x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 {
   int connection;
   Display *dpy;
   struct terminal *terminal;
   struct x_display_info *dpyinfo;
   XrmDatabase xrdb;
+  Mouse_HLInfo *hlinfo;
 
   BLOCK_INPUT;
 
@@ -10127,23 +9885,16 @@ x_term_init (display_name, xrm_option, resource_name)
     char *argv[NUM_ARGV];
     char **argv2 = argv;
     guint id;
-#ifndef HAVE_GTK_MULTIDISPLAY
-    if (!EQ (Vinitial_window_system, Qx))
-      error ("Sorry, you cannot connect to X servers with the GTK toolkit");
-#endif
 
     if (x_initialized++ > 1)
       {
-#ifdef HAVE_GTK_MULTIDISPLAY
-        /* Opening another display.  If xg_display_open returns less
-           than zero, we are probably on GTK 2.0, which can only handle
-           one display.  GTK 2.2 or later can handle more than one.  */
-        if (xg_display_open (SDATA (display_name), &dpy) < 0)
-#endif
-          error ("Sorry, this version of GTK can only handle one display");
+        xg_display_open (SDATA (display_name), &dpy);
       }
     else
       {
+        static char display_opt[] = "--display";
+        static char name_opt[] = "--name";
+        
         for (argc = 0; argc < NUM_ARGV; ++argc)
           argv[argc] = 0;
 
@@ -10152,11 +9903,11 @@ x_term_init (display_name, xrm_option, resource_name)
 
         if (! NILP (display_name))
           {
-            argv[argc++] = "--display";
+            argv[argc++] = display_opt;
             argv[argc++] = SDATA (display_name);
           }
 
-        argv[argc++] = "--name";
+        argv[argc++] = name_opt;
         argv[argc++] = resource_name;
 
         XSetLocaleModifiers ("");
@@ -10179,7 +9930,7 @@ x_term_init (display_name, xrm_option, resource_name)
 
         /* Load our own gtkrc if it exists.  */
         {
-          char *file = "~/.emacs.d/gtkrc";
+          const char *file = "~/.emacs.d/gtkrc";
           Lisp_Object s, abs_file;
 
           s = make_string (file, strlen (file));
@@ -10244,7 +9995,8 @@ x_term_init (display_name, xrm_option, resource_name)
   /* We have definitely succeeded.  Record the new connection.  */
 
   dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info));
-  bzero (dpyinfo, sizeof *dpyinfo);
+  memset (dpyinfo, 0, sizeof *dpyinfo);
+  hlinfo = &dpyinfo->mouse_highlight;
 
   terminal = x_create_terminal (dpyinfo);
 
@@ -10367,16 +10119,16 @@ x_term_init (display_name, xrm_option, resource_name)
   dpyinfo->bitmaps_size = 0;
   dpyinfo->bitmaps_last = 0;
   dpyinfo->scratch_cursor_gc = 0;
-  dpyinfo->mouse_face_mouse_frame = 0;
-  dpyinfo->mouse_face_deferred_gc = 0;
-  dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
-  dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
-  dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID;
-  dpyinfo->mouse_face_window = Qnil;
-  dpyinfo->mouse_face_overlay = Qnil;
-  dpyinfo->mouse_face_mouse_x = dpyinfo->mouse_face_mouse_y = 0;
-  dpyinfo->mouse_face_defer = 0;
-  dpyinfo->mouse_face_hidden = 0;
+  hlinfo->mouse_face_mouse_frame = 0;
+  hlinfo->mouse_face_deferred_gc = 0;
+  hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
+  hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
+  hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
+  hlinfo->mouse_face_window = Qnil;
+  hlinfo->mouse_face_overlay = Qnil;
+  hlinfo->mouse_face_mouse_x = hlinfo->mouse_face_mouse_y = 0;
+  hlinfo->mouse_face_defer = 0;
+  hlinfo->mouse_face_hidden = 0;
   dpyinfo->x_focus_frame = 0;
   dpyinfo->x_focus_event_frame = 0;
   dpyinfo->x_highlight_frame = 0;
@@ -10522,9 +10274,12 @@ x_term_init (display_name, xrm_option, resource_name)
     = XInternAtom (dpyinfo->display, "_NET_WM_WINDOW_TYPE", False);
   dpyinfo->Xatom_net_window_type_tooltip
     = XInternAtom (dpyinfo->display, "_NET_WM_WINDOW_TYPE_TOOLTIP", False);
+  dpyinfo->Xatom_net_wm_icon_name
+    = XInternAtom (dpyinfo->display, "_NET_WM_ICON_NAME", False);
+  dpyinfo->Xatom_net_wm_name
+    = XInternAtom (dpyinfo->display, "_NET_WM_NAME", False);
   dpyinfo->Xatom_net_frame_extents  
     = XInternAtom (dpyinfo->display, "_NET_FRAME_EXTENTS", False);
-  dpyinfo->cut_buffers_initialized = 0;
 
   dpyinfo->x_dnd_atoms_size = 8;
   dpyinfo->x_dnd_atoms_length = 0;
@@ -10539,8 +10294,6 @@ x_term_init (display_name, xrm_option, resource_name)
   dpyinfo->connection = connection;
 
   {
-    extern int gray_bitmap_width, gray_bitmap_height;
-    extern char *gray_bitmap_bits;
     dpyinfo->gray
       = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window,
                                     gray_bitmap_bits,
@@ -10554,11 +10307,9 @@ x_term_init (display_name, xrm_option, resource_name)
 
   xsettings_initialize (dpyinfo);
 
-#ifdef subprocesses
   /* This is only needed for distinguishing keyboard and process input.  */
   if (connection != 0)
     add_keyboard_wait_descriptor (connection);
-#endif
 
 #ifdef F_SETOWN
   fcntl (connection, F_SETOWN, getpid ());
@@ -10640,8 +10391,7 @@ x_term_init (display_name, xrm_option, resource_name)
    and without sending any more commands to the X server.  */
 
 void
-x_delete_display (dpyinfo)
-     struct x_display_info *dpyinfo;
+x_delete_display (struct x_display_info *dpyinfo)
 {
   struct terminal *t;
 
@@ -10653,7 +10403,7 @@ x_delete_display (dpyinfo)
 #ifdef HAVE_X_SM
         /* Close X session management when we close its display.  */
         if (t->id == 1 && x_session_have_connection ())
-          x_session_close();
+          x_session_close ();
 #endif
         delete_terminal (t);
         break;
@@ -10710,8 +10460,7 @@ x_delete_display (dpyinfo)
    that slows us down.  */
 
 static void
-x_process_timeouts (timer)
-     struct atimer *timer;
+x_process_timeouts (struct atimer *timer)
 {
   BLOCK_INPUT;
   x_timeout_atimer_activated_flag = 0;
@@ -10734,7 +10483,7 @@ x_process_timeouts (timer)
    processed, these widgets don't behave normally.  */
 
 void
-x_activate_timeout_atimer ()
+x_activate_timeout_atimer (void)
 {
   BLOCK_INPUT;
   if (!x_timeout_atimer_activated_flag)
@@ -10910,7 +10659,7 @@ x_create_terminal (struct x_display_info *dpyinfo)
 }
 
 void
-x_initialize ()
+x_initialize (void)
 {
   baud_rate = 19200;
 
@@ -10968,7 +10717,7 @@ x_initialize ()
 
 
 void
-syms_of_xterm ()
+syms_of_xterm (void)
 {
   x_error_message = NULL;
 
@@ -11024,9 +10773,11 @@ selected window or cursor position is preserved.  */);
   x_mouse_click_focus_ignore_position = 0;
 
   DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
-    doc: /* What X toolkit scroll bars Emacs uses.
-A value of nil means Emacs doesn't use X toolkit scroll bars.
-Otherwise, value is a symbol describing the X toolkit.  */);
+    doc: /* Which toolkit scroll bars Emacs uses, if any.
+A value of nil means Emacs doesn't use toolkit scroll bars.
+With the X Window system, the value is a symbol describing the
+X toolkit.  Possible values are: gtk, motif, xaw, or xaw3d.
+With MS Windows, the value is t.  */);
 #ifdef USE_TOOLKIT_SCROLL_BARS
 #ifdef USE_MOTIF
   Vx_toolkit_scroll_bars = intern_c_string ("motif");
@@ -11092,5 +10843,3 @@ default is nil, which is the same as `super'.  */);
 
 #endif /* HAVE_X_WINDOWS */
 
-/* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
-   (do not change this comment) */