Merge changes from emacs-23 branch.
[bpt/emacs.git] / lisp / term / common-win.el
1 ;;; common-win.el --- common part of handling window systems
2
3 ;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: terminals
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28
29 (defvar x-invocation-args)
30
31 (defvar x-command-line-resources nil)
32
33 ;; Handler for switches of the form "-switch value" or "-switch".
34 (defun x-handle-switch (switch)
35 (let ((aelt (assoc switch command-line-x-option-alist)))
36 (if aelt
37 (let ((param (nth 3 aelt))
38 (value (nth 4 aelt)))
39 (if value
40 (setq default-frame-alist
41 (cons (cons param value)
42 default-frame-alist))
43 (setq default-frame-alist
44 (cons (cons param
45 (car x-invocation-args))
46 default-frame-alist)
47 x-invocation-args (cdr x-invocation-args)))))))
48
49 ;; Handler for switches of the form "-switch n"
50 (defun x-handle-numeric-switch (switch)
51 (let ((aelt (assoc switch command-line-x-option-alist)))
52 (if aelt
53 (let ((param (nth 3 aelt)))
54 (setq default-frame-alist
55 (cons (cons param
56 (string-to-number (car x-invocation-args)))
57 default-frame-alist)
58 x-invocation-args
59 (cdr x-invocation-args))))))
60
61 ;; Handle options that apply to initial frame only
62 (defun x-handle-initial-switch (switch)
63 (let ((aelt (assoc switch command-line-x-option-alist)))
64 (if aelt
65 (let ((param (nth 3 aelt))
66 (value (nth 4 aelt)))
67 (if value
68 (setq initial-frame-alist
69 (cons (cons param value)
70 initial-frame-alist))
71 (setq initial-frame-alist
72 (cons (cons param
73 (car x-invocation-args))
74 initial-frame-alist)
75 x-invocation-args (cdr x-invocation-args)))))))
76
77 ;; Make -iconic apply only to the initial frame!
78 (defun x-handle-iconic (switch)
79 (setq initial-frame-alist
80 (cons '(visibility . icon) initial-frame-alist)))
81
82 ;; Handle the -xrm option.
83 (defun x-handle-xrm-switch (switch)
84 (unless (consp x-invocation-args)
85 (error "%s: missing argument to `%s' option" (invocation-name) switch))
86 (setq x-command-line-resources
87 (if (null x-command-line-resources)
88 (car x-invocation-args)
89 (concat x-command-line-resources "\n" (car x-invocation-args))))
90 (setq x-invocation-args (cdr x-invocation-args)))
91
92 (declare-function x-parse-geometry "frame.c" (string))
93
94 ;; Handle the geometry option
95 (defun x-handle-geometry (switch)
96 (let* ((geo (x-parse-geometry (car x-invocation-args)))
97 (left (assq 'left geo))
98 (top (assq 'top geo))
99 (height (assq 'height geo))
100 (width (assq 'width geo)))
101 (if (or height width)
102 (setq default-frame-alist
103 (append default-frame-alist
104 '((user-size . t))
105 (if height (list height))
106 (if width (list width)))
107 initial-frame-alist
108 (append initial-frame-alist
109 '((user-size . t))
110 (if height (list height))
111 (if width (list width)))))
112 (if (or left top)
113 (setq initial-frame-alist
114 (append initial-frame-alist
115 '((user-position . t))
116 (if left (list left))
117 (if top (list top)))))
118 (setq x-invocation-args (cdr x-invocation-args))))
119
120 (defvar x-resource-name)
121
122 ;; Handle the -name option. Set the variable x-resource-name
123 ;; to the option's operand; set the name of
124 ;; the initial frame, too.
125 (defun x-handle-name-switch (switch)
126 (or (consp x-invocation-args)
127 (error "%s: missing argument to `%s' option" (invocation-name) switch))
128 (setq x-resource-name (car x-invocation-args)
129 x-invocation-args (cdr x-invocation-args))
130 (setq initial-frame-alist (cons (cons 'name x-resource-name)
131 initial-frame-alist)))
132
133 (defvar x-display-name nil
134 "The name of the window display on which Emacs was started.
135 On X, the display name of individual X frames is recorded in the
136 `display' frame parameter.")
137
138 (defun x-handle-display (switch)
139 "Handle -display DISPLAY option."
140 (setq x-display-name (car x-invocation-args)
141 x-invocation-args (cdr x-invocation-args))
142 ;; Make subshell programs see the same DISPLAY value Emacs really uses.
143 ;; Note that this isn't completely correct, since Emacs can use
144 ;; multiple displays. However, there is no way to tell an already
145 ;; running subshell which display the user is currently typing on.
146 (setenv "DISPLAY" x-display-name))
147
148 (defun x-handle-args (args)
149 "Process the X-related command line options in ARGS.
150 This is done before the user's startup file is loaded. They are copied to
151 `x-invocation-args', from which the X-related things are extracted, first
152 the switch (e.g., \"-fg\") in the following code, and possible values
153 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
154 This function returns ARGS minus the arguments that have been processed."
155 ;; We use ARGS to accumulate the args that we don't handle here, to return.
156 (setq x-invocation-args args
157 args nil)
158 (while (and x-invocation-args
159 (not (equal (car x-invocation-args) "--")))
160 (let* ((this-switch (car x-invocation-args))
161 (orig-this-switch this-switch)
162 completion argval aelt handler)
163 (setq x-invocation-args (cdr x-invocation-args))
164 ;; Check for long options with attached arguments
165 ;; and separate out the attached option argument into argval.
166 (if (string-match "^--[^=]*=" this-switch)
167 (setq argval (substring this-switch (match-end 0))
168 this-switch (substring this-switch 0 (1- (match-end 0)))))
169 ;; Complete names of long options.
170 (if (string-match "^--" this-switch)
171 (progn
172 (setq completion (try-completion this-switch command-line-x-option-alist))
173 (if (eq completion t)
174 ;; Exact match for long option.
175 nil
176 (if (stringp completion)
177 (let ((elt (assoc completion command-line-x-option-alist)))
178 ;; Check for abbreviated long option.
179 (or elt
180 (error "Option `%s' is ambiguous" this-switch))
181 (setq this-switch completion))))))
182 (setq aelt (assoc this-switch command-line-x-option-alist))
183 (if aelt (setq handler (nth 2 aelt)))
184 (if handler
185 (if argval
186 (let ((x-invocation-args
187 (cons argval x-invocation-args)))
188 (funcall handler this-switch))
189 (funcall handler this-switch))
190 (setq args (cons orig-this-switch args)))))
191 (nconc (nreverse args) x-invocation-args))
192
193 \f
194 ;;
195 ;; Available colors
196 ;;
197 ;; The ordering of the colors is chosen for the user's convenience in
198 ;; `list-colors-display', which displays the reverse of this list.
199 ;; Roughly speaking, `list-colors-display' orders by (i) named shades
200 ;; of grey with hue 0.0, sorted by value (ii) named colors with
201 ;; saturation 1.0, sorted by hue, (iii) named non-white colors with
202 ;; saturation less than 1.0, sorted by hue, (iv) other named shades of
203 ;; white, (v) numbered colors sorted by hue, and (vi) numbered shades
204 ;; of grey.
205
206 (defvar x-colors
207 (purecopy
208 '("gray100" "grey100" "gray99" "grey99" "gray98" "grey98" "gray97"
209 "grey97" "gray96" "grey96" "gray95" "grey95" "gray94" "grey94"
210 "gray93" "grey93" "gray92" "grey92" "gray91" "grey91" "gray90"
211 "grey90" "gray89" "grey89" "gray88" "grey88" "gray87" "grey87"
212 "gray86" "grey86" "gray85" "grey85" "gray84" "grey84" "gray83"
213 "grey83" "gray82" "grey82" "gray81" "grey81" "gray80" "grey80"
214 "gray79" "grey79" "gray78" "grey78" "gray77" "grey77" "gray76"
215 "grey76" "gray75" "grey75" "gray74" "grey74" "gray73" "grey73"
216 "gray72" "grey72" "gray71" "grey71" "gray70" "grey70" "gray69"
217 "grey69" "gray68" "grey68" "gray67" "grey67" "gray66" "grey66"
218 "gray65" "grey65" "gray64" "grey64" "gray63" "grey63" "gray62"
219 "grey62" "gray61" "grey61" "gray60" "grey60" "gray59" "grey59"
220 "gray58" "grey58" "gray57" "grey57" "gray56" "grey56" "gray55"
221 "grey55" "gray54" "grey54" "gray53" "grey53" "gray52" "grey52"
222 "gray51" "grey51" "gray50" "grey50" "gray49" "grey49" "gray48"
223 "grey48" "gray47" "grey47" "gray46" "grey46" "gray45" "grey45"
224 "gray44" "grey44" "gray43" "grey43" "gray42" "grey42" "gray41"
225 "grey41" "gray40" "grey40" "gray39" "grey39" "gray38" "grey38"
226 "gray37" "grey37" "gray36" "grey36" "gray35" "grey35" "gray34"
227 "grey34" "gray33" "grey33" "gray32" "grey32" "gray31" "grey31"
228 "gray30" "grey30" "gray29" "grey29" "gray28" "grey28" "gray27"
229 "grey27" "gray26" "grey26" "gray25" "grey25" "gray24" "grey24"
230 "gray23" "grey23" "gray22" "grey22" "gray21" "grey21" "gray20"
231 "grey20" "gray19" "grey19" "gray18" "grey18" "gray17" "grey17"
232 "gray16" "grey16" "gray15" "grey15" "gray14" "grey14" "gray13"
233 "grey13" "gray12" "grey12" "gray11" "grey11" "gray10" "grey10"
234 "gray9" "grey9" "gray8" "grey8" "gray7" "grey7" "gray6" "grey6"
235 "gray5" "grey5" "gray4" "grey4" "gray3" "grey3" "gray2" "grey2"
236 "gray1" "grey1" "gray0" "grey0"
237 "LightPink1" "LightPink2" "LightPink3" "LightPink4"
238 "pink1" "pink2" "pink3" "pink4"
239 "PaleVioletRed1" "PaleVioletRed2" "PaleVioletRed3" "PaleVioletRed4"
240 "LavenderBlush1" "LavenderBlush2" "LavenderBlush3" "LavenderBlush4"
241 "VioletRed1" "VioletRed2" "VioletRed3" "VioletRed4"
242 "HotPink1" "HotPink2" "HotPink3" "HotPink4"
243 "DeepPink1" "DeepPink2" "DeepPink3" "DeepPink4"
244 "maroon1" "maroon2" "maroon3" "maroon4"
245 "orchid1" "orchid2" "orchid3" "orchid4"
246 "plum1" "plum2" "plum3" "plum4"
247 "thistle1" "thistle2" "thistle3" "thistle4"
248 "MediumOrchid1" "MediumOrchid2" "MediumOrchid3" "MediumOrchid4"
249 "DarkOrchid1" "DarkOrchid2" "DarkOrchid3" "DarkOrchid4"
250 "purple1" "purple2" "purple3" "purple4"
251 "MediumPurple1" "MediumPurple2" "MediumPurple3" "MediumPurple4"
252 "SlateBlue1" "SlateBlue2" "SlateBlue3" "SlateBlue4"
253 "RoyalBlue1" "RoyalBlue2" "RoyalBlue3" "RoyalBlue4"
254 "LightSteelBlue1" "LightSteelBlue2" "LightSteelBlue3" "LightSteelBlue4"
255 "SlateGray1" "SlateGray2" "SlateGray3" "SlateGray4"
256 "DodgerBlue1" "DodgerBlue2" "DodgerBlue3" "DodgerBlue4"
257 "SteelBlue1" "SteelBlue2" "SteelBlue3" "SteelBlue4"
258 "SkyBlue1" "SkyBlue2" "SkyBlue3" "SkyBlue4"
259 "LightSkyBlue1" "LightSkyBlue2" "LightSkyBlue3" "LightSkyBlue4"
260 "LightBlue1" "LightBlue2" "LightBlue3" "LightBlue4"
261 "CadetBlue1" "CadetBlue2" "CadetBlue3" "CadetBlue4"
262 "azure1" "azure2" "azure3" "azure4"
263 "LightCyan1" "LightCyan2" "LightCyan3" "LightCyan4"
264 "PaleTurquoise1" "PaleTurquoise2" "PaleTurquoise3" "PaleTurquoise4"
265 "DarkSlateGray1" "DarkSlateGray2" "DarkSlateGray3" "DarkSlateGray4"
266 "aquamarine1" "aquamarine2" "aquamarine3" "aquamarine4"
267 "SeaGreen1" "SeaGreen2" "SeaGreen3" "SeaGreen4"
268 "honeydew1" "honeydew2" "honeydew3" "honeydew4"
269 "DarkSeaGreen1" "DarkSeaGreen2" "DarkSeaGreen3" "DarkSeaGreen4"
270 "PaleGreen1" "PaleGreen2" "PaleGreen3" "PaleGreen4"
271 "DarkOliveGreen1" "DarkOliveGreen2" "DarkOliveGreen3" "DarkOliveGreen4"
272 "OliveDrab1" "OliveDrab2" "OliveDrab3" "OliveDrab4"
273 "ivory1" "ivory2" "ivory3" "ivory4"
274 "LightYellow1" "LightYellow2" "LightYellow3" "LightYellow4"
275 "khaki1" "khaki2" "khaki3" "khaki4"
276 "LemonChiffon1" "LemonChiffon2" "LemonChiffon3" "LemonChiffon4"
277 "LightGoldenrod1" "LightGoldenrod2" "LightGoldenrod3" "LightGoldenrod4"
278 "cornsilk1" "cornsilk2" "cornsilk3" "cornsilk4"
279 "goldenrod1" "goldenrod2" "goldenrod3" "goldenrod4"
280 "DarkGoldenrod1" "DarkGoldenrod2" "DarkGoldenrod3" "DarkGoldenrod4"
281 "wheat1" "wheat2" "wheat3" "wheat4"
282 "NavajoWhite1" "NavajoWhite2" "NavajoWhite3" "NavajoWhite4"
283 "burlywood1" "burlywood2" "burlywood3" "burlywood4"
284 "AntiqueWhite1" "AntiqueWhite2" "AntiqueWhite3" "AntiqueWhite4"
285 "bisque1" "bisque2" "bisque3" "bisque4"
286 "tan1" "tan2" "tan3" "tan4"
287 "PeachPuff1" "PeachPuff2" "PeachPuff3" "PeachPuff4"
288 "seashell1" "seashell2" "seashell3" "seashell4"
289 "chocolate1" "chocolate2" "chocolate3" "chocolate4"
290 "sienna1" "sienna2" "sienna3" "sienna4"
291 "LightSalmon1" "LightSalmon2" "LightSalmon3" "LightSalmon4"
292 "salmon1" "salmon2" "salmon3" "salmon4"
293 "coral1" "coral2" "coral3" "coral4"
294 "tomato1" "tomato2" "tomato3" "tomato4"
295 "MistyRose1" "MistyRose2" "MistyRose3" "MistyRose4"
296 "snow1" "snow2" "snow3" "snow4"
297 "RosyBrown1" "RosyBrown2" "RosyBrown3" "RosyBrown4"
298 "IndianRed1" "IndianRed2" "IndianRed3" "IndianRed4"
299 "firebrick1" "firebrick2" "firebrick3" "firebrick4"
300 "brown1" "brown2" "brown3" "brown4"
301 "magenta1" "magenta2" "magenta3" "magenta4"
302 "blue1" "blue2" "blue3" "blue4"
303 "DeepSkyBlue1" "DeepSkyBlue2" "DeepSkyBlue3" "DeepSkyBlue4"
304 "turquoise1" "turquoise2" "turquoise3" "turquoise4"
305 "cyan1" "cyan2" "cyan3" "cyan4"
306 "SpringGreen1" "SpringGreen2" "SpringGreen3" "SpringGreen4"
307 "green1" "green2" "green3" "green4"
308 "chartreuse1" "chartreuse2" "chartreuse3" "chartreuse4"
309 "yellow1" "yellow2" "yellow3" "yellow4"
310 "gold1" "gold2" "gold3" "gold4"
311 "orange1" "orange2" "orange3" "orange4"
312 "DarkOrange1" "DarkOrange2" "DarkOrange3" "DarkOrange4"
313 "OrangeRed1" "OrangeRed2" "OrangeRed3" "OrangeRed4"
314 "red1" "red2" "red3" "red4"
315 "lavender blush" "LavenderBlush" "ghost white" "GhostWhite"
316 "lavender" "alice blue" "AliceBlue" "azure" "light cyan"
317 "LightCyan" "mint cream" "MintCream" "honeydew" "ivory"
318 "light goldenrod yellow" "LightGoldenrodYellow" "light yellow"
319 "LightYellow" "beige" "floral white" "FloralWhite" "old lace"
320 "OldLace" "blanched almond" "BlanchedAlmond" "moccasin"
321 "papaya whip" "PapayaWhip" "bisque" "antique white"
322 "AntiqueWhite" "linen" "peach puff" "PeachPuff" "seashell"
323 "misty rose" "MistyRose" "snow" "light pink" "LightPink" "pink"
324 "hot pink" "HotPink" "deep pink" "DeepPink" "maroon"
325 "pale violet red" "PaleVioletRed" "violet red" "VioletRed"
326 "medium violet red" "MediumVioletRed" "violet" "plum" "thistle"
327 "orchid" "medium orchid" "MediumOrchid" "dark orchid"
328 "DarkOrchid" "purple" "blue violet" "BlueViolet" "medium purple"
329 "MediumPurple" "light slate blue" "LightSlateBlue"
330 "medium slate blue" "MediumSlateBlue" "slate blue" "SlateBlue"
331 "dark slate blue" "DarkSlateBlue" "midnight blue" "MidnightBlue"
332 "navy" "navy blue" "NavyBlue" "dark blue" "DarkBlue"
333 "light steel blue" "LightSteelBlue" "cornflower blue"
334 "CornflowerBlue" "dodger blue" "DodgerBlue" "royal blue"
335 "RoyalBlue" "light slate gray" "light slate grey"
336 "LightSlateGray" "LightSlateGrey" "slate gray" "slate grey"
337 "SlateGray" "SlateGrey" "dark slate gray" "dark slate grey"
338 "DarkSlateGray" "DarkSlateGrey" "steel blue" "SteelBlue"
339 "cadet blue" "CadetBlue" "light sky blue" "LightSkyBlue"
340 "sky blue" "SkyBlue" "light blue" "LightBlue" "powder blue"
341 "PowderBlue" "pale turquoise" "PaleTurquoise" "turquoise"
342 "medium turquoise" "MediumTurquoise" "dark turquoise"
343 "DarkTurquoise" "dark cyan" "DarkCyan" "aquamarine"
344 "medium aquamarine" "MediumAquamarine" "light sea green"
345 "LightSeaGreen" "medium sea green" "MediumSeaGreen" "sea green"
346 "SeaGreen" "dark sea green" "DarkSeaGreen" "pale green"
347 "PaleGreen" "lime green" "LimeGreen" "dark green" "DarkGreen"
348 "forest green" "ForestGreen" "light green" "LightGreen"
349 "green yellow" "GreenYellow" "yellow green" "YellowGreen"
350 "olive drab" "OliveDrab" "dark olive green" "DarkOliveGreen"
351 "lemon chiffon" "LemonChiffon" "khaki" "dark khaki" "DarkKhaki"
352 "cornsilk" "pale goldenrod" "PaleGoldenrod" "light goldenrod"
353 "LightGoldenrod" "goldenrod" "dark goldenrod" "DarkGoldenrod"
354 "wheat" "navajo white" "NavajoWhite" "tan" "burlywood"
355 "sandy brown" "SandyBrown" "peru" "chocolate" "saddle brown"
356 "SaddleBrown" "sienna" "rosy brown" "RosyBrown" "dark salmon"
357 "DarkSalmon" "coral" "tomato" "light salmon" "LightSalmon"
358 "salmon" "light coral" "LightCoral" "indian red" "IndianRed"
359 "firebrick" "brown" "dark red" "DarkRed" "magenta"
360 "dark magenta" "DarkMagenta" "dark violet" "DarkViolet"
361 "medium blue" "MediumBlue" "blue" "deep sky blue" "DeepSkyBlue"
362 "cyan" "medium spring green" "MediumSpringGreen" "spring green"
363 "SpringGreen" "green" "lawn green" "LawnGreen" "chartreuse"
364 "yellow" "gold" "orange" "dark orange" "DarkOrange" "orange red"
365 "OrangeRed" "red" "white" "white smoke" "WhiteSmoke" "gainsboro"
366 "light gray" "light grey" "LightGray" "LightGrey" "gray" "grey"
367 "dark gray" "dark grey" "DarkGray" "DarkGrey" "dim gray"
368 "dim grey" "DimGray" "DimGrey" "black"))
369 "List of basic colors available on color displays.
370 For X, the list comes from the `rgb.txt' file,v 10.41 94/02/20.
371 For Nextstep, this is a list of non-PANTONE colors returned by
372 the operating system.")
373
374 ;; arch-tag: 2a128601-99cc-401e-9dff-0ee6a36102ef
375 ;;; common-win.el ends here