]> code.delx.au - gnu-emacs/blobdiff - src/xfns.c
Merge changes from emacs-23 branch.
[gnu-emacs] / src / xfns.c
index 458904b326af0b8e65779b0e2504b92b9d751ff8..ee020371683df69d41a5588c4f282cf6b65adf17 100644 (file)
@@ -110,11 +110,6 @@ extern void _XEditResCheckMessages ();
 
 extern LWLIB_ID widget_id_tick;
 
-#ifdef USE_LUCID
-/* This is part of a kludge--see lwlib/xlwmenu.c.  */
-extern XFontStruct *xlwmenu_default_font;
-#endif
-
 extern void free_frame_menubar ();
 extern double atof ();
 
@@ -203,8 +198,13 @@ Lisp_Object Qfont_param;
 
 extern Lisp_Object Vwindow_system_version;
 
+/* In editfns.c */
+
+extern Lisp_Object Vsystem_name;
+
 /* The below are defined in frame.c.  */
 
+extern Lisp_Object Vmenu_bar_mode, Vtool_bar_mode;
 extern Lisp_Object Qtooltip;
 
 #if GLYPH_DEBUG
@@ -219,7 +219,7 @@ char *x_last_font_name;
 /* Error if we are not connected to X.  */
 
 void
-check_x ()
+check_x (void)
 {
   if (! x_in_use)
     error ("X windows are not in use or not initialized");
@@ -229,7 +229,7 @@ check_x ()
    You should not call this unless HAVE_MENUS is defined.  */
 
 int
-have_menus_p ()
+have_menus_p (void)
 {
   return x_in_use;
 }
@@ -238,8 +238,7 @@ have_menus_p ()
    and checking validity for X.  */
 
 FRAME_PTR
-check_x_frame (frame)
-     Lisp_Object frame;
+check_x_frame (Lisp_Object frame)
 {
   FRAME_PTR f;
 
@@ -258,8 +257,7 @@ check_x_frame (frame)
    the first X display on the list.  */
 
 struct x_display_info *
-check_x_display_info (object)
-     Lisp_Object object;
+check_x_display_info (Lisp_Object object)
 {
   struct x_display_info *dpyinfo = NULL;
 
@@ -301,9 +299,7 @@ check_x_display_info (object)
 /* This function can be called during GC, so use GC_xxx type test macros.  */
 
 struct frame *
-x_window_to_frame (dpyinfo, wdesc)
-     struct x_display_info *dpyinfo;
-     int wdesc;
+x_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
 {
   Lisp_Object tail, frame;
   struct frame *f;
@@ -351,9 +347,7 @@ x_window_to_frame (dpyinfo, wdesc)
    windows.  */
 
 struct frame *
-x_any_window_to_frame (dpyinfo, wdesc)
-     struct x_display_info *dpyinfo;
-     int wdesc;
+x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
 {
   Lisp_Object tail, frame;
   struct frame *f, *found;
@@ -404,9 +398,7 @@ x_any_window_to_frame (dpyinfo, wdesc)
 /* Likewise, but consider only the menu bar widget.  */
 
 struct frame *
-x_menubar_window_to_frame (dpyinfo, event)
-     struct x_display_info *dpyinfo;
-     XEvent *event;
+x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event)
 {
   Window wdesc = event->xany.window;
   Lisp_Object tail, frame;
@@ -441,9 +433,7 @@ x_menubar_window_to_frame (dpyinfo, event)
    If WDESC is some other (smaller) window, we return 0.  */
 
 struct frame *
-x_top_window_to_frame (dpyinfo, wdesc)
-     struct x_display_info *dpyinfo;
-     int wdesc;
+x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
 {
   Lisp_Object tail, frame;
   struct frame *f;
@@ -491,33 +481,33 @@ x_top_window_to_frame (dpyinfo, wdesc)
 
 \f
 
-static void x_default_font_parameter P_ ((struct frame *, Lisp_Object));
-
-static Lisp_Object unwind_create_frame P_ ((Lisp_Object));
-static Lisp_Object unwind_create_tip_frame P_ ((Lisp_Object));
-
-void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
-static void x_set_wait_for_wm P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_border_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_cursor_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_icon_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_icon_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
-void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object,
-                                     Lisp_Object));
-void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object,
-                                     Lisp_Object));
-static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *,
-                                                            Lisp_Object,
-                                                            Lisp_Object,
-                                                            char *, char *,
-                                                            int));
+static void x_default_font_parameter (struct frame *, Lisp_Object);
+
+static Lisp_Object unwind_create_frame (Lisp_Object);
+static Lisp_Object unwind_create_tip_frame (Lisp_Object);
+
+void x_set_foreground_color (struct frame *, Lisp_Object, Lisp_Object);
+static void x_set_wait_for_wm (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_background_color (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_mouse_color (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_cursor_color (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_border_color (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_cursor_type (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_icon_type (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_icon_name (struct frame *, Lisp_Object, Lisp_Object);
+void x_explicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_title (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_tool_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
+void x_set_scroll_bar_foreground (struct frame *, Lisp_Object,
+                                  Lisp_Object);
+void x_set_scroll_bar_background (struct frame *, Lisp_Object,
+                                  Lisp_Object);
+static Lisp_Object x_default_scroll_bar_color_parameter (struct frame *,
+                                                         Lisp_Object,
+                                                         Lisp_Object,
+                                                         char *, char *,
+                                                         int);
 \f
 
 /* Store the screen positions of frame F into XPTR and YPTR.
@@ -525,9 +515,7 @@ static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *,
    not Emacs's own window.  */
 
 void
-x_real_positions (f, xptr, yptr)
-     FRAME_PTR f;
-     int *xptr, *yptr;
+x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
 {
   int win_x, win_y, outer_x, outer_y;
   int real_x = 0, real_y = 0;
@@ -645,9 +633,7 @@ x_real_positions (f, xptr, yptr)
 /* Gamma-correct COLOR on frame F.  */
 
 void
-gamma_correct (f, color)
-     struct frame *f;
-     XColor *color;
+gamma_correct (struct frame *f, XColor *color)
 {
   if (f->gamma)
     {
@@ -664,11 +650,7 @@ gamma_correct (f, color)
    no color could be allocated.  */
 
 int
-x_defined_color (f, color_name, color, alloc_p)
-     struct frame *f;
-     char *color_name;
-     XColor *color;
-     int alloc_p;
+x_defined_color (struct frame *f, char *color_name, XColor *color, int alloc_p)
 {
   int success_p;
   Display *dpy = FRAME_X_DISPLAY (f);
@@ -689,10 +671,7 @@ x_defined_color (f, color_name, color, alloc_p)
    Signal an error if color can't be allocated.  */
 
 int
-x_decode_color (f, color_name, mono_color)
-     FRAME_PTR f;
-     Lisp_Object color_name;
-     int mono_color;
+x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color)
 {
   XColor cdef;
 
@@ -726,9 +705,7 @@ x_decode_color (f, color_name, mono_color)
    See also the comment of wait_for_wm in struct x_output.  */
 
 static void
-x_set_wait_for_wm (f, new_value, old_value)
-     struct frame *f;
-     Lisp_Object new_value, old_value;
+x_set_wait_for_wm (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   f->output_data.x->wait_for_wm = !NILP (new_value);
 }
@@ -739,9 +716,7 @@ x_set_wait_for_wm (f, new_value, old_value)
    may be any format that GdkPixbuf knows about, i.e. not just bitmaps.  */
 
 int
-xg_set_icon (f, file)
-    FRAME_PTR f;
-    Lisp_Object file;
+xg_set_icon (FRAME_PTR f, Lisp_Object file)
 {
   int result = 0;
   Lisp_Object found;
@@ -775,9 +750,7 @@ xg_set_icon (f, file)
 }
 
 int
-xg_set_icon_from_xpm_data (f, data)
-    FRAME_PTR f;
-    char **data;
+xg_set_icon_from_xpm_data (FRAME_PTR f, char **data)
 {
   int result = 0;
   GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) data);
@@ -801,9 +774,7 @@ xg_set_icon_from_xpm_data (f, data)
    in the standard place; do not attempt to change the window.  */
 
 void
-x_set_foreground_color (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   struct x_output *x = f->output_data.x;
   unsigned long fg, old_fg;
@@ -839,9 +810,7 @@ x_set_foreground_color (f, arg, oldval)
 }
 
 void
-x_set_background_color (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   struct x_output *x = f->output_data.x;
   unsigned long bg;
@@ -887,8 +856,7 @@ x_set_background_color (f, arg, oldval)
 }
 
 static Cursor
-make_invisible_cursor (f)
-     struct frame *f;
+make_invisible_cursor (struct frame *f)
 {
   Display *dpy = FRAME_X_DISPLAY (f);
   static char const no_data[] = { 0 };
@@ -916,9 +884,7 @@ make_invisible_cursor (f)
 }
 
 void
-x_set_mouse_color (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   struct x_output *x = f->output_data.x;
   Display *dpy = FRAME_X_DISPLAY (f);
@@ -1063,9 +1029,7 @@ x_set_mouse_color (f, arg, oldval)
 }
 
 void
-x_set_cursor_color (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   unsigned long fore_pixel, pixel;
   int fore_pixel_allocated_p = 0, pixel_allocated_p = 0;
@@ -1136,9 +1100,7 @@ x_set_cursor_color (f, arg, oldval)
    F has an x-window.  */
 
 void
-x_set_border_pixel (f, pix)
-     struct frame *f;
-     int pix;
+x_set_border_pixel (struct frame *f, int pix)
 {
   unload_color (f, f->output_data.x->border_pixel);
   f->output_data.x->border_pixel = pix;
@@ -1167,9 +1129,7 @@ x_set_border_pixel (f, pix)
    and so emacs' border colors may be overridden.  */
 
 void
-x_set_border_color (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int pix;
 
@@ -1181,9 +1141,7 @@ x_set_border_color (f, arg, oldval)
 
 
 void
-x_set_cursor_type (f, arg, oldval)
-     FRAME_PTR f;
-     Lisp_Object arg, oldval;
+x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
 {
   set_frame_cursor_types (f, arg);
 
@@ -1192,9 +1150,7 @@ x_set_cursor_type (f, arg, oldval)
 }
 \f
 void
-x_set_icon_type (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int result;
 
@@ -1226,9 +1182,7 @@ x_set_icon_type (f, arg, oldval)
 }
 
 void
-x_set_icon_name (f, arg, oldval)
-     struct frame *f;
-     Lisp_Object arg, oldval;
+x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int result;
 
@@ -1266,9 +1220,7 @@ x_set_icon_name (f, arg, oldval)
 
 \f
 void
-x_set_menu_bar_lines (f, value, oldval)
-     struct frame *f;
-     Lisp_Object value, oldval;
+x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   int nlines;
 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
@@ -1358,9 +1310,7 @@ x_set_menu_bar_lines (f, value, oldval)
    The frame's height doesn't change.  */
 
 void
-x_set_tool_bar_lines (f, value, oldval)
-     struct frame *f;
-     Lisp_Object value, oldval;
+x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   int delta, nlines, root_height;
   Lisp_Object root_window;
@@ -1455,9 +1405,7 @@ x_set_tool_bar_lines (f, value, oldval)
    the frame parameter.  */
 
 void
-x_set_scroll_bar_foreground (f, value, oldval)
-     struct frame *f;
-     Lisp_Object value, oldval;
+x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   unsigned long pixel;
 
@@ -1490,9 +1438,7 @@ x_set_scroll_bar_foreground (f, value, oldval)
    parameter.  */
 
 void
-x_set_scroll_bar_background (f, value, oldval)
-     struct frame *f;
-     Lisp_Object value, oldval;
+x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   unsigned long pixel;
 
@@ -1555,11 +1501,7 @@ x_set_scroll_bar_background (f, value, oldval)
    the result should be `COMPOUND_TEXT'.  */
 
 static unsigned char *
-x_encode_text (string, coding_system, selectionp, text_bytes, stringp, freep)
-     Lisp_Object string, coding_system;
-     int *text_bytes, *stringp;
-     int selectionp;
-     int *freep;
+x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp, int *text_bytes, int *stringp, int *freep)
 {
   int result = string_xstring_p (string);
   struct coding_system coding;
@@ -1593,9 +1535,7 @@ x_encode_text (string, coding_system, selectionp, text_bytes, stringp, freep)
    icon name to NAME.  */
 
 static void
-x_set_name_internal (f, name)
-     FRAME_PTR f;
-     Lisp_Object name;
+x_set_name_internal (FRAME_PTR f, Lisp_Object name)
 {
   if (FRAME_X_WINDOW (f))
     {
@@ -1605,8 +1545,8 @@ x_set_name_internal (f, name)
        int bytes, stringp;
         int do_free_icon_value = 0, do_free_text_value = 0;
        Lisp_Object coding_system;
-#ifdef USE_GTK
        Lisp_Object encoded_name;
+       Lisp_Object encoded_icon_name;
        struct gcpro gcpro1;
 
        /* As ENCODE_UTF_8 may cause GC and relocation of string data,
@@ -1614,7 +1554,6 @@ x_set_name_internal (f, name)
        GCPRO1 (name);
        encoded_name = ENCODE_UTF_8 (name);
        UNGCPRO;
-#endif
 
        coding_system = Qcompound_text;
        /* Note: Encoding strategy
@@ -1630,7 +1569,12 @@ x_set_name_internal (f, name)
           We may also be able to use "UTF8_STRING" in text.encoding
           in the future which can encode all Unicode characters.
           But, for the moment, there's no way to know that the
-          current window manager supports it or not.  */
+          current window manager supports it or not.
+
+          Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
+          properties.  Per the EWMH specification, those two properties
+          are always UTF8_STRING.  This matches what gtk_window_set_title()
+          does in the USE_GTK case. */
        text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp,
                                    &do_free_text_value);
        text.encoding = (stringp ? XA_STRING
@@ -1641,6 +1585,7 @@ x_set_name_internal (f, name)
        if (!STRINGP (f->icon_name))
          {
            icon = text;
+           encoded_icon_name = encoded_name;
          }
        else
          {
@@ -1651,6 +1596,8 @@ x_set_name_internal (f, name)
                             : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
            icon.format = 8;
            icon.nitems = bytes;
+
+           encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
          }
 
 #ifdef USE_GTK
@@ -1658,9 +1605,21 @@ x_set_name_internal (f, name)
                               (char *) SDATA (encoded_name));
 #else /* not USE_GTK */
        XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
+       XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                        FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_name,
+                        FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
+                        8, PropModeReplace,
+                        (char *) SDATA (encoded_name),
+                        SBYTES (encoded_name));
 #endif /* not USE_GTK */
 
        XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
+       XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
+                        FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_icon_name,
+                        FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
+                        8, PropModeReplace,
+                        (char *) SDATA (encoded_icon_name),
+                        SBYTES (encoded_icon_name));
 
        if (do_free_icon_value)
          xfree (icon.value);
@@ -1683,10 +1642,7 @@ x_set_name_internal (f, name)
        F->explicit_name is set, ignore the new name; otherwise, set it.  */
 
 void
-x_set_name (f, name, explicit)
-     struct frame *f;
-     Lisp_Object name;
-     int explicit;
+x_set_name (struct frame *f, Lisp_Object name, int explicit)
 {
   /* Make sure that requests from lisp code override requests from
      Emacs redisplay code.  */
@@ -1733,9 +1689,7 @@ x_set_name (f, name, explicit)
    specified a name for the frame; the name will override any set by the
    redisplay code.  */
 void
-x_explicitly_set_name (f, arg, oldval)
-     FRAME_PTR f;
-     Lisp_Object arg, oldval;
+x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
 {
   x_set_name (f, arg, 1);
 }
@@ -1744,9 +1698,7 @@ x_explicitly_set_name (f, arg, oldval)
    name; names set this way will never override names set by the user's
    lisp code.  */
 void
-x_implicitly_set_name (f, arg, oldval)
-     FRAME_PTR f;
-     Lisp_Object arg, oldval;
+x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
 {
   x_set_name (f, arg, 0);
 }
@@ -1755,9 +1707,7 @@ x_implicitly_set_name (f, arg, oldval)
    If NAME is nil, use the frame name as the title.  */
 
 void
-x_set_title (f, name, old_name)
-     struct frame *f;
-     Lisp_Object name, old_name;
+x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
 {
   /* Don't change the title if it's already NAME.  */
   if (EQ (name, f->title))
@@ -1776,8 +1726,7 @@ x_set_title (f, name, old_name)
 }
 
 void
-x_set_scroll_bar_default_width (f)
-     struct frame *f;
+x_set_scroll_bar_default_width (struct frame *f)
 {
   int wid = FRAME_COLUMN_WIDTH (f);
 
@@ -1804,14 +1753,10 @@ x_set_scroll_bar_default_width (f)
    named NAME.  If that is not found either, use the value DEFLT.  */
 
 static Lisp_Object
-x_default_scroll_bar_color_parameter (f, alist, prop, xprop, xclass,
-                                     foreground_p)
-     struct frame *f;
-     Lisp_Object alist;
-     Lisp_Object prop;
-     char *xprop;
-     char *xclass;
-     int foreground_p;
+x_default_scroll_bar_color_parameter (struct frame *f,
+                                     Lisp_Object alist, Lisp_Object prop,
+                                     char *xprop, char *xclass,
+                                     int foreground_p)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Lisp_Object tem;
@@ -1862,9 +1807,7 @@ x_default_scroll_bar_color_parameter (f, alist, prop, xprop, xclass,
    for example, but Xt doesn't).  */
 
 static void
-hack_wm_protocols (f, widget)
-     FRAME_PTR f;
-     Widget widget;
+hack_wm_protocols (FRAME_PTR f, Widget widget)
 {
   Display *dpy = XtDisplay (widget);
   Window w = XtWindow (widget);
@@ -1930,8 +1873,8 @@ hack_wm_protocols (f, widget)
 
 #ifdef HAVE_X_I18N
 
-static XFontSet xic_create_xfontset P_ ((struct frame *));
-static XIMStyle best_xim_style P_ ((XIMStyles *, XIMStyles *));
+static XFontSet xic_create_xfontset (struct frame *);
+static XIMStyle best_xim_style (XIMStyles *, XIMStyles *);
 
 
 /* Supported XIM styles, ordered by preference.  */
@@ -1958,9 +1901,7 @@ char xic_defaut_fontset[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
 /* Create an Xt fontset spec from the name of a base font.
    If `motif' is True use the Motif syntax.  */
 char *
-xic_create_fontsetname (base_fontname, motif)
-     char *base_fontname;
-     Bool motif;
+xic_create_fontsetname (char *base_fontname, int motif)
 {
   const char *sep = motif ? ";" : ",";
   char *fontsetname;
@@ -1970,7 +1911,7 @@ xic_create_fontsetname (base_fontname, motif)
     { /* There is no base font name, use the default.  */
       int len = strlen (base_fontname) + 2;
       fontsetname = xmalloc (len);
-      bzero (fontsetname, len);
+      memset (fontsetname, 0, len);
       strcpy (fontsetname, base_fontname);
     }
   else
@@ -1991,7 +1932,7 @@ xic_create_fontsetname (base_fontname, motif)
             Use the specified font plus the default.  */
          int len = strlen (base_fontname) + strlen (xic_defaut_fontset) + 3;
          fontsetname = xmalloc (len);
-         bzero (fontsetname, len);
+         memset (fontsetname, 0, len);
          strcpy (fontsetname, base_fontname);
          strcat (fontsetname, sep);
          strcat (fontsetname, xic_defaut_fontset);
@@ -2028,7 +1969,7 @@ xic_create_fontsetname (base_fontname, motif)
              int diff = (p2 - p3) - 2;
 
              base = alloca (strlen (base_fontname) + 1);
-             bcopy (base_fontname, base, p3 - base_fontname);
+             memcpy (base, base_fontname, p3 - base_fontname);
              base[p3 - base_fontname] = '*';
              base[(p3 - base_fontname) + 1] = '-';
              strcpy (base + (p3 - base_fontname) + 2, p2);
@@ -2041,33 +1982,33 @@ xic_create_fontsetname (base_fontname, motif)
          /* Build the font spec that matches all charsets.  */
          len = p - base_fontname + strlen (allcs) + 1;
          font_allcs = (char *) alloca (len);
-         bzero (font_allcs, len);
-         bcopy (base_fontname, font_allcs, p - base_fontname);
+         memset (font_allcs, 0, len);
+         memcpy (font_allcs, base_fontname, p - base_fontname);
          strcat (font_allcs, allcs);
 
          /* Build the font spec that matches all families and
             add-styles.  */
          len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1;
          font_allfamilies = (char *) alloca (len);
-         bzero (font_allfamilies, len);
+         memset (font_allfamilies, 0, len);
          strcpy (font_allfamilies, allfamilies);
-         bcopy (p1, font_allfamilies + strlen (allfamilies), p - p1);
+         memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1);
          strcat (font_allfamilies, allcs);
 
          /* Build the font spec that matches all.  */
          len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1;
          font_all = (char *) alloca (len);
-         bzero (font_all, len);
+         memset (font_all, 0, len);
          strcpy (font_all, allfamilies);
          strcat (font_all, all);
-         bcopy (p2, font_all + strlen (all) + strlen (allfamilies), p - p2);
+         memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2);
          strcat (font_all, allcs);
 
          /* Build the actual font set name.  */
          len = strlen (base_fontname) + strlen (font_allcs)
            + strlen (font_allfamilies) + strlen (font_all) + 5;
          fontsetname = xmalloc (len);
-         bzero (fontsetname, len);
+         memset (fontsetname, 0, len);
          strcpy (fontsetname, base_fontname);
          strcat (fontsetname, sep);
          strcat (fontsetname, font_allcs);
@@ -2106,8 +2047,7 @@ print_fontset_result (xfs, name, missing_list, missing_count)
 #endif
 
 static XFontSet
-xic_create_xfontset (f)
-     struct frame *f;
+xic_create_xfontset (struct frame *f)
 {
   XFontSet xfs = NULL;
   struct font *font = FRAME_FONT (f);
@@ -2206,8 +2146,7 @@ xic_create_xfontset (f)
 /* Free the X fontset of frame F if it is the last frame using it.  */
 
 void
-xic_free_xfontset (f)
-     struct frame *f;
+xic_free_xfontset (struct frame *f)
 {
   Lisp_Object rest, frame;
   int shared_p = 0;
@@ -2244,9 +2183,7 @@ xic_free_xfontset (f)
    input method XIM.  */
 
 static XIMStyle
-best_xim_style (user, xim)
-     XIMStyles *user;
-     XIMStyles *xim;
+best_xim_style (XIMStyles *user, XIMStyles *xim)
 {
   int i, j;
 
@@ -2264,8 +2201,7 @@ best_xim_style (user, xim)
 static XIMStyle xic_style;
 
 void
-create_frame_xic (f)
-     struct frame *f;
+create_frame_xic (struct frame *f)
 {
   XIM xim;
   XIC xic = NULL;
@@ -2340,8 +2276,7 @@ create_frame_xic (f)
 /* Destroy XIC and free XIC fontset of frame F, if any. */
 
 void
-free_frame_xic (f)
-     struct frame *f;
+free_frame_xic (struct frame *f)
 {
   if (FRAME_XIC (f) == NULL)
     return;
@@ -2357,9 +2292,7 @@ free_frame_xic (f)
    pixel position X/Y.  X and Y are relative to window W.  */
 
 void
-xic_set_preeditarea (w, x, y)
-     struct window *w;
-     int x, y;
+xic_set_preeditarea (struct window *w, int x, int y)
 {
   struct frame *f = XFRAME (w->frame);
   XVaNestedList attr;
@@ -2376,8 +2309,7 @@ xic_set_preeditarea (w, x, y)
 /* Place status area for XIC in bottom right corner of frame F.. */
 
 void
-xic_set_statusarea (f)
-     struct frame *f;
+xic_set_statusarea (struct frame *f)
 {
   XIC xic = FRAME_XIC (f);
   XVaNestedList attr;
@@ -2421,9 +2353,7 @@ xic_set_statusarea (f)
    BASE_FONTNAME.  Called when a new Emacs fontset is chosen.  */
 
 void
-xic_set_xfontset (f, base_fontname)
-     struct frame *f;
-     char *base_fontname;
+xic_set_xfontset (struct frame *f, char *base_fontname)
 {
   XVaNestedList attr;
   XFontSet xfs;
@@ -2451,10 +2381,7 @@ xic_set_xfontset (f, base_fontname)
 /* Create and set up the X widget for frame F.  */
 
 static void
-x_window (f, window_prompting, minibuffer_only)
-     struct frame *f;
-     long window_prompting;
-     int minibuffer_only;
+x_window (struct frame *f, long window_prompting, int minibuffer_only)
 {
   XClassHint class_hints;
   XSetWindowAttributes attributes;
@@ -2506,6 +2433,7 @@ x_window (f, window_prompting, minibuffer_only)
   XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
   XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
   XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
+  XtSetArg (al[ac], XtNborderWidth, 0); ac++;
   XtSetValues (pane_widget, al, ac);
   f->output_data.x->column_widget = pane_widget;
 
@@ -2521,6 +2449,7 @@ x_window (f, window_prompting, minibuffer_only)
   XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
   XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
   XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
+  XtSetArg (al[ac], XtNborderWidth, 0); ac++;
   frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget,
                                 al, ac);
 
@@ -2698,8 +2627,7 @@ x_window (f, window_prompting, minibuffer_only)
 #else /* not USE_X_TOOLKIT */
 #ifdef USE_GTK
 void
-x_window (f)
-     FRAME_PTR f;
+x_window (FRAME_PTR f)
 {
   if (! xg_create_frame_widgets (f))
     error ("Unable to create window");
@@ -2739,9 +2667,7 @@ x_window (f)
 /* Create and set up the X window for frame F.  */
 
 void
-x_window (f)
-     struct frame *f;
-
+x_window (struct frame *f)
 {
   XClassHint class_hints;
   XSetWindowAttributes attributes;
@@ -2846,9 +2772,7 @@ x_window (f)
 /* Verify that the icon position args for this window are valid.  */
 
 static void
-x_icon_verify (f, parms)
-     struct frame *f;
-     Lisp_Object parms;
+x_icon_verify (struct frame *f, Lisp_Object parms)
 {
   Lisp_Object icon_x, icon_y;
 
@@ -2870,9 +2794,7 @@ x_icon_verify (f, parms)
    well.  */
 
 static void
-x_icon (f, parms)
-     struct frame *f;
-     Lisp_Object parms;
+x_icon (struct frame *f, Lisp_Object parms)
 {
   Lisp_Object icon_x, icon_y;
 #if 0
@@ -2918,8 +2840,7 @@ x_icon (f, parms)
    mouse cursor and the gray border tile.  */
 
 static void
-x_make_gc (f)
-     struct frame *f;
+x_make_gc (struct frame *f)
 {
   XGCValues gc_values;
 
@@ -2978,8 +2899,7 @@ x_make_gc (f)
 /* Free what was allocated in x_make_gc.  */
 
 void
-x_free_gcs (f)
-     struct frame *f;
+x_free_gcs (struct frame *f)
 {
   Display *dpy = FRAME_X_DISPLAY (f);
 
@@ -3018,8 +2938,7 @@ x_free_gcs (f)
    constructed.  */
 
 static Lisp_Object
-unwind_create_frame (frame)
-     Lisp_Object frame;
+unwind_create_frame (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
 
@@ -3051,32 +2970,34 @@ unwind_create_frame (frame)
 
 
 static void
-x_default_font_parameter (f, parms)
-     struct frame *f;
-     Lisp_Object parms;
+x_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
   Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
                                       RES_TYPE_STRING);
-  Lisp_Object font;
-  int got_from_gconf = 0;
+  Lisp_Object font = Qnil;
   if (EQ (font_param, Qunbound))
     font_param = Qnil;
 
   if (NILP (font_param))
     {
-      /* System font takes precedendce over X resources.  We must suggest this
+      /* System font should take precedendce over X resources.  We suggest this
          regardless of font-use-system-font because .emacs may not have been
          read yet.  */
       const char *system_font = xsettings_get_system_font ();
-      if (system_font) font_param = make_string (system_font,
-                                                 strlen (system_font));
+      if (system_font)
+        {
+          char *name = xstrdup (system_font);
+          font = font_open_by_name (f, name);
+          free (name);
+        }
     }
-  
-  font = !NILP (font_param) ? font_param
-    : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
 
-  if (! STRINGP (font))
+  if (NILP (font))
+      font = !NILP (font_param) ? font_param
+      : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
+
+  if (! FONTP (font) && ! STRINGP (font))
     {
       char *names[]
        = {
@@ -3113,10 +3034,8 @@ x_default_font_parameter (f, parms)
       x_set_frame_parameters (f, Fcons (Fcons (Qfont_param, font_param), Qnil));
     }
 
-  x_default_parameter (f, parms, Qfont, font,
-                       got_from_gconf ? NULL : "font",
-                       got_from_gconf ? NULL : "Font",
-                       RES_TYPE_STRING);
+  /* This call will make X resources override any system font setting.  */
+  x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
 }
 
 
@@ -3124,8 +3043,7 @@ DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint, Sx_wm_set_size_hint,
        0, 1, 0,
        doc: /* Send the size hints for frame FRAME to the window manager.
 If FRAME is nil, use the selected frame.  */)
-     (frame)
-     Lisp_Object frame;
+  (Lisp_Object frame)
 {
   struct frame *f;
   if (NILP (frame))
@@ -3138,6 +3056,37 @@ If FRAME is nil, use the selected frame.  */)
   return Qnil;
 }
 
+static void
+set_machine_and_pid_properties (struct frame *f)
+{
+  /* See the above comment "Note: Encoding strategy".  */
+  XTextProperty text;
+  int bytes, stringp;
+  int do_free_text_value = 0;
+  long pid = (long) getpid ();
+
+  text.value = x_encode_text (Vsystem_name,
+                              Qcompound_text, 0, &bytes, &stringp,
+                              &do_free_text_value);
+  text.encoding = (stringp ? XA_STRING
+                   : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
+  text.format = 8;
+  text.nitems = bytes;
+  XSetWMClientMachine (FRAME_X_DISPLAY (f),
+                       FRAME_OUTER_WINDOW (f),
+                       &text);
+  if (do_free_text_value)
+    xfree (text.value);
+
+  XChangeProperty (FRAME_X_DISPLAY (f),
+                   FRAME_OUTER_WINDOW (f),
+                   XInternAtom (FRAME_X_DISPLAY (f),
+                                "_NET_WM_PID",
+                                False),
+                   XA_CARDINAL, 32, PropModeReplace,
+                   (unsigned char *) &pid, 1);
+}
+
 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
        1, 1, 0,
        doc: /* Make a new X window, which is called a "frame" in Emacs terms.
@@ -3149,8 +3098,7 @@ then `default-minibuffer-frame' must be a frame whose minibuffer can
 be shared by the new frame.
 
 This function is an internal primitive--use `make-frame' instead.  */)
-     (parms)
-     Lisp_Object parms;
+  (Lisp_Object parms)
 {
   struct frame *f;
   Lisp_Object frame, tem;
@@ -3227,7 +3175,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
 
   f->output_method = output_x_window;
   f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
-  bzero (f->output_data.x, sizeof (struct x_output));
+  memset (f->output_data.x, 0, sizeof (struct x_output));
   f->output_data.x->icon_bitmap = -1;
   FRAME_FONTSET (f) = -1;
   f->output_data.x->scroll_bar_foreground_pixel = -1;
@@ -3337,17 +3285,9 @@ This function is an internal primitive--use `make-frame' instead.  */)
       error ("Invalid frame font");
     }
 
-#ifdef USE_LUCID
-  /* Prevent lwlib/xlwmenu.c from crashing because of a bug
-     whereby it fails to get any font.  */
-  BLOCK_INPUT;
-  xlwmenu_default_font = XLoadQueryFont (FRAME_X_DISPLAY (f), "fixed");
-  UNBLOCK_INPUT;
-#endif
-
   /* Frame contents get displaced if an embedded X window has a border.  */
   if (! FRAME_X_EMBEDDED_P (f))
-    x_default_parameter (f, parms, Qborder_width, make_number (2),
+    x_default_parameter (f, parms, Qborder_width, make_number (0),
                         "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
 
   /* This defaults to 1 in order to match xterm.  We recognize either
@@ -3371,7 +3311,12 @@ This function is an internal primitive--use `make-frame' instead.  */)
 #endif
                       "internalBorderWidth", "internalBorderWidth",
                       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qvertical_scroll_bars, Qleft,
+  x_default_parameter (f, parms, Qvertical_scroll_bars,
+#if defined(USE_GTK) && defined(USE_TOOLKIT_SCROLL_BARS)
+                      Qright,
+#else
+                      Qleft,
+#endif
                       "verticalScrollBars", "ScrollBars",
                       RES_TYPE_SYMBOL);
 
@@ -3410,10 +3355,18 @@ This function is an internal primitive--use `make-frame' instead.  */)
      happen.  */
   init_frame_faces (f);
 
-  x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
-                      "menuBar", "MenuBar", RES_TYPE_BOOLEAN_NUMBER);
-  x_default_parameter (f, parms, Qtool_bar_lines, make_number (1),
-                      "toolBar", "ToolBar", RES_TYPE_NUMBER);
+  /* The X resources controlling the menu-bar and tool-bar are
+     processed specially at startup, and reflected in the mode
+     variables; ignore them here.  */
+  x_default_parameter (f, parms, Qmenu_bar_lines,
+                      NILP (Vmenu_bar_mode)
+                      ? make_number (0) : make_number (1),
+                      NULL, NULL, RES_TYPE_NUMBER);
+  x_default_parameter (f, parms, Qtool_bar_lines,
+                      NILP (Vtool_bar_mode)
+                      ? make_number (0) : make_number (1),
+                      NULL, NULL, RES_TYPE_NUMBER);
+
   x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
                       "bufferPredicate", "BufferPredicate",
                       RES_TYPE_SYMBOL);
@@ -3519,19 +3472,24 @@ This function is an internal primitive--use `make-frame' instead.  */)
        ;
     }
 
+  BLOCK_INPUT;
+                       
+  /* Set machine name and pid for the purpose of window managers.  */
+  set_machine_and_pid_properties(f);
+
   /* Set the WM leader property.  GTK does this itself, so this is not
      needed when using GTK.  */
   if (dpyinfo->client_leader_window != 0)
     {
-      BLOCK_INPUT;
       XChangeProperty (FRAME_X_DISPLAY (f),
                        FRAME_OUTER_WINDOW (f),
                        dpyinfo->Xatom_wm_client_leader,
                        XA_WINDOW, 32, PropModeReplace,
                        (unsigned char *) &dpyinfo->client_leader_window, 1);
-      UNBLOCK_INPUT;
     }
 
+  UNBLOCK_INPUT;
+
   /* Initialize `default-minibuffer-frame' in case this is the first
      frame on this terminal.  */
   if (FRAME_HAS_MINIBUF_P (f)
@@ -3560,8 +3518,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
    know about that structure.  */
 
 Lisp_Object
-x_get_focus_frame (frame)
-     struct frame *frame;
+x_get_focus_frame (struct frame *frame)
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame);
   Lisp_Object xfocus;
@@ -3585,8 +3542,7 @@ x_get_focus_frame (frame)
 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
        doc: /* Set the input focus to FRAME.
 FRAME nil means use the selected frame.  */)
-     (frame)
-     Lisp_Object frame;
+  (Lisp_Object frame)
 {
   struct frame *f = check_x_frame (frame);
   Display *dpy = FRAME_X_DISPLAY (f);
@@ -3605,8 +3561,7 @@ FRAME nil means use the selected frame.  */)
 \f
 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
        doc: /* Internal function called by `color-defined-p', which see.  */)
-     (color, frame)
-     Lisp_Object color, frame;
+  (Lisp_Object color, Lisp_Object frame)
 {
   XColor foo;
   FRAME_PTR f = check_x_frame (frame);
@@ -3621,8 +3576,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
 
 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
        doc: /* Internal function called by `color-values', which see.  */)
-     (color, frame)
-     Lisp_Object color, frame;
+  (Lisp_Object color, Lisp_Object frame)
 {
   XColor foo;
   FRAME_PTR f = check_x_frame (frame);
@@ -3639,8 +3593,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
 
 DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
        doc: /* Internal function called by `display-color-p', which see.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3667,8 +3620,7 @@ Note that color displays do support shades of gray.
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3696,8 +3648,7 @@ DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3710,8 +3661,7 @@ DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3724,8 +3674,7 @@ DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3738,8 +3687,7 @@ DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3763,8 +3711,7 @@ DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3778,8 +3725,7 @@ that operating systems cannot be developed and distributed noncommercially.)
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
   char *vendor = ServerVendor (dpyinfo->display);
@@ -3797,8 +3743,7 @@ number.  See also the function `x-server-vendor'.
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
   Display *dpy = dpyinfo->display;
@@ -3813,8 +3758,7 @@ DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3826,8 +3770,7 @@ DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3839,8 +3782,7 @@ DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3854,8 +3796,7 @@ The value may be `always', `when-mapped', or `not-useful'.
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
   Lisp_Object result;
@@ -3891,8 +3832,7 @@ The value is one of the symbols `static-gray', `gray-scale',
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
   Lisp_Object result;
@@ -3931,8 +3871,7 @@ DEFUN ("x-display-save-under", Fx_display_save_under,
 The optional argument TERMINAL specifies which display to ask about.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If omitted or nil, that stands for the selected frame's display.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -3943,36 +3882,31 @@ If omitted or nil, that stands for the selected frame's display.  */)
 }
 \f
 int
-x_pixel_width (f)
-     register struct frame *f;
+x_pixel_width (register struct frame *f)
 {
   return FRAME_PIXEL_WIDTH (f);
 }
 
 int
-x_pixel_height (f)
-     register struct frame *f;
+x_pixel_height (register struct frame *f)
 {
   return FRAME_PIXEL_HEIGHT (f);
 }
 
 int
-x_char_width (f)
-     register struct frame *f;
+x_char_width (register struct frame *f)
 {
   return FRAME_COLUMN_WIDTH (f);
 }
 
 int
-x_char_height (f)
-     register struct frame *f;
+x_char_height (register struct frame *f)
 {
   return FRAME_LINE_HEIGHT (f);
 }
 
 int
-x_screen_planes (f)
-     register struct frame *f;
+x_screen_planes (register struct frame *f)
 {
   return FRAME_X_DISPLAY_INFO (f)->n_planes;
 }
@@ -4029,8 +3963,7 @@ XScreenNumberOfScreen (scr)
    members of DPYINFO appropriately.  Called from x_term_init.  */
 
 void
-select_visual (dpyinfo)
-     struct x_display_info *dpyinfo;
+select_visual (struct x_display_info *dpyinfo)
 {
   Display *dpy = dpyinfo->display;
   Screen *screen = dpyinfo->screen;
@@ -4052,7 +3985,7 @@ select_visual (dpyinfo)
       XVisualInfo vinfo;
 
       strcpy (s, SDATA (value));
-      dash = index (s, '-');
+      dash = strchr (s, '-');
       if (dash)
        {
          dpyinfo->n_planes = atoi (dash + 1);
@@ -4090,7 +4023,7 @@ select_visual (dpyinfo)
       vinfo_template.screen = XScreenNumberOfScreen (screen);
       vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask,
                              &vinfo_template, &n_visuals);
-      if (n_visuals != 1)
+      if (n_visuals <= 0)
        fatal ("Can't get proper X visual info");
 
       dpyinfo->n_planes = vinfo->depth;
@@ -4103,8 +4036,7 @@ select_visual (dpyinfo)
    Open a new connection if necessary.  */
 
 struct x_display_info *
-x_display_info_for_name (name)
-     Lisp_Object name;
+x_display_info_for_name (Lisp_Object name)
 {
   Lisp_Object names;
   struct x_display_info *dpyinfo;
@@ -4151,8 +4083,7 @@ DISPLAY is the name of the display to connect to.
 Optional second arg XRM-STRING is a string of resources in xrdb format.
 If the optional third arg MUST-SUCCEED is non-nil,
 terminate Emacs if we can't open the connection.  */)
-     (display, xrm_string, must_succeed)
-     Lisp_Object display, xrm_string, must_succeed;
+  (Lisp_Object display, Lisp_Object xrm_string, Lisp_Object must_succeed)
 {
   unsigned char *xrm_option;
   struct x_display_info *dpyinfo;
@@ -4203,8 +4134,7 @@ DEFUN ("x-close-connection", Fx_close_connection,
 For TERMINAL, specify a terminal object, a frame or a display name (a
 string).  If TERMINAL is nil, that stands for the selected frame's
 terminal.  */)
-     (terminal)
-     Lisp_Object terminal;
+  (Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -4218,7 +4148,7 @@ terminal.  */)
 
 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
        doc: /* Return the list of display names that Emacs has connections to.  */)
-     ()
+  (void)
 {
   Lisp_Object tail, result;
 
@@ -4238,8 +4168,7 @@ easier.
 The optional second argument TERMINAL specifies which display to act on.
 TERMINAL should be a terminal object, a frame or a display name (a string).
 If TERMINAL is omitted or nil, that stands for the selected frame's display.  */)
-     (on, terminal)
-    Lisp_Object terminal, on;
+  (Lisp_Object on, Lisp_Object terminal)
 {
   struct x_display_info *dpyinfo = check_x_display_info (terminal);
 
@@ -4251,8 +4180,7 @@ If TERMINAL is omitted or nil, that stands for the selected frame's display.  */
 /* Wait for responses to all X commands issued so far for frame F.  */
 
 void
-x_sync (f)
-     FRAME_PTR f;
+x_sync (FRAME_PTR f)
 {
   BLOCK_INPUT;
   XSync (FRAME_X_DISPLAY (f), False);
@@ -4283,8 +4211,7 @@ If OUTER_P is non-nil, the property is changed for the outer X window of
 FRAME.  Default is to change on the edit X window.
 
 Value is VALUE.  */)
-     (prop, value, frame, type, format, outer_p)
-     Lisp_Object prop, value, frame, type, format, outer_p;
+  (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
 {
   struct frame *f = check_x_frame (frame);
   Atom prop_atom;
@@ -4362,8 +4289,7 @@ DEFUN ("x-delete-window-property", Fx_delete_window_property,
        Sx_delete_window_property, 1, 2, 0,
        doc: /* Remove window property PROP from X window of FRAME.
 FRAME nil or omitted means use the selected frame.  Value is PROP.  */)
-     (prop, frame)
-     Lisp_Object prop, frame;
+  (Lisp_Object prop, Lisp_Object frame)
 {
   struct frame *f = check_x_frame (frame);
   Atom prop_atom;
@@ -4394,8 +4320,7 @@ If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
 
 Value is nil if FRAME hasn't a property with name PROP or if PROP has
 no value of TYPE.  */)
-     (prop, frame, type, source, delete_p, vector_ret_p)
-     Lisp_Object prop, frame, type, source, delete_p, vector_ret_p;
+  (Lisp_Object prop, Lisp_Object frame, Lisp_Object type, Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
 {
   struct frame *f = check_x_frame (frame);
   Atom prop_atom;
@@ -4463,7 +4388,7 @@ no value of TYPE.  */)
              elements."
              This applies even if long is more than 32 bits, the X library
              converts from 32 bit elements received from the X server to long
-             and passes the long array to us.  Thus, for that case bcopy can not
+             and passes the long array to us.  Thus, for that case memcpy can not
              be used.  We convert to a 32 bit type here, because so much code
              assume on that.
 
@@ -4514,8 +4439,7 @@ no value of TYPE.  */)
    shown on the frames.  */
 
 void
-show_hourglass (timer)
-     struct atimer *timer;
+show_hourglass (struct atimer *timer)
 {
   /* The timer implementation will cancel this timer automatically
      after this function has run.  Set hourglass_atimer to null
@@ -4579,7 +4503,7 @@ show_hourglass (timer)
    shown.  */
 
 void
-hide_hourglass ()
+hide_hourglass (void)
 {
   if (hourglass_shown_p)
     {
@@ -4614,10 +4538,10 @@ hide_hourglass ()
                                Tool tips
  ***********************************************************************/
 
-static Lisp_Object x_create_tip_frame P_ ((struct x_display_info *,
-                                          Lisp_Object, Lisp_Object));
-static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object,
-                               Lisp_Object, int, int, int *, int *));
+static Lisp_Object x_create_tip_frame (struct x_display_info *,
+                                       Lisp_Object, Lisp_Object);
+static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object,
+                            Lisp_Object, int, int, int *, int *);
 
 /* The frame of a currently visible tooltip.  */
 
@@ -4640,8 +4564,7 @@ Lisp_Object Vx_max_tooltip_size;
 
 
 static Lisp_Object
-unwind_create_tip_frame (frame)
-     Lisp_Object frame;
+unwind_create_tip_frame (Lisp_Object frame)
 {
   Lisp_Object deleted;
 
@@ -4666,9 +4589,7 @@ unwind_create_tip_frame (frame)
    when this happens.  */
 
 static Lisp_Object
-x_create_tip_frame (dpyinfo, parms, text)
-     struct x_display_info *dpyinfo;
-     Lisp_Object parms, text;
+x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms, Lisp_Object text)
 {
   struct frame *f;
   Lisp_Object frame, tem;
@@ -4723,7 +4644,7 @@ x_create_tip_frame (dpyinfo, parms, text)
      counts etc.  */
   f->output_method = output_x_window;
   f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
-  bzero (f->output_data.x, sizeof (struct x_output));
+  memset (f->output_data.x, 0, sizeof (struct x_output));
   f->output_data.x->icon_bitmap = -1;
   FRAME_FONTSET (f) = -1;
   f->output_data.x->scroll_bar_foreground_pixel = -1;
@@ -4808,7 +4729,7 @@ x_create_tip_frame (dpyinfo, parms, text)
      needed to determine window geometry.  */
   x_default_font_parameter (f, parms);
 
-  x_default_parameter (f, parms, Qborder_width, make_number (2),
+  x_default_parameter (f, parms, Qborder_width, make_number (0),
                       "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
 
   /* This defaults to 2 in order to match xterm.  We recognize either
@@ -4982,11 +4903,7 @@ x_create_tip_frame (dpyinfo, parms, text)
    the display in *ROOT_X, and *ROOT_Y.  */
 
 static void
-compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
-     struct frame *f;
-     Lisp_Object parms, dx, dy;
-     int width, height;
-     int *root_x, *root_y;
+compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object dy, int width, int height, int *root_x, int *root_y)
 {
   Lisp_Object left, top;
   int win_x, win_y;
@@ -5063,8 +4980,7 @@ DY added (default is -10).
 
 A tooltip's maximum size is specified by `x-max-tooltip-size'.
 Text larger than the specified size is clipped.  */)
-     (string, frame, parms, timeout, dx, dy)
-     Lisp_Object string, frame, parms, timeout, dx, dy;
+  (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
 {
   struct frame *f;
   struct window *w;
@@ -5188,7 +5104,7 @@ Text larger than the specified size is clipped.  */)
   clear_glyph_matrix (w->desired_matrix);
   clear_glyph_matrix (w->current_matrix);
   SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
-  try_window (FRAME_ROOT_WINDOW (f), pos, 0);
+  try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
 
   /* Compute width and height of the tooltip.  */
   width = height = 0;
@@ -5205,15 +5121,15 @@ Text larger than the specified size is clipped.  */)
       /* Let the row go over the full width of the frame.  */
       row->full_width_p = 1;
 
+      row_width = row->pixel_width;
       /* There's a glyph at the end of rows that is used to place
         the cursor there.  Don't include the width of this glyph.  */
       if (row->used[TEXT_AREA])
        {
          last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
-         row_width = row->pixel_width - last->pixel_width;
+         if (INTEGERP (last->object))
+           row_width -= last->pixel_width;
        }
-      else
-       row_width = row->pixel_width;
 
       height += row->height;
       width = max (width, row_width);
@@ -5255,7 +5171,7 @@ Text larger than the specified size is clipped.  */)
 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
        doc: /* Hide the current tooltip window, if there is any.
 Value is t if tooltip was open, nil otherwise.  */)
-     ()
+  (void)
 {
   int count;
   Lisp_Object deleted, frame, timer;
@@ -5289,7 +5205,7 @@ Value is t if tooltip was open, nil otherwise.  */)
       {
        struct frame *f = SELECTED_FRAME ();
        Widget w = f->output_data.x->menubar_widget;
-       extern void xlwmenu_redisplay P_ ((Widget));
+        extern void xlwmenu_redisplay (Widget);
 
        if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
            && w != NULL)
@@ -5316,7 +5232,7 @@ DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog,
        Sx_uses_old_gtk_dialog,
        0, 0, 0,
        doc: /* Return t if the old Gtk+ file selection dialog is used.  */)
-     ()
+  (void)
 {
 #ifdef USE_GTK
   extern int use_dialog_box;
@@ -5383,8 +5299,7 @@ DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
 Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
 selection box, if specified.  If MUSTMATCH is non-nil, the returned file
 or directory must exist.  ONLY-DIR-P is ignored."  */)
-  (prompt, dir, default_filename, mustmatch, only_dir_p)
-     Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
+  (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
 {
   int result;
   struct frame *f = SELECTED_FRAME ();
@@ -5542,8 +5457,7 @@ or directory must exist.  ONLY-DIR-P is ignored."  */)
 #ifdef USE_GTK
 
 static Lisp_Object
-clean_up_dialog (arg)
-     Lisp_Object arg;
+clean_up_dialog (Lisp_Object arg)
 {
   x_menu_set_in_use (0);
 
@@ -5556,8 +5470,7 @@ Use a file selection dialog.  Select DEFAULT-FILENAME in the dialog's file
 selection box, if specified.  If MUSTMATCH is non-nil, the returned file
 or directory must exist.  If ONLY-DIR-P is non-nil, the user can only select
 directories.  */)
-  (prompt, dir, default_filename, mustmatch, only_dir_p)
-     Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
+  (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
 {
   FRAME_PTR f = SELECTED_FRAME ();
   char *fn;
@@ -5618,8 +5531,7 @@ DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
 Return a GTK-style font string corresponding to the selection.
 
 If FRAME is omitted or nil, it defaults to the selected frame. */)
-  (frame, ignored)
-     Lisp_Object frame, ignored;
+  (Lisp_Object frame, Lisp_Object ignored)
 {
   FRAME_PTR f = check_x_frame (frame);
   char *name;
@@ -5707,8 +5619,7 @@ FRAME nil means use the selected frame.
 Value is t if we know that both keys are present, and are mapped to the
 usual X keysyms.  Value is `lambda' if we cannot determine if both keys are
 present and mapped to the usual X keysyms.  */)
-     (frame)
-     Lisp_Object frame;
+  (Lisp_Object frame)
 {
 #ifdef HAVE_XKBGETKEYBOARD
   XkbDescPtr kb;
@@ -5769,9 +5680,9 @@ present and mapped to the usual X keysyms.  */)
              /* The XKB symbolic key names can be seen most easily in
                 the PS file generated by `xkbprint -label name
                 $DISPLAY'.  */
-             if (bcmp ("DELE", kb->names->keys[i].name, 4) == 0)
+             if (memcmp ("DELE", kb->names->keys[i].name, 4) == 0)
                delete_keycode = i;
-             else if (bcmp ("BKSP", kb->names->keys[i].name, 4) == 0)
+             else if (memcmp ("BKSP", kb->names->keys[i].name, 4) == 0)
                backspace_keycode = i;
            }
 
@@ -5839,7 +5750,7 @@ frame_parm_handler x_frame_parm_handlers[] =
 };
 
 void
-syms_of_xfns ()
+syms_of_xfns (void)
 {
   /* This is zero if not using X windows.  */
   x_in_use = 0;