Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / term / x-win.el
index 593df58..8a2b01c 100644 (file)
@@ -1,7 +1,7 @@
 ;;; x-win.el --- parse relevant switches and set up for X  -*-coding: iso-2022-7bit;-*-
 
-;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;;   2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 ;; Author: FSF
 ;; Keywords: terminals, i18n
 ;; system and process X-specific command line parameters before
 ;; creating the first X frame.
 
-;; Note that contrary to previous Emacs versions, the act of loading
-;; this file should not have the side effect of initializing the
-;; window system or processing command line arguments (this file is
-;; now loaded in loadup.el).  See the variables
-;; `handle-args-function-alist' and
+;; Beginning in Emacs 23, the act of loading this file should not have
+;; the side effect of initializing the window system or processing
+;; command line arguments (this file is now loaded in loadup.el).  See
+;; the variables `handle-args-function-alist' and
 ;; `window-system-initialization-alist' for more details.
 
 ;; startup.el will then examine startup files, and eventually call the hooks
 (defvar x-session-id)
 (defvar x-session-previous-id)
 
-(defvar x-command-line-resources nil)
-
-;; Handler for switches of the form "-switch value" or "-switch".
-(defun x-handle-switch (switch)
-  (let ((aelt (assoc switch command-line-x-option-alist)))
-    (if aelt
-       (let ((param (nth 3 aelt))
-             (value (nth 4 aelt)))
-         (if value
-             (setq default-frame-alist
-                   (cons (cons param value)
-                         default-frame-alist))
-           (setq default-frame-alist
-                 (cons (cons param
-                             (car x-invocation-args))
-                       default-frame-alist)
-                 x-invocation-args (cdr x-invocation-args)))))))
-
-;; Handler for switches of the form "-switch n"
-(defun x-handle-numeric-switch (switch)
-  (let ((aelt (assoc switch command-line-x-option-alist)))
-    (if aelt
-       (let ((param (nth 3 aelt)))
-         (setq default-frame-alist
-               (cons (cons param
-                           (string-to-number (car x-invocation-args)))
-                     default-frame-alist)
-               x-invocation-args
-               (cdr x-invocation-args))))))
-
-;; Handle options that apply to initial frame only
-(defun x-handle-initial-switch (switch)
-  (let ((aelt (assoc switch command-line-x-option-alist)))
-    (if aelt
-       (let ((param (nth 3 aelt))
-             (value (nth 4 aelt)))
-         (if value
-             (setq initial-frame-alist
-                   (cons (cons param value)
-                         initial-frame-alist))
-           (setq initial-frame-alist
-                 (cons (cons param
-                             (car x-invocation-args))
-                       initial-frame-alist)
-                 x-invocation-args (cdr x-invocation-args)))))))
-
 (defun x-handle-no-bitmap-icon (switch)
   (setq default-frame-alist (cons '(icon-type) default-frame-alist)))
 
-;; Make -iconic apply only to the initial frame!
-(defun x-handle-iconic (switch)
-  (setq initial-frame-alist
-       (cons '(visibility . icon) initial-frame-alist)))
-
-;; Handle the -xrm option.
-(defun x-handle-xrm-switch (switch)
-  (unless (consp x-invocation-args)
-    (error "%s: missing argument to `%s' option" (invocation-name) switch))
-  (setq x-command-line-resources
-       (if (null x-command-line-resources)
-           (car x-invocation-args)
-         (concat x-command-line-resources "\n" (car x-invocation-args))))
-  (setq x-invocation-args (cdr x-invocation-args)))
-
-;; Handle the geometry option
-(defun x-handle-geometry (switch)
-  (let* ((geo (x-parse-geometry (car x-invocation-args)))
-        (left (assq 'left geo))
-        (top (assq 'top geo))
-        (height (assq 'height geo))
-        (width (assq 'width geo)))
-    (if (or height width)
-       (setq default-frame-alist
-             (append default-frame-alist
-                     '((user-size . t))
-                     (if height (list height))
-                     (if width (list width)))
-             initial-frame-alist
-             (append initial-frame-alist
-                     '((user-size . t))
-                     (if height (list height))
-                     (if width (list width)))))
-    (if (or left top)
-       (setq initial-frame-alist
-             (append initial-frame-alist
-                     '((user-position . t))
-                     (if left (list left))
-                     (if top (list top)))))
-    (setq x-invocation-args (cdr x-invocation-args))))
-
-;; Handle the -name option.  Set the variable x-resource-name
-;; to the option's operand; set the name of
-;; the initial frame, too.
-(defun x-handle-name-switch (switch)
-  (or (consp x-invocation-args)
-      (error "%s: missing argument to `%s' option" (invocation-name) switch))
-  (setq x-resource-name (car x-invocation-args)
-       x-invocation-args (cdr x-invocation-args))
-  (setq initial-frame-alist (cons (cons 'name x-resource-name)
-                                 initial-frame-alist)))
-
 ;; Handle the --parent-id option.
 (defun x-handle-parent-id (switch)
   (or (consp x-invocation-args)
                              initial-frame-alist)
         x-invocation-args (cdr x-invocation-args)))
 
-(defvar x-display-name nil
-  "The name of the X display on which Emacs was started.
-
-For the X display name of individual frames, see the `display'
-frame parameter.")
-
-(defun x-handle-display (switch)
-  "Handle -display DISPLAY option."
-  (setq x-display-name (car x-invocation-args)
-       x-invocation-args (cdr x-invocation-args))
-  ;; Make subshell programs see the same DISPLAY value Emacs really uses.
-  ;; Note that this isn't completely correct, since Emacs can use
-  ;; multiple displays.  However, there is no way to tell an already
-  ;; running subshell which display the user is currently typing on.
-  (setenv "DISPLAY" x-display-name))
-
-(defun x-handle-args (args)
-  "Process the X-related command line options in ARGS.
-This is done before the user's startup file is loaded.  They are copied to
-`x-invocation-args', from which the X-related things are extracted, first
-the switch (e.g., \"-fg\") in the following code, and possible values
-\(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
-This function returns ARGS minus the arguments that have been processed."
-  ;; We use ARGS to accumulate the args that we don't handle here, to return.
-  (setq x-invocation-args args
-       args nil)
-  (while (and x-invocation-args
-             (not (equal (car x-invocation-args) "--")))
-    (let* ((this-switch (car x-invocation-args))
-          (orig-this-switch this-switch)
-          completion argval aelt handler)
-      (setq x-invocation-args (cdr x-invocation-args))
-      ;; Check for long options with attached arguments
-      ;; and separate out the attached option argument into argval.
-      (if (string-match "^--[^=]*=" this-switch)
-         (setq argval (substring this-switch (match-end 0))
-               this-switch (substring this-switch 0 (1- (match-end 0)))))
-      ;; Complete names of long options.
-      (if (string-match "^--" this-switch)
-         (progn
-           (setq completion (try-completion this-switch command-line-x-option-alist))
-           (if (eq completion t)
-               ;; Exact match for long option.
-               nil
-             (if (stringp completion)
-                 (let ((elt (assoc completion command-line-x-option-alist)))
-                   ;; Check for abbreviated long option.
-                   (or elt
-                       (error "Option `%s' is ambiguous" this-switch))
-                   (setq this-switch completion))))))
-      (setq aelt (assoc this-switch command-line-x-option-alist))
-      (if aelt (setq handler (nth 2 aelt)))
-      (if handler
-         (if argval
-             (let ((x-invocation-args
-                    (cons argval x-invocation-args)))
-               (funcall handler this-switch))
-           (funcall handler this-switch))
-       (setq args (cons orig-this-switch args)))))
-  (nconc (nreverse args) x-invocation-args))
-
 ;; Handle the --smid switch.  This is used by the session manager
 ;; to give us back our session id we had on the previous run.
 (defun x-handle-smid (switch)
@@ -293,9 +133,9 @@ When a session manager tells Emacs that the window system is shutting
 down, this function is called.  It calls the functions in the hook
 `emacs-save-session-functions'.  Functions are called with the current
 buffer set to a temporary buffer.  Functions should use `insert' to insert
-lisp code to save the session state.  The buffer is saved
-in a file in the home directory of the user running Emacs.  The file
-is evaluated when Emacs is restarted by the session manager.
+lisp code to save the session state.  The buffer is saved in a file in the
+home directory of the user running Emacs.  The file is evaluated when
+Emacs is restarted by the session manager.
 
 If any of the functions returns non-nil, no more functions are called
 and this function returns non-nil.  This will inform the session manager
@@ -410,108 +250,12 @@ exists."
 (defconst x-pointer-watch 150)
 (defconst x-pointer-xterm 152)
 (defconst x-pointer-invisible 255)
+
 \f
-;;
-;; Available colors
-;;
-;; The ordering of the colors is chosen for the user's convenience in
-;; `list-colors-display', which displays the reverse of this list.
-;; Roughly speaking, `list-colors-display' orders by (i) named shades
-;; of grey with hue 0.0, sorted by value (ii) named colors with
-;; saturation 1.0, sorted by hue, (iii) named non-white colors with
-;; saturation less than 1.0, sorted by hue, (iv) other named shades of
-;; white, (v) numbered colors sorted by hue, and (vi) numbered shades
-;; of grey.
-
-(defvar x-colors
-  '("gray100" "gray99" "gray98" "gray97" "gray96" "gray95" "gray94" "gray93" "gray92"
-    "gray91" "gray90" "gray89" "gray88" "gray87" "gray86" "gray85" "gray84" "gray83"
-    "gray82" "gray81" "gray80" "gray79" "gray78" "gray77" "gray76" "gray75" "gray74"
-    "gray73" "gray72" "gray71" "gray70" "gray69" "gray68" "gray67" "gray66" "gray65"
-    "gray64" "gray63" "gray62" "gray61" "gray60" "gray59" "gray58" "gray57" "gray56"
-    "gray55" "gray54" "gray53" "gray52" "gray51" "gray50" "gray49" "gray48" "gray47"
-    "gray46" "gray45" "gray44" "gray43" "gray42" "gray41" "gray40" "gray39" "gray38"
-    "gray37" "gray36" "gray35" "gray34" "gray33" "gray32" "gray31" "gray30" "gray29"
-    "gray28" "gray27" "gray26" "gray25" "gray24" "gray23" "gray22" "gray21" "gray20"
-    "gray19" "gray18" "gray17" "gray16" "gray15" "gray14" "gray13" "gray12" "gray11"
-    "gray10" "gray9" "gray8" "gray7" "gray6" "gray5" "gray4" "gray3" "gray2" "gray1"
-    "gray0" "LightPink1" "LightPink2" "LightPink3" "LightPink4" "pink1" "pink2" "pink3"
-    "pink4" "PaleVioletRed1" "PaleVioletRed2" "PaleVioletRed3" "PaleVioletRed4"
-    "LavenderBlush1" "LavenderBlush2" "LavenderBlush3" "LavenderBlush4" "VioletRed1"
-    "VioletRed2" "VioletRed3" "VioletRed4" "HotPink1" "HotPink2" "HotPink3" "HotPink4"
-    "DeepPink1" "DeepPink2" "DeepPink3" "DeepPink4" "maroon1" "maroon2" "maroon3"
-    "maroon4" "orchid1" "orchid2" "orchid3" "orchid4" "plum1" "plum2" "plum3" "plum4"
-    "thistle1" "thistle2" "thistle3" "thistle4" "MediumOrchid1" "MediumOrchid2"
-    "MediumOrchid3" "MediumOrchid4" "DarkOrchid1" "DarkOrchid2" "DarkOrchid3"
-    "DarkOrchid4" "purple1" "purple2" "purple3" "purple4" "MediumPurple1"
-    "MediumPurple2" "MediumPurple3" "MediumPurple4" "SlateBlue1" "SlateBlue2"
-    "SlateBlue3" "SlateBlue4" "RoyalBlue1" "RoyalBlue2" "RoyalBlue3" "RoyalBlue4"
-    "LightSteelBlue1" "LightSteelBlue2" "LightSteelBlue3" "LightSteelBlue4" "SlateGray1"
-    "SlateGray2" "SlateGray3" "SlateGray4" "DodgerBlue1" "DodgerBlue2" "DodgerBlue3"
-    "DodgerBlue4" "SteelBlue1" "SteelBlue2" "SteelBlue3" "SteelBlue4" "SkyBlue1"
-    "SkyBlue2" "SkyBlue3" "SkyBlue4" "LightSkyBlue1" "LightSkyBlue2" "LightSkyBlue3"
-    "LightSkyBlue4" "LightBlue1" "LightBlue2" "LightBlue3" "LightBlue4" "CadetBlue1"
-    "CadetBlue2" "CadetBlue3" "CadetBlue4" "azure1" "azure2" "azure3" "azure4"
-    "LightCyan1" "LightCyan2" "LightCyan3" "LightCyan4" "PaleTurquoise1"
-    "PaleTurquoise2" "PaleTurquoise3" "PaleTurquoise4" "DarkSlateGray1" "DarkSlateGray2"
-    "DarkSlateGray3" "DarkSlateGray4" "aquamarine1" "aquamarine2" "aquamarine3"
-    "aquamarine4" "SeaGreen1" "SeaGreen2" "SeaGreen3" "SeaGreen4" "honeydew1"
-    "honeydew2" "honeydew3" "honeydew4" "DarkSeaGreen1" "DarkSeaGreen2" "DarkSeaGreen3"
-    "DarkSeaGreen4" "PaleGreen1" "PaleGreen2" "PaleGreen3" "PaleGreen4"
-    "DarkOliveGreen1" "DarkOliveGreen2" "DarkOliveGreen3" "DarkOliveGreen4" "OliveDrab1"
-    "OliveDrab2" "OliveDrab3" "OliveDrab4" "ivory1" "ivory2" "ivory3" "ivory4"
-    "LightYellow1" "LightYellow2" "LightYellow3" "LightYellow4" "khaki1" "khaki2"
-    "khaki3" "khaki4" "LemonChiffon1" "LemonChiffon2" "LemonChiffon3" "LemonChiffon4"
-    "LightGoldenrod1" "LightGoldenrod2" "LightGoldenrod3" "LightGoldenrod4" "cornsilk1"
-    "cornsilk2" "cornsilk3" "cornsilk4" "goldenrod1" "goldenrod2" "goldenrod3"
-    "goldenrod4" "DarkGoldenrod1" "DarkGoldenrod2" "DarkGoldenrod3" "DarkGoldenrod4"
-    "wheat1" "wheat2" "wheat3" "wheat4" "NavajoWhite1" "NavajoWhite2" "NavajoWhite3"
-    "NavajoWhite4" "burlywood1" "burlywood2" "burlywood3" "burlywood4" "AntiqueWhite1"
-    "AntiqueWhite2" "AntiqueWhite3" "AntiqueWhite4" "bisque1" "bisque2" "bisque3"
-    "bisque4" "tan1" "tan2" "tan3" "tan4" "PeachPuff1" "PeachPuff2" "PeachPuff3"
-    "PeachPuff4" "seashell1" "seashell2" "seashell3" "seashell4" "chocolate1"
-    "chocolate2" "chocolate3" "chocolate4" "sienna1" "sienna2" "sienna3" "sienna4"
-    "LightSalmon1" "LightSalmon2" "LightSalmon3" "LightSalmon4" "salmon1" "salmon2"
-    "salmon3" "salmon4" "coral1" "coral2" "coral3" "coral4" "tomato1" "tomato2"
-    "tomato3" "tomato4" "MistyRose1" "MistyRose2" "MistyRose3" "MistyRose4" "snow1"
-    "snow2" "snow3" "snow4" "RosyBrown1" "RosyBrown2" "RosyBrown3" "RosyBrown4"
-    "IndianRed1" "IndianRed2" "IndianRed3" "IndianRed4" "firebrick1" "firebrick2"
-    "firebrick3" "firebrick4" "brown1" "brown2" "brown3" "brown4" "magenta1" "magenta2"
-    "magenta3" "magenta4" "blue1" "blue2" "blue3" "blue4" "DeepSkyBlue1" "DeepSkyBlue2"
-    "DeepSkyBlue3" "DeepSkyBlue4" "turquoise1" "turquoise2" "turquoise3" "turquoise4"
-    "cyan1" "cyan2" "cyan3" "cyan4" "SpringGreen1" "SpringGreen2" "SpringGreen3"
-    "SpringGreen4" "green1" "green2" "green3" "green4" "chartreuse1" "chartreuse2"
-    "chartreuse3" "chartreuse4" "yellow1" "yellow2" "yellow3" "yellow4" "gold1" "gold2"
-    "gold3" "gold4" "orange1" "orange2" "orange3" "orange4" "DarkOrange1" "DarkOrange2"
-    "DarkOrange3" "DarkOrange4" "OrangeRed1" "OrangeRed2" "OrangeRed3" "OrangeRed4"
-    "red1" "red2" "red3" "red4" "lavender blush" "ghost white" "lavender" "alice blue"
-    "azure" "light cyan" "mint cream" "honeydew" "ivory" "light goldenrod yellow"
-    "light yellow" "beige" "floral white" "old lace" "blanched almond" "moccasin"
-    "papaya whip" "bisque" "antique white" "linen" "peach puff" "seashell" "misty rose"
-    "snow" "light pink" "pink" "hot pink" "deep pink" "maroon" "pale violet red"
-    "violet red" "medium violet red" "violet" "plum" "thistle" "orchid" "medium orchid"
-    "dark orchid" "purple" "blue violet" "medium purple" "light slate blue"
-    "medium slate blue" "slate blue" "dark slate blue" "midnight blue" "navy"
-    "dark blue" "light steel blue" "cornflower blue" "dodger blue" "royal blue"
-    "light slate gray" "slate gray" "dark slate gray" "steel blue" "cadet blue"
-    "light sky blue" "sky blue" "light blue" "powder blue" "pale turquoise" "turquoise"
-    "medium turquoise" "dark cyan" "aquamarine" "medium aquamarine" "light sea green"
-    "medium sea green" "sea green" "dark sea green" "pale green" "lime green"
-    "forest green" "light green" "green yellow" "yellow green" "olive drab"
-    "dark olive green" "lemon chiffon" "khaki" "dark khaki" "cornsilk"
-    "pale goldenrod" "light goldenrod" "goldenrod" "dark goldenrod" "wheat"
-    "navajo white" "tan" "burlywood" "sandy brown" "peru" "chocolate" "saddle brown"
-    "sienna" "rosy brown" "dark salmon" "coral" "tomato" "light salmon" "salmon"
-    "light coral" "indian red" "firebrick" "brown" "dark red" "magenta"
-    "dark magenta" "dark violet" "medium blue" "blue" "deep sky blue"
-    "cyan" "medium spring green" "spring green" "green" "lawn green" "chartreuse"
-    "yellow" "gold" "orange" "dark orange" "orange red" "red" "white" "white smoke"
-    "gainsboro" "light grey" "gray" "dark grey" "dim gray" "black" )
-  "The list of X colors from the `rgb.txt' file.
-XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
+(defvar x-colors)
 
 (defun xw-defined-colors (&optional frame)
-  "Internal function called by `defined-colors', which see."
+  "Internal function called by `defined-colors'."
   (or frame (setq frame (selected-frame)))
   (let ((all-colors x-colors)
        (this-color nil)
@@ -528,13 +272,6 @@ XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
 (defvar x-alternatives-map
   (let ((map (make-sparse-keymap)))
     ;; Map certain keypad keys into ASCII characters that people usually expect.
-    (define-key map [backspace] [127])
-    (define-key map [delete] [127])
-    (define-key map [tab] [?\t])
-    (define-key map [linefeed] [?\n])
-    (define-key map [clear] [?\C-l])
-    (define-key map [return] [?\C-m])
-    (define-key map [escape] [?\e])
     (define-key map [M-backspace] [?\M-\d])
     (define-key map [M-delete] [?\M-\d])
     (define-key map [M-tab] [?\M-\t])
@@ -548,7 +285,7 @@ XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
   "Keymap of possible alternative meanings for some keys.")
 
 (defun x-setup-function-keys (frame)
-  "Set up `function-key-map' on FRAME for the X window system."
+  "Set up `function-key-map' on the graphical frame FRAME."
   ;; Don't do this twice on the same display, or it would break
   ;; normal-erase-is-backspace-mode.
   (unless (terminal-parameter frame 'x-setup-function-keys)
@@ -558,17 +295,6 @@ XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
         (set-keymap-parent map (keymap-parent local-function-key-map))
         (set-keymap-parent local-function-key-map map)))
     (set-terminal-parameter frame 'x-setup-function-keys t)))
-
-;; These tell read-char how to convert
-;; these special chars to ASCII.
-(put 'backspace 'ascii-character 127)
-(put 'delete 'ascii-character 127)
-(put 'tab 'ascii-character ?\t)
-(put 'linefeed 'ascii-character ?\n)
-(put 'clear 'ascii-character 12)
-(put 'return 'ascii-character 13)
-(put 'escape 'ascii-character ?\e)
-
 \f
 ;;;; Keysyms
 
@@ -1471,7 +1197,7 @@ as returned by `x-server-vendor'."
 ;; We keep track of the last text selected here, so we can check the
 ;; current selection against it, and avoid passing back our own text
 ;; from x-cut-buffer-or-selection-value.  We track all three
-;; seperately in case another X application only sets one of them
+;; separately in case another X application only sets one of them
 ;; (say the cut buffer) we aren't fooled by the PRIMARY or
 ;; CLIPBOARD selection staying the same.
 (defvar x-last-selected-text-clipboard nil
@@ -1495,7 +1221,11 @@ It is said that overlarge strings are slow to put into the cut buffer.")
 
 (defcustom x-select-enable-clipboard nil
   "Non-nil means cutting and pasting uses the clipboard.
-This is in addition to, but in preference to, the primary selection."
+This is in addition to, but in preference to, the primary selection.
+
+On MS-Windows, this is non-nil by default, since Windows does not
+support other types of selections.  \(The primary selection that is
+set by Emacs is not accessible to other programs on Windows.\)"
   :type 'boolean
   :group 'killing)
 
@@ -1505,11 +1235,19 @@ This is in addition to, but in preference to, the primary selection."
   :group 'killing)
 
 (defun x-select-text (text &optional push)
-  "Make TEXT, a string, the primary X selection.
-Also, set the value of X cut buffer 0, for backward compatibility
-with older X applications.
-gildea@stop.mail-abuse.org says it's not desirable to put kills
-in the clipboard."
+  "Select TEXT, a string, according to the window system.
+
+On X, put TEXT in the primary X selection.  For backward
+compatibility with older X applications, set the value of X cut
+buffer 0 as well, and if the optional argument PUSH is non-nil,
+rotate the cut buffers.  If `x-select-enable-clipboard' is
+non-nil, copy the text to the X clipboard as well.
+
+On Windows, make TEXT the current selection.  If
+`x-select-enable-clipboard' is non-nil, copy the text to the
+clipboard as well.  The argument PUSH is ignored.
+
+On Nextstep, put TEXT in the pasteboard; PUSH is ignored."
   ;; With multi-tty, this function may be called from a tty frame.
   (when (eq (framep (selected-frame)) 'x)
     ;; Don't send the cut buffer too much text.
@@ -1548,7 +1286,7 @@ The value nil is the same as this list:
 ")
 
 ;; Get a selection value of type TYPE by calling x-get-selection with
-;; an appropiate DATA-TYPE argument decided by `x-select-request-type'.
+;; an appropriate DATA-TYPE argument decided by `x-select-request-type'.
 ;; The return value is already decoded.  If x-get-selection causes an
 ;; error, this function return nil.
 
@@ -1684,21 +1422,37 @@ The value nil is the same as this list:
        (kill-new clipboard-text))
     (yank)))
 
+(declare-function accelerate-menu "xmenu.c" (&optional frame) t)
+
 (defun x-menu-bar-open (&optional frame)
-  "Open the menu bar if `menu-bar-mode' is on. otherwise call `tmm-menubar'."
+  "Open the menu bar if `menu-bar-mode' is on, otherwise call `tmm-menubar'."
   (interactive "i")
-  (if menu-bar-mode (accelerate-menu frame)
+  (if (and menu-bar-mode
+          (fboundp 'accelerate-menu))
+      (accelerate-menu frame)
     (tmm-menubar)))
 
 \f
 ;;; Window system initialization.
 
 (defun x-win-suspend-error ()
-  (error "Suspending an Emacs running under X makes no sense"))
+  ;; Don't allow suspending if any of the frames are X frames.
+  (if (memq 'x (mapcar 'window-system (frame-list)))
+      (error "Cannot suspend Emacs while running under X")))
 
 (defvar x-initialized nil
   "Non-nil if the X window system has been initialized.")
 
+(declare-function x-open-connection "xfns.c"
+                 (display &optional xrm-string must-succeed))
+(declare-function x-server-max-request-size "xfns.c" (&optional terminal))
+(declare-function x-get-resource "frame.c"
+                 (attribute class &optional component subclass))
+(declare-function x-parse-geometry "frame.c" (string))
+(defvar x-resource-name)
+(defvar x-display-name)
+(defvar x-command-line-resources)
+
 (defun x-initialize-window-system ()
   "Initialize Emacs for X frames and open the first connection to an X server."
   ;; Make sure we have a valid resource name.
@@ -1722,11 +1476,16 @@ The value nil is the same as this list:
   (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
                              x-cut-buffer-max))
 
-  ;; Setup the default fontset.
-  (setup-default-fontset)
+  ;; Create the default fontset.
+  (create-default-fontset)
 
   ;; Create the standard fontset.
-  (create-fontset-from-fontset-spec standard-fontset-spec t)
+  (condition-case err
+       (create-fontset-from-fontset-spec standard-fontset-spec t)
+    (error (display-warning
+           'initialization
+           (format "Creation of the standard fontset failed: %s" err)
+           :error)))
 
   ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
   (create-fontset-from-x-resource)
@@ -1781,6 +1540,12 @@ The value nil is the same as this list:
   ;; Don't let Emacs suspend under X.
   (add-hook 'suspend-hook 'x-win-suspend-error)
 
+  ;; During initialization, we defer sending size hints to the window
+  ;; manager, because that can induce a race condition:
+  ;; http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00033.html
+  ;; Send the size hints once initialization is done.
+  (add-hook 'after-init-hook 'x-wm-set-size-hint)
+
   ;; Turn off window-splitting optimization; X is usually fast enough
   ;; that this is only annoying.
   (setq split-window-keep-point t)
@@ -1792,9 +1557,6 @@ The value nil is the same as this list:
   ;; (if (featurep 'motif)
   ;;     (global-set-key [f10] 'ignore))
 
-  ;; Turn on support for mouse wheels.
-  (mouse-wheel-mode 1)
-
   ;; Enable CLIPBOARD copy/paste through menu bar commands.
   (menu-bar-enable-clipboard)
 
@@ -1816,6 +1578,8 @@ The value nil is the same as this list:
 (define-key special-event-map [drag-n-drop] 'x-dnd-handle-drag-n-drop-event)
 
 (defcustom x-gtk-stock-map
+  (mapcar (lambda (arg)
+           (cons (purecopy (car arg)) (purecopy (cdr arg))))
   '(
     ("etc/images/new" . "gtk-new")
     ("etc/images/open" . "gtk-open")
@@ -1872,10 +1636,14 @@ The value nil is the same as this list:
     ("images/mail/save-draft" . "gtk-mail-handling")
     ("images/mail/send" . "gtk-mail-send")
     ("images/mail/spam" . "gtk-spam")
+    ;; Used for GDB Graphical Interface
+    ("images/gud/break" . "gtk-no")
+    ("images/gud/recstart" . "gtk-media-record")
+    ("images/gud/recstop" . "gtk-media-stop")
     ;; No themed versions available:
     ;; mail/preview (combining stock_mail and stock_zoom)
     ;; mail/save    (combining stock_mail, stock_save and stock_convert)
-    )
+    ))
   "How icons for tool bars are mapped to Gtk+ stock items.
 Emacs must be compiled with the Gtk+ toolkit for this to have any effect.
 A value that begins with n: denotes a named icon instead of a stock icon."
@@ -1886,7 +1654,7 @@ A value that begins with n: denotes a named icon instead of a stock icon."
   :group 'x)
 
 (defcustom icon-map-list '(x-gtk-stock-map)
-  "A list of alists that maps icon file names to stock/named icons.
+  "A list of alists that map icon file names to stock/named icons.
 The alists are searched in the order they appear.  The first match is used.
 The keys in the alists are file names without extension and with two directory
 components.  For example, to map /usr/share/emacs/22.1.1/etc/images/open.xpm
@@ -1909,20 +1677,31 @@ If you don't want stock icons, set the variable to nil."
                                       (string :tag "Stock/named")))))
   :group 'x)
 
+(defconst x-gtk-stock-cache (make-hash-table :weakness t :test 'equal))
+
 (defun x-gtk-map-stock (file)
-  "Map icon with file name FILE to a Gtk+ stock name, using `x-gtk-stock-map'."
-  (if (stringp file)
-      (let* ((file-sans (file-name-sans-extension file))
-            (key (and (string-match "/\\([^/]+/[^/]+/[^/]+$\\)" file-sans)
-                      (match-string 1 file-sans)))
-            (value))
-       (mapc (lambda (elem)
-               (let ((assoc (if (symbolp elem) (symbol-value elem) elem)))
-                 (or value (setq value (assoc-string (or key file-sans)
-                                                     assoc)))))
-             icon-map-list)
-       (and value (cdr value)))
-    nil))
+  "Map icon with file name FILE to a Gtk+ stock name.
+This uses `icon-map-list' to map icon file names to stock icon names."
+  (when (stringp file)
+    (or (gethash file x-gtk-stock-cache)
+       (puthash
+        file
+        (save-match-data
+          (let* ((file-sans (file-name-sans-extension file))
+                 (key (and (string-match "/\\([^/]+/[^/]+/[^/]+$\\)"
+                                         file-sans)
+                           (match-string 1 file-sans)))
+                 (icon-map icon-map-list)
+                 elem value)
+            (while (and (null value) icon-map)
+              (setq elem (car icon-map)
+                    value (assoc-string (or key file-sans)
+                                        (if (symbolp elem)
+                                            (symbol-value elem)
+                                          elem))
+                    icon-map (cdr icon-map)))
+            (and value (cdr value))))
+        x-gtk-stock-cache))))
 
 (provide 'x-win)