1 ;;; x-win.el --- parse switches controlling interface with X window system
2 ;; Copyright (C) 1993 Free Software Foundation, Inc.
7 ;;; This file is part of GNU Emacs.
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.
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.
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.
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).
35 ;; These are the standard X switches from the Xt Initialize.c file of
38 ;; Command line Resource Manager string
41 ;; +synchronous *synchronous
42 ;; -background *background
45 ;; -bordercolor *borderColor
46 ;; -borderwidth .borderWidth
52 ;; -foreground *foreground
53 ;; -geometry .geometry
58 ;; -reverse *reverseVideo
60 ;; -selectionTimeout .selectionTimeout
61 ;; -synchronous *synchronous
64 ;; An alist of X options and the function which handles them. See
67 (if (not (eq window-system
'x
))
68 (error "Loading x-win.el but not compiled for X"))
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
115 ("-reverse" reverse t
)
118 ("-ib" internal-border-width
)
119 ("-fg" foreground-color
)
120 ("-foreground" foreground-color
)
121 ("-bg" background-color
)
122 ("-background" background-color
)
125 ("-itype" icon-type t
)
127 ("-iconic" iconic-startup t
)
128 ("-vb" vertical-scroll-bars t
)
129 ("-hb" horizontal-scroll-bars t
)
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
)))
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
))
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
)))
151 (setq default-frame-alist
152 (cons (cons (nth 1 aelt
)
153 (string-to-int (car 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
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
))
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)
285 (defvar x-colors
'("aquamarine"
343 "medium forest green"
347 "medium spring green"
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
)
433 (defined-colors nil
))
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
))))
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 ()
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))
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)
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
527 (let ((res-geometry (x-get-resource "geometry" "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