*** empty log message ***
[bpt/emacs.git] / lisp / term / x-win.el
CommitLineData
63f77899
JB
1;; Parse switches controlling how Emacs interfaces with X window system.
2;; Copyright (C) 1990 Free Software Foundation, Inc.
3
4;; This file is part of GNU Emacs.
5
6;; GNU Emacs is distributed in the hope that it will be useful,
7;; but WITHOUT ANY WARRANTY. No author or distributor
8;; accepts responsibility to anyone for the consequences of using it
9;; or for whether it serves any particular purpose or works at all,
10;; unless he says so in writing. Refer to the GNU Emacs General Public
11;; License for full details.
12
13;; Everyone is granted permission to copy, modify and redistribute
14;; GNU Emacs, but only under the conditions described in the
15;; GNU Emacs General Public License. A copy of this license is
16;; supposed to have been given to you along with GNU Emacs so you
17;; can know your rights and responsibilities. It should be in a
18;; file named COPYING. Among other things, the copyright notice
19;; and this notice must be preserved on all copies.
20
21
22;; X-win.el: this file is loaded from ../lisp/startup.el when it recognizes
23;; that X windows are to be used. Command line switches are parsed and those
24;; pertaining to X are processed and removed from the command line. The
25;; X display is opened and hooks are set for popping up the initial window.
26
27;; startup.el will then examine startup files, and eventually call the hooks
28;; which create the first window (s).
29\f
30;; These are the standard X switches from the Xt Initialize.c file of
31;; Release 4.
32
33;; Command line Resource Manager string
34
35;; +rv *reverseVideo
36;; +synchronous *synchronous
37;; -background *background
38;; -bd *borderColor
39;; -bg *background
40;; -bordercolor *borderColor
41;; -borderwidth .borderWidth
42;; -bw .borderWidth
43;; -display .display
44;; -fg *foreground
45;; -fn *font
46;; -font *font
47;; -foreground *foreground
48;; -geometry .geometry
49;; -iconic .iconic
50;; -name .name
51;; -reverse *reverseVideo
52;; -rv *reverseVideo
53;; -selectionTimeout .selectionTimeout
54;; -synchronous *synchronous
55;; -title .title
56;; -xrm
57
63f77899
JB
58;; An alist of X options and the function which handles them. See
59;; ../startup.el.
60
63c86e17
JB
61(if (not (eq window-system 'x))
62 (error "Loading x-win.el but not compiled for X"))
63
63c86e17 64(require 'screen)
3eb43f71 65(require 'mouse)
63c86e17 66
63f77899 67(setq command-switch-alist
708c60f8 68 (append '(("-bw" . x-handle-numeric-switch)
63c86e17
JB
69 ("-d" . x-handle-display)
70 ("-display" . x-handle-display)
71 ("-name" . x-handle-switch)
72 ("-T" . x-handle-switch)
73 ("-r" . x-handle-switch)
74 ("-rv" . x-handle-switch)
75 ("-reverse" . x-handle-switch)
76 ("-fn" . x-handle-switch)
77 ("-font" . x-handle-switch)
78 ("-ib" . x-handle-switch)
79 ("-g" . x-handle-geometry)
80 ("-geometry" . x-handle-geometry)
81 ("-fg" . x-handle-switch)
82 ("-foreground". x-handle-switch)
83 ("-bg" . x-handle-switch)
84 ("-background". x-handle-switch)
85 ("-ms" . x-handle-switch)
86 ("-ib" . x-handle-switch)
87 ("-iconic" . x-handle-switch)
88 ("-cr" . x-handle-switch)
89 ("-vb" . x-handle-switch)
90 ("-hb" . x-handle-switch)
91 ("-bd" . x-handle-switch))
63f77899
JB
92 command-switch-alist))
93
63f77899
JB
94(defconst x-switch-definitions
95 '(("-name" name)
96 ("-T" name)
97 ("-r" lose)
98 ("-rv" lose)
99 ("-reverse" lose)
100 ("-fn" font)
101 ("-font" font)
102 ("-ib" internal-border-width)
103 ("-fg" foreground-color)
104 ("-foreground" foreground-color)
105 ("-bg" background-color)
106 ("-background" background-color)
107 ("-ms" mouse-color)
108 ("-cr" cursor-color)
109 ("-ib" icon-type t)
110 ("-iconic" iconic-startup t)
111 ("-vb" vertical-scroll-bar t)
112 ("-hb" horizontal-scroll-bar t)
113 ("-bd" border-color)
114 ("-bw" border-width)))
115
116;; Handler for switches of the form "-switch value" or "-switch".
117(defun x-handle-switch (switch)
118 (let ((aelt (assoc switch x-switch-definitions)))
119 (if aelt
120 (if (nth 2 aelt)
4f0f077c 121 (setq default-screen-alist
63f77899 122 (cons (cons (nth 1 aelt) (nth 2 aelt))
4f0f077c
JB
123 default-screen-alist))
124 (setq default-screen-alist
63f77899
JB
125 (cons (cons (nth 1 aelt)
126 (car x-invocation-args))
4f0f077c 127 default-screen-alist)
63f77899
JB
128 x-invocation-args (cdr x-invocation-args))))))
129
130;; Handler for switches of the form "-switch n"
131(defun x-handle-numeric-switch (switch)
132 (let ((aelt (assoc switch x-switch-definitions)))
133 (if aelt
4f0f077c 134 (setq default-screen-alist
63f77899
JB
135 (cons (cons (nth 1 aelt)
136 (string-to-int (car x-invocation-args)))
4f0f077c 137 default-screen-alist)
63f77899
JB
138 x-invocation-args
139 (cdr x-invocation-args)))))
140
141;; Handle the geometry option
142(defun x-handle-geometry (switch)
b54621ea 143 (setq initial-screen-alist (append initial-screen-alist
63f77899
JB
144 (x-geometry (car x-invocation-args)))
145 x-invocation-args (cdr x-invocation-args)))
146
63f77899
JB
147(defvar x-display-name nil
148 "The X display name specifying server and X screen.")
149
150(defun x-handle-display (switch)
151 (setq x-display-name (car x-invocation-args)
152 x-invocation-args (cdr x-invocation-args)))
153
63f77899
JB
154(defvar x-invocation-args nil)
155
8769d648
JB
156(defun x-handle-args (args)
157 "Here the X-related command line options in ARGS are processed,
158before the user's startup file is loaded. They are copied to
159x-invocation args from which the X-related things are extracted, first
160the switch (e.g., \"-fg\") in the following code, and possible values
161(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
162This returns ARGS with the arguments that have been processed removed."
63c86e17
JB
163 (setq x-invocation-args args
164 args nil)
165 (while x-invocation-args
166 (let* ((this-switch (car x-invocation-args))
167 (aelt (assoc this-switch command-switch-alist)))
168 (setq x-invocation-args (cdr x-invocation-args))
169 (if aelt
170 (funcall (cdr aelt) this-switch)
171 (setq args (cons this-switch args)))))
172 (setq args (nreverse args)))
173
b54621ea 174
63f77899
JB
175\f
176;;
177;; Standard X cursor shapes, courtesy of Mr. Fox, who wanted ALL of them.
178;;
179
180(defconst x-pointer-X-cursor 0)
181(defconst x-pointer-arrow 2)
182(defconst x-pointer-based-arrow-down 4)
183(defconst x-pointer-based-arrow-up 6)
184(defconst x-pointer-boat 8)
185(defconst x-pointer-bogosity 10)
186(defconst x-pointer-bottom-left-corner 12)
187(defconst x-pointer-bottom-right-corner 14)
188(defconst x-pointer-bottom-side 16)
189(defconst x-pointer-bottom-tee 18)
190(defconst x-pointer-box-spiral 20)
191(defconst x-pointer-center-ptr 22)
192(defconst x-pointer-circle 24)
193(defconst x-pointer-clock 26)
194(defconst x-pointer-coffee-mug 28)
195(defconst x-pointer-cross 30)
196(defconst x-pointer-cross-reverse 32)
197(defconst x-pointer-crosshair 34)
198(defconst x-pointer-diamond-cross 36)
199(defconst x-pointer-dot 38)
200(defconst x-pointer-dotbox 40)
201(defconst x-pointer-double-arrow 42)
202(defconst x-pointer-draft-large 44)
203(defconst x-pointer-draft-small 46)
204(defconst x-pointer-draped-box 48)
205(defconst x-pointer-exchange 50)
206(defconst x-pointer-fleur 52)
207(defconst x-pointer-gobbler 54)
208(defconst x-pointer-gumby 56)
209(defconst x-pointer-hand1 58)
210(defconst x-pointer-hand2 60)
211(defconst x-pointer-heart 62)
212(defconst x-pointer-icon 64)
213(defconst x-pointer-iron-cross 66)
214(defconst x-pointer-left-ptr 68)
215(defconst x-pointer-left-side 70)
216(defconst x-pointer-left-tee 72)
217(defconst x-pointer-leftbutton 74)
218(defconst x-pointer-ll-angle 76)
219(defconst x-pointer-lr-angle 78)
220(defconst x-pointer-man 80)
221(defconst x-pointer-middlebutton 82)
222(defconst x-pointer-mouse 84)
223(defconst x-pointer-pencil 86)
224(defconst x-pointer-pirate 88)
225(defconst x-pointer-plus 90)
226(defconst x-pointer-question-arrow 92)
227(defconst x-pointer-right-ptr 94)
228(defconst x-pointer-right-side 96)
229(defconst x-pointer-right-tee 98)
230(defconst x-pointer-rightbutton 100)
231(defconst x-pointer-rtl-logo 102)
232(defconst x-pointer-sailboat 104)
233(defconst x-pointer-sb-down-arrow 106)
234(defconst x-pointer-sb-h-double-arrow 108)
235(defconst x-pointer-sb-left-arrow 110)
236(defconst x-pointer-sb-right-arrow 112)
237(defconst x-pointer-sb-up-arrow 114)
238(defconst x-pointer-sb-v-double-arrow 116)
239(defconst x-pointer-shuttle 118)
240(defconst x-pointer-sizing 120)
241(defconst x-pointer-spider 122)
242(defconst x-pointer-spraycan 124)
243(defconst x-pointer-star 126)
244(defconst x-pointer-target 128)
245(defconst x-pointer-tcross 130)
246(defconst x-pointer-top-left-arrow 132)
247(defconst x-pointer-top-left-corner 134)
248(defconst x-pointer-top-right-corner 136)
249(defconst x-pointer-top-side 138)
250(defconst x-pointer-top-tee 140)
251(defconst x-pointer-trek 142)
252(defconst x-pointer-ul-angle 144)
253(defconst x-pointer-umbrella 146)
254(defconst x-pointer-ur-angle 148)
255(defconst x-pointer-watch 150)
256(defconst x-pointer-xterm 152)
257\f
258;;
259;; Available colors
260;;
261
262(defvar x-colors '("aquamarine"
263 "Aquamarine"
264 "medium aquamarine"
265 "MediumAquamarine"
266 "black"
267 "Black"
268 "blue"
269 "Blue"
270 "cadet blue"
271 "CadetBlue"
272 "cornflower blue"
273 "CornflowerBlue"
274 "dark slate blue"
275 "DarkSlateBlue"
276 "light blue"
277 "LightBlue"
278 "light steel blue"
279 "LightSteelBlue"
280 "medium blue"
281 "MediumBlue"
282 "medium slate blue"
283 "MediumSlateBlue"
284 "midnight blue"
285 "MidnightBlue"
286 "navy blue"
287 "NavyBlue"
288 "navy"
289 "Navy"
290 "sky blue"
291 "SkyBlue"
292 "slate blue"
293 "SlateBlue"
294 "steel blue"
295 "SteelBlue"
296 "coral"
297 "Coral"
298 "cyan"
299 "Cyan"
300 "firebrick"
301 "Firebrick"
302 "brown"
303 "Brown"
304 "gold"
305 "Gold"
306 "goldenrod"
307 "Goldenrod"
308 "medium goldenrod"
309 "MediumGoldenrod"
310 "green"
311 "Green"
312 "dark green"
313 "DarkGreen"
314 "dark olive green"
315 "DarkOliveGreen"
316 "forest green"
317 "ForestGreen"
318 "lime green"
319 "LimeGreen"
320 "medium forest green"
321 "MediumForestGreen"
322 "medium sea green"
323 "MediumSeaGreen"
324 "medium spring green"
325 "MediumSpringGreen"
326 "pale green"
327 "PaleGreen"
328 "sea green"
329 "SeaGreen"
330 "spring green"
331 "SpringGreen"
332 "yellow green"
333 "YellowGreen"
334 "dark slate grey"
335 "DarkSlateGrey"
336 "dark slate gray"
337 "DarkSlateGray"
338 "dim grey"
339 "DimGrey"
340 "dim gray"
341 "DimGray"
342 "light grey"
343 "LightGrey"
344 "light gray"
345 "LightGray"
346 "gray"
347 "grey"
348 "Gray"
349 "Grey"
350 "khaki"
351 "Khaki"
352 "magenta"
353 "Magenta"
354 "maroon"
355 "Maroon"
356 "orange"
357 "Orange"
358 "orchid"
359 "Orchid"
360 "dark orchid"
361 "DarkOrchid"
362 "medium orchid"
363 "MediumOrchid"
364 "pink"
365 "Pink"
366 "plum"
367 "Plum"
368 "red"
369 "Red"
370 "indian red"
371 "IndianRed"
372 "medium violet red"
373 "MediumVioletRed"
374 "orange red"
375 "OrangeRed"
376 "violet red"
377 "VioletRed"
378 "salmon"
379 "Salmon"
380 "sienna"
381 "Sienna"
382 "tan"
383 "Tan"
384 "thistle"
385 "Thistle"
386 "turquoise"
387 "Turquoise"
388 "dark turquoise"
389 "DarkTurquoise"
390 "medium turquoise"
391 "MediumTurquoise"
392 "violet"
393 "Violet"
394 "blue violet"
395 "BlueViolet"
396 "wheat"
397 "Wheat"
398 "white"
399 "White"
400 "yellow"
401 "Yellow"
402 "green yellow"
403 "GreenYellow")
404 "The full list of X colors from the rgb.text file.")
405
406(defun x-defined-colors ()
407 "Return a list of colors supported by the current X-Display."
408 (let ((all-colors x-colors)
409 (this-color nil)
410 (defined-colors nil))
411 (while all-colors
412 (setq this-color (car all-colors)
413 all-colors (cdr all-colors))
414 (and (x-defined-color this-color)
415 (setq defined-colors (cons this-color defined-colors))))
416 defined-colors))
63f77899 417\f
98bf0c8d
JB
418;;;; Function keys
419
420;;; Give some common function keys reasonable definitions.
421(define-key global-map [home] 'beginning-of-line)
422(define-key global-map [left] 'backward-char)
423(define-key global-map [up] 'previous-line)
424(define-key global-map [right] 'forward-char)
425(define-key global-map [down] 'next-line)
426(define-key global-map [prior] 'scroll-down)
427(define-key global-map [next] 'scroll-up)
428(define-key global-map [begin] 'beginning-of-buffer)
429(define-key global-map [end] 'end-of-buffer)
63c86e17 430
080a57ce 431(define-key global-map "\C-z" 'iconify)
98bf0c8d 432\f
b54621ea
JB
433;;; Do the actual X Windows setup here; the above code just defines
434;;; functions and variables that we use now.
63c86e17 435
708c60f8 436(setq command-line-args (x-handle-args command-line-args))
63c86e17
JB
437(x-open-connection (or x-display-name
438 (setq x-display-name (getenv "DISPLAY"))))
e9de784c 439
492878e4
JB
440;;; xterm.c depends on using interrupt-driven input, but we don't want
441;;; the fcntls to apply to the terminal, so we do this after opening
442;;; the display.
e9de784c
JB
443(set-input-mode t nil t)
444
67dbf5b0 445(setq screen-creation-function 'x-create-screen)
63c86e17
JB
446(setq suspend-hook
447 '(lambda ()
448 (error "Suspending an emacs running under X makes no sense")))
67c86cfc 449
daa37602
JB
450;;; We keep track of the last text selected here, so we can check the
451;;; current selection against it, and avoid passing back our own text
452;;; from x-cut-buffer-or-selection-value.
453(defvar x-last-selected-text nil)
454
492878e4
JB
455;;; Make TEXT, a string, the primary and clipboard X selections.
456;;; If you are running xclipboard, this means you can effectively
457;;; have a window on a copy of the kill-ring.
458;;; Also, set the value of X cut buffer 0, for backward compatibility
459;;; with older X application.
67c86cfc 460(defun x-select-text (text)
492878e4
JB
461 (x-own-selection text 'cut-buffer0)
462 (x-own-selection text 'clipboard)
daa37602
JB
463 (x-own-selection text)
464 (setq x-last-selected-text text))
492878e4
JB
465
466;;; Return the value of the current X selection. For compatibility
467;;; with older X applications, this checks cut buffer 0 before
468;;; retrieving the value of the primary selection.
469(defun x-cut-buffer-or-selection-value ()
daa37602
JB
470 (let ((text (or (x-selection-value 'cut-buffer0)
471 (x-selection-value))))
472 (if (string= text x-last-selected-text)
473 nil
474 (setq x-last-selected-text nil)
475 text)))
492878e4
JB
476
477;;; Arrange for the kill and yank functions to set and check the clipboard.
478(setq interprogram-cut-function 'x-select-text)
479(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
63c86e17 480
0cc6db57
JB
481;;; Turn off window-splitting optimization; X is usually fast enough
482;;; that this is only annoying.
483(setq split-window-keep-point t)