(x-invocation-args): Add defvar.
[emacs.git] / lisp / term / x-win.el
bloba0aca0814a3d530a7ace6ee5c54b5e119f2820b2
1 ;;; x-win.el --- parse switches controlling interface with X window system
2 ;; Copyright (C) 1993 Free Software Foundation, Inc.
4 ;; Author: FSF
5 ;; Keywords: terminals
7 ;;; This file is part of GNU Emacs.
8 ;;;
9 ;;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;;; it under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 2, or (at your option)
12 ;;; any later version.
13 ;;;
14 ;;; GNU Emacs is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 ;;; Commentary:
25 ;; X-win.el: this file is loaded from ../lisp/startup.el when it recognizes
26 ;; that X windows are to be used. Command line switches are parsed and those
27 ;; pertaining to X are processed and removed from the command line. The
28 ;; X display is opened and hooks are set for popping up the initial window.
30 ;; startup.el will then examine startup files, and eventually call the hooks
31 ;; which create the first window (s).
33 ;;; Code:
35 ;; These are the standard X switches from the Xt Initialize.c file of
36 ;; Release 4.
38 ;; Command line Resource Manager string
40 ;; +rv *reverseVideo
41 ;; +synchronous *synchronous
42 ;; -background *background
43 ;; -bd *borderColor
44 ;; -bg *background
45 ;; -bordercolor *borderColor
46 ;; -borderwidth .borderWidth
47 ;; -bw .borderWidth
48 ;; -display .display
49 ;; -fg *foreground
50 ;; -fn *font
51 ;; -font *font
52 ;; -foreground *foreground
53 ;; -geometry .geometry
54 ;; -i .iconType
55 ;; -itype .iconType
56 ;; -iconic .iconic
57 ;; -name .name
58 ;; -reverse *reverseVideo
59 ;; -rv *reverseVideo
60 ;; -selectionTimeout .selectionTimeout
61 ;; -synchronous *synchronous
62 ;; -xrm
64 ;; An alist of X options and the function which handles them. See
65 ;; ../startup.el.
67 (if (not (eq window-system 'x))
68 (error "Loading x-win.el but not compiled for X"))
70 (require 'frame)
71 (require 'mouse)
72 (require 'scroll-bar)
73 (require 'faces)
74 (require 'select)
75 (require 'menu-bar)
77 (defvar x-invocation-args)
79 (defvar x-command-line-resources nil)
81 (setq command-switch-alist
82 (append '(("-bw" . x-handle-numeric-switch)
83 ("-d" . x-handle-display)
84 ("-display" . x-handle-display)
85 ("-name" . x-handle-switch)
86 ("-T" . x-handle-switch)
87 ("-r" . x-handle-switch)
88 ("-rv" . x-handle-switch)
89 ("-reverse" . x-handle-switch)
90 ("-fn" . x-handle-switch)
91 ("-font" . x-handle-switch)
92 ("-ib" . x-handle-switch)
93 ("-g" . x-handle-geometry)
94 ("-geometry" . x-handle-geometry)
95 ("-fg" . x-handle-switch)
96 ("-foreground". x-handle-switch)
97 ("-bg" . x-handle-switch)
98 ("-background". x-handle-switch)
99 ("-ms" . x-handle-switch)
100 ("-itype" . x-handle-switch)
101 ("-i" . x-handle-switch)
102 ("-iconic" . x-handle-switch)
103 ("-rn" . x-handle-rn-switch)
104 ("-cr" . x-handle-switch)
105 ("-vb" . x-handle-switch)
106 ("-hb" . x-handle-switch)
107 ("-bd" . x-handle-switch))
108 command-switch-alist))
110 (defconst x-switch-definitions
111 '(("-name" name)
112 ("-T" name)
113 ("-r" reverse t)
114 ("-rv" reverse t)
115 ("-reverse" reverse t)
116 ("-fn" font)
117 ("-font" font)
118 ("-ib" internal-border-width)
119 ("-fg" foreground-color)
120 ("-foreground" foreground-color)
121 ("-bg" background-color)
122 ("-background" background-color)
123 ("-ms" mouse-color)
124 ("-cr" cursor-color)
125 ("-itype" icon-type t)
126 ("-i" icon-type t)
127 ("-iconic" iconic-startup t)
128 ("-vb" vertical-scroll-bars t)
129 ("-hb" horizontal-scroll-bars t)
130 ("-bd" border-color)
131 ("-bw" border-width)))
133 ;; Handler for switches of the form "-switch value" or "-switch".
134 (defun x-handle-switch (switch)
135 (let ((aelt (assoc switch x-switch-definitions)))
136 (if aelt
137 (if (nth 2 aelt)
138 (setq default-frame-alist
139 (cons (cons (nth 1 aelt) (nth 2 aelt))
140 default-frame-alist))
141 (setq default-frame-alist
142 (cons (cons (nth 1 aelt)
143 (car x-invocation-args))
144 default-frame-alist)
145 x-invocation-args (cdr x-invocation-args))))))
147 ;; Handler for switches of the form "-switch n"
148 (defun x-handle-numeric-switch (switch)
149 (let ((aelt (assoc switch x-switch-definitions)))
150 (if aelt
151 (setq default-frame-alist
152 (cons (cons (nth 1 aelt)
153 (string-to-int (car x-invocation-args)))
154 default-frame-alist)
155 x-invocation-args
156 (cdr x-invocation-args)))))
158 ;; Handle the -rn option.
159 (defun x-handle-rn-switch (switch)
160 (setq x-command-line-resources (car x-invocation-args))
161 (setq x-invocation-args (cdr x-invocation-args)))
163 ;; Handle the geometry option
164 (defun x-handle-geometry (switch)
165 (setq initial-frame-alist
166 (append initial-frame-alist
167 (x-parse-geometry (car x-invocation-args)))
168 x-invocation-args (cdr x-invocation-args)))
170 (defvar x-display-name nil
171 "The X display name specifying server and X frame.")
173 (defun x-handle-display (switch)
174 (setq x-display-name (car x-invocation-args)
175 x-invocation-args (cdr x-invocation-args)))
177 (defvar x-invocation-args nil)
179 (defun x-handle-args (args)
180 "Here the X-related command line options in ARGS are processed,
181 before the user's startup file is loaded. They are copied to
182 x-invocation args from which the X-related things are extracted, first
183 the switch (e.g., \"-fg\") in the following code, and possible values
184 (e.g., \"black\") in the option handler code (e.g., x-handle-switch).
185 This returns ARGS with the arguments that have been processed removed."
186 (setq x-invocation-args args
187 args nil)
188 (while x-invocation-args
189 (let* ((this-switch (car x-invocation-args))
190 (aelt (assoc this-switch command-switch-alist)))
191 (setq x-invocation-args (cdr x-invocation-args))
192 (if aelt
193 (funcall (cdr aelt) this-switch)
194 (setq args (cons this-switch args)))))
195 (setq args (nreverse args)))
200 ;; Standard X cursor shapes, courtesy of Mr. Fox, who wanted ALL of them.
203 (defconst x-pointer-X-cursor 0)
204 (defconst x-pointer-arrow 2)
205 (defconst x-pointer-based-arrow-down 4)
206 (defconst x-pointer-based-arrow-up 6)
207 (defconst x-pointer-boat 8)
208 (defconst x-pointer-bogosity 10)
209 (defconst x-pointer-bottom-left-corner 12)
210 (defconst x-pointer-bottom-right-corner 14)
211 (defconst x-pointer-bottom-side 16)
212 (defconst x-pointer-bottom-tee 18)
213 (defconst x-pointer-box-spiral 20)
214 (defconst x-pointer-center-ptr 22)
215 (defconst x-pointer-circle 24)
216 (defconst x-pointer-clock 26)
217 (defconst x-pointer-coffee-mug 28)
218 (defconst x-pointer-cross 30)
219 (defconst x-pointer-cross-reverse 32)
220 (defconst x-pointer-crosshair 34)
221 (defconst x-pointer-diamond-cross 36)
222 (defconst x-pointer-dot 38)
223 (defconst x-pointer-dotbox 40)
224 (defconst x-pointer-double-arrow 42)
225 (defconst x-pointer-draft-large 44)
226 (defconst x-pointer-draft-small 46)
227 (defconst x-pointer-draped-box 48)
228 (defconst x-pointer-exchange 50)
229 (defconst x-pointer-fleur 52)
230 (defconst x-pointer-gobbler 54)
231 (defconst x-pointer-gumby 56)
232 (defconst x-pointer-hand1 58)
233 (defconst x-pointer-hand2 60)
234 (defconst x-pointer-heart 62)
235 (defconst x-pointer-icon 64)
236 (defconst x-pointer-iron-cross 66)
237 (defconst x-pointer-left-ptr 68)
238 (defconst x-pointer-left-side 70)
239 (defconst x-pointer-left-tee 72)
240 (defconst x-pointer-leftbutton 74)
241 (defconst x-pointer-ll-angle 76)
242 (defconst x-pointer-lr-angle 78)
243 (defconst x-pointer-man 80)
244 (defconst x-pointer-middlebutton 82)
245 (defconst x-pointer-mouse 84)
246 (defconst x-pointer-pencil 86)
247 (defconst x-pointer-pirate 88)
248 (defconst x-pointer-plus 90)
249 (defconst x-pointer-question-arrow 92)
250 (defconst x-pointer-right-ptr 94)
251 (defconst x-pointer-right-side 96)
252 (defconst x-pointer-right-tee 98)
253 (defconst x-pointer-rightbutton 100)
254 (defconst x-pointer-rtl-logo 102)
255 (defconst x-pointer-sailboat 104)
256 (defconst x-pointer-sb-down-arrow 106)
257 (defconst x-pointer-sb-h-double-arrow 108)
258 (defconst x-pointer-sb-left-arrow 110)
259 (defconst x-pointer-sb-right-arrow 112)
260 (defconst x-pointer-sb-up-arrow 114)
261 (defconst x-pointer-sb-v-double-arrow 116)
262 (defconst x-pointer-shuttle 118)
263 (defconst x-pointer-sizing 120)
264 (defconst x-pointer-spider 122)
265 (defconst x-pointer-spraycan 124)
266 (defconst x-pointer-star 126)
267 (defconst x-pointer-target 128)
268 (defconst x-pointer-tcross 130)
269 (defconst x-pointer-top-left-arrow 132)
270 (defconst x-pointer-top-left-corner 134)
271 (defconst x-pointer-top-right-corner 136)
272 (defconst x-pointer-top-side 138)
273 (defconst x-pointer-top-tee 140)
274 (defconst x-pointer-trek 142)
275 (defconst x-pointer-ul-angle 144)
276 (defconst x-pointer-umbrella 146)
277 (defconst x-pointer-ur-angle 148)
278 (defconst x-pointer-watch 150)
279 (defconst x-pointer-xterm 152)
282 ;; Available colors
285 (defvar x-colors '("aquamarine"
286 "Aquamarine"
287 "medium aquamarine"
288 "MediumAquamarine"
289 "black"
290 "Black"
291 "blue"
292 "Blue"
293 "cadet blue"
294 "CadetBlue"
295 "cornflower blue"
296 "CornflowerBlue"
297 "dark slate blue"
298 "DarkSlateBlue"
299 "light blue"
300 "LightBlue"
301 "light steel blue"
302 "LightSteelBlue"
303 "medium blue"
304 "MediumBlue"
305 "medium slate blue"
306 "MediumSlateBlue"
307 "midnight blue"
308 "MidnightBlue"
309 "navy blue"
310 "NavyBlue"
311 "navy"
312 "Navy"
313 "sky blue"
314 "SkyBlue"
315 "slate blue"
316 "SlateBlue"
317 "steel blue"
318 "SteelBlue"
319 "coral"
320 "Coral"
321 "cyan"
322 "Cyan"
323 "firebrick"
324 "Firebrick"
325 "brown"
326 "Brown"
327 "gold"
328 "Gold"
329 "goldenrod"
330 "Goldenrod"
331 "medium goldenrod"
332 "MediumGoldenrod"
333 "green"
334 "Green"
335 "dark green"
336 "DarkGreen"
337 "dark olive green"
338 "DarkOliveGreen"
339 "forest green"
340 "ForestGreen"
341 "lime green"
342 "LimeGreen"
343 "medium forest green"
344 "MediumForestGreen"
345 "medium sea green"
346 "MediumSeaGreen"
347 "medium spring green"
348 "MediumSpringGreen"
349 "pale green"
350 "PaleGreen"
351 "sea green"
352 "SeaGreen"
353 "spring green"
354 "SpringGreen"
355 "yellow green"
356 "YellowGreen"
357 "dark slate grey"
358 "DarkSlateGrey"
359 "dark slate gray"
360 "DarkSlateGray"
361 "dim grey"
362 "DimGrey"
363 "dim gray"
364 "DimGray"
365 "light grey"
366 "LightGrey"
367 "light gray"
368 "LightGray"
369 "gray"
370 "grey"
371 "Gray"
372 "Grey"
373 "khaki"
374 "Khaki"
375 "magenta"
376 "Magenta"
377 "maroon"
378 "Maroon"
379 "orange"
380 "Orange"
381 "orchid"
382 "Orchid"
383 "dark orchid"
384 "DarkOrchid"
385 "medium orchid"
386 "MediumOrchid"
387 "pink"
388 "Pink"
389 "plum"
390 "Plum"
391 "red"
392 "Red"
393 "indian red"
394 "IndianRed"
395 "medium violet red"
396 "MediumVioletRed"
397 "orange red"
398 "OrangeRed"
399 "violet red"
400 "VioletRed"
401 "salmon"
402 "Salmon"
403 "sienna"
404 "Sienna"
405 "tan"
406 "Tan"
407 "thistle"
408 "Thistle"
409 "turquoise"
410 "Turquoise"
411 "dark turquoise"
412 "DarkTurquoise"
413 "medium turquoise"
414 "MediumTurquoise"
415 "violet"
416 "Violet"
417 "blue violet"
418 "BlueViolet"
419 "wheat"
420 "Wheat"
421 "white"
422 "White"
423 "yellow"
424 "Yellow"
425 "green yellow"
426 "GreenYellow")
427 "The full list of X colors from the rgb.text file.")
429 (defun x-defined-colors ()
430 "Return a list of colors supported by the current X-Display."
431 (let ((all-colors x-colors)
432 (this-color nil)
433 (defined-colors nil))
434 (while all-colors
435 (setq this-color (car all-colors)
436 all-colors (cdr all-colors))
437 (and (x-color-defined-p this-color)
438 (setq defined-colors (cons this-color defined-colors))))
439 defined-colors))
441 ;;;; Function keys
443 (substitute-key-definition 'suspend-emacs 'iconify-frame global-map)
445 ;; Map certain keypad keys into ASCII characters
446 ;; that people usually expect.
447 (define-key function-key-map [backspace] [127])
448 (define-key function-key-map [delete] [127])
449 (define-key function-key-map [tab] [?\t])
450 (define-key function-key-map [linefeed] [?\n])
451 (define-key function-key-map [clear] [11])
452 (define-key function-key-map [return] [13])
453 (define-key function-key-map [escape] [?\e])
454 (define-key function-key-map [M-backspace] [?\M-\d])
455 (define-key function-key-map [M-delete] [?\M-\d])
456 (define-key function-key-map [M-tab] [?\M-\t])
457 (define-key function-key-map [M-linefeed] [?\M-\n])
458 (define-key function-key-map [M-clear] [?\M-\013])
459 (define-key function-key-map [M-return] [?\M-\015])
460 (define-key function-key-map [M-escape] [?\M-\e])
462 ;; These tell read-char how to convert
463 ;; these special chars to ASCII.
464 (put 'backspace 'ascii-character 127)
465 (put 'delete 'ascii-character 127)
466 (put 'tab 'ascii-character ?\t)
467 (put 'linefeed 'ascii-character ?\n)
468 (put 'clear 'ascii-character 12)
469 (put 'return 'ascii-character 13)
470 (put 'escape 'ascii-character ?\e)
472 ;;;; Selections and cut buffers
474 ;;; We keep track of the last text selected here, so we can check the
475 ;;; current selection against it, and avoid passing back our own text
476 ;;; from x-cut-buffer-or-selection-value.
477 (defvar x-last-selected-text nil)
479 ;;; Make TEXT, a string, the primary and clipboard X selections.
480 ;;; If you are running xclipboard, this means you can effectively
481 ;;; have a window on a copy of the kill-ring.
482 ;;; Also, set the value of X cut buffer 0, for backward compatibility
483 ;;; with older X applications.
484 (defun x-select-text (text &optional push)
485 (x-set-cut-buffer text push)
486 (x-set-selection 'CLIPBOARD text)
487 (x-set-selection 'PRIMARY text)
488 (setq x-last-selected-text text))
490 ;;; Return the value of the current X selection. For compatibility
491 ;;; with older X applications, this checks cut buffer 0 before
492 ;;; retrieving the value of the primary selection.
493 (defun x-cut-buffer-or-selection-value ()
494 (let (text)
496 ;; Consult the cut buffer, then the selection. Treat empty strings
497 ;; as if they were unset.
498 (setq text (x-get-cut-buffer 0))
499 (if (string= text "") (setq text nil))
500 (or text (setq text (x-get-selection 'PRIMARY)))
501 (if (string= text "") (setq text nil))
503 (cond
504 ((not text) nil)
505 ((eq text x-last-selected-text) nil)
506 ((string= text x-last-selected-text)
507 ;; Record the newer string, so subsequent calls can use the `eq' test.
508 (setq x-last-selected-text text)
509 nil)
511 (setq x-last-selected-text text)))))
514 ;;; Do the actual X Windows setup here; the above code just defines
515 ;;; functions and variables that we use now.
517 (setq command-line-args (x-handle-args command-line-args))
518 (x-open-connection (or x-display-name
519 (setq x-display-name (getenv "DISPLAY")))
520 x-command-line-resources)
522 (setq frame-creation-function 'x-create-frame-with-faces)
524 ;; Apply a geometry resource to the initial frame. Put it at the end
525 ;; of the alist, so that anything specified on the command line takes
526 ;; precedence.
527 (let ((res-geometry (x-get-resource "geometry" "Geometry")))
528 (if res-geometry
529 (setq initial-frame-alist (append initial-frame-alist
530 (x-parse-geometry res-geometry)))))
532 (defun x-win-suspend-error ()
533 (error "Suspending an emacs running under X makes no sense"))
534 (add-hook 'suspend-hook 'x-win-suspend-error)
536 ;;; Arrange for the kill and yank functions to set and check the clipboard.
537 (setq interprogram-cut-function 'x-select-text)
538 (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
540 ;;; Turn off window-splitting optimization; X is usually fast enough
541 ;;; that this is only annoying.
542 (setq split-window-keep-point t)
544 ;;; x-win.el ends here