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