(tibetan-pre-write-conversion): Cancel previous
[bpt/emacs.git] / lisp / term / x-win.el
CommitLineData
5cdb3f1e 1;;; x-win.el --- parse switches controlling interface with X window system
2fe590dc 2
d733c5ec 3;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
5cdb3f1e
ER
4
5;; Author: FSF
6;; Keywords: terminals
7
2fe590dc
EN
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
63f77899 24
5cdb3f1e 25;;; Commentary:
63f77899
JB
26
27;; X-win.el: this file is loaded from ../lisp/startup.el when it recognizes
28;; that X windows are to be used. Command line switches are parsed and those
29;; pertaining to X are processed and removed from the command line. The
30;; X display is opened and hooks are set for popping up the initial window.
31
32;; startup.el will then examine startup files, and eventually call the hooks
33;; which create the first window (s).
5cdb3f1e
ER
34
35;;; Code:
63f77899
JB
36\f
37;; These are the standard X switches from the Xt Initialize.c file of
38;; Release 4.
39
40;; Command line Resource Manager string
41
42;; +rv *reverseVideo
43;; +synchronous *synchronous
44;; -background *background
45;; -bd *borderColor
46;; -bg *background
47;; -bordercolor *borderColor
48;; -borderwidth .borderWidth
49;; -bw .borderWidth
50;; -display .display
51;; -fg *foreground
52;; -fn *font
53;; -font *font
54;; -foreground *foreground
55;; -geometry .geometry
db176f55
JB
56;; -i .iconType
57;; -itype .iconType
63f77899
JB
58;; -iconic .iconic
59;; -name .name
60;; -reverse *reverseVideo
61;; -rv *reverseVideo
62;; -selectionTimeout .selectionTimeout
63;; -synchronous *synchronous
63f77899
JB
64;; -xrm
65
63f77899
JB
66;; An alist of X options and the function which handles them. See
67;; ../startup.el.
68
63c86e17 69(if (not (eq window-system 'x))
800642d2 70 (error "%s: Loading x-win.el but not compiled for X" (invocation-name)))
63c86e17 71
0cc89026 72(require 'frame)
3eb43f71 73(require 'mouse)
b16795eb 74(require 'scroll-bar)
ffe1dd7a
JB
75(require 'faces)
76(require 'select)
290cb602 77(require 'menu-bar)
5afb8c58
RS
78(if (fboundp 'new-fontset)
79 (require 'fontset))
63c86e17 80
19b08de9
RS
81(defvar x-invocation-args)
82
f6f6d98c
RS
83(defvar x-command-line-resources nil)
84
63f77899
JB
85;; Handler for switches of the form "-switch value" or "-switch".
86(defun x-handle-switch (switch)
80128ceb 87 (let ((aelt (assoc switch command-line-x-option-alist)))
63f77899 88 (if aelt
80128ceb
RS
89 (let ((param (nth 3 aelt))
90 (value (nth 4 aelt)))
91 (if value
92 (setq default-frame-alist
93 (cons (cons param value)
94 default-frame-alist))
0cc89026 95 (setq default-frame-alist
80128ceb
RS
96 (cons (cons param
97 (car x-invocation-args))
98 default-frame-alist)
99 x-invocation-args (cdr x-invocation-args)))))))
100
101;; Handler for switches of the form "-switch n"
102(defun x-handle-numeric-switch (switch)
103 (let ((aelt (assoc switch command-line-x-option-alist)))
104 (if aelt
105 (let ((param (nth 3 aelt)))
0cc89026 106 (setq default-frame-alist
80128ceb
RS
107 (cons (cons param
108 (string-to-int (car x-invocation-args)))
0cc89026 109 default-frame-alist)
80128ceb
RS
110 x-invocation-args
111 (cdr x-invocation-args))))))
63f77899 112
ef599142
RS
113;; Make -iconic apply only to the initial frame!
114(defun x-handle-iconic (switch)
115 (setq initial-frame-alist
116 (cons '(visibility . icon) initial-frame-alist)))
117
800642d2
JB
118;; Handle the -xrm option.
119(defun x-handle-xrm-switch (switch)
120 (or (consp x-invocation-args)
121 (error "%s: missing argument to `%s' option" (invocation-name) switch))
f6f6d98c
RS
122 (setq x-command-line-resources (car x-invocation-args))
123 (setq x-invocation-args (cdr x-invocation-args)))
124
63f77899
JB
125;; Handle the geometry option
126(defun x-handle-geometry (switch)
6e42f5f8
RS
127 (let ((geo (x-parse-geometry (car x-invocation-args))))
128 (setq initial-frame-alist
129 (append initial-frame-alist
130 (if (or (assq 'left geo) (assq 'top geo))
131 '((user-position . t)))
132 (if (or (assq 'height geo) (assq 'width geo))
133 '((user-size . t)))
134 geo)
135 x-invocation-args (cdr x-invocation-args))))
63f77899 136
66f229be
RS
137;; Handle the -name option. Set the variable x-resource-name
138;; to the option's operand; set the name of
800642d2 139;; the initial frame, too.
66f229be 140(defun x-handle-name-switch (switch)
800642d2
JB
141 (or (consp x-invocation-args)
142 (error "%s: missing argument to `%s' option" (invocation-name) switch))
143 (setq x-resource-name (car x-invocation-args)
144 x-invocation-args (cdr x-invocation-args))
66f229be
RS
145 (setq initial-frame-alist (cons (cons 'name x-resource-name)
146 initial-frame-alist)))
800642d2 147
63f77899 148(defvar x-display-name nil
0cc89026 149 "The X display name specifying server and X frame.")
63f77899
JB
150
151(defun x-handle-display (switch)
152 (setq x-display-name (car x-invocation-args)
d98f0b87
RS
153 x-invocation-args (cdr x-invocation-args))
154 ;; Make subshell programs see the same DISPLAY value Emacs really uses.
155 ;; Note that this isn't completely correct, since Emacs can use
156 ;; multiple displays. However, there is no way to tell an already
157 ;; running subshell which display the user is currently typing on.
158 (setenv "DISPLAY" x-display-name))
63f77899 159
8769d648 160(defun x-handle-args (args)
dc20df95
RS
161 "Process the X-related command line options in ARGS.
162This is done before the user's startup file is loaded. They are copied to
80128ceb 163`x-invocation-args', from which the X-related things are extracted, first
8769d648 164the switch (e.g., \"-fg\") in the following code, and possible values
a4e104bf 165\(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
80128ceb
RS
166This function returns ARGS minus the arguments that have been processed."
167 ;; We use ARGS to accumulate the args that we don't handle here, to return.
63c86e17
JB
168 (setq x-invocation-args args
169 args nil)
0dd96d4c
RS
170 (while (and x-invocation-args
171 (not (equal (car x-invocation-args) "--")))
63c86e17 172 (let* ((this-switch (car x-invocation-args))
e491912f 173 (orig-this-switch this-switch)
80128ceb 174 completion argval aelt handler)
63c86e17 175 (setq x-invocation-args (cdr x-invocation-args))
e491912f
RS
176 ;; Check for long options with attached arguments
177 ;; and separate out the attached option argument into argval.
178 (if (string-match "^--[^=]*=" this-switch)
179 (setq argval (substring this-switch (match-end 0))
180 this-switch (substring this-switch 0 (1- (match-end 0)))))
80128ceb
RS
181 ;; Complete names of long options.
182 (if (string-match "^--" this-switch)
183 (progn
184 (setq completion (try-completion this-switch command-line-x-option-alist))
185 (if (eq completion t)
186 ;; Exact match for long option.
187 nil
188 (if (stringp completion)
189 (let ((elt (assoc completion command-line-x-option-alist)))
190 ;; Check for abbreviated long option.
191 (or elt
192 (error "Option `%s' is ambiguous" this-switch))
193 (setq this-switch completion))))))
194 (setq aelt (assoc this-switch command-line-x-option-alist))
195 (if aelt (setq handler (nth 2 aelt)))
196 (if handler
e491912f
RS
197 (if argval
198 (let ((x-invocation-args
199 (cons argval x-invocation-args)))
80128ceb
RS
200 (funcall handler this-switch))
201 (funcall handler this-switch))
202 (setq args (cons orig-this-switch args)))))
0dd96d4c 203 (nconc (nreverse args) x-invocation-args))
63f77899
JB
204\f
205;;
206;; Standard X cursor shapes, courtesy of Mr. Fox, who wanted ALL of them.
207;;
208
209(defconst x-pointer-X-cursor 0)
210(defconst x-pointer-arrow 2)
211(defconst x-pointer-based-arrow-down 4)
212(defconst x-pointer-based-arrow-up 6)
213(defconst x-pointer-boat 8)
214(defconst x-pointer-bogosity 10)
215(defconst x-pointer-bottom-left-corner 12)
216(defconst x-pointer-bottom-right-corner 14)
217(defconst x-pointer-bottom-side 16)
218(defconst x-pointer-bottom-tee 18)
219(defconst x-pointer-box-spiral 20)
220(defconst x-pointer-center-ptr 22)
221(defconst x-pointer-circle 24)
222(defconst x-pointer-clock 26)
223(defconst x-pointer-coffee-mug 28)
224(defconst x-pointer-cross 30)
225(defconst x-pointer-cross-reverse 32)
226(defconst x-pointer-crosshair 34)
227(defconst x-pointer-diamond-cross 36)
228(defconst x-pointer-dot 38)
229(defconst x-pointer-dotbox 40)
230(defconst x-pointer-double-arrow 42)
231(defconst x-pointer-draft-large 44)
232(defconst x-pointer-draft-small 46)
233(defconst x-pointer-draped-box 48)
234(defconst x-pointer-exchange 50)
235(defconst x-pointer-fleur 52)
236(defconst x-pointer-gobbler 54)
237(defconst x-pointer-gumby 56)
238(defconst x-pointer-hand1 58)
239(defconst x-pointer-hand2 60)
240(defconst x-pointer-heart 62)
241(defconst x-pointer-icon 64)
242(defconst x-pointer-iron-cross 66)
243(defconst x-pointer-left-ptr 68)
244(defconst x-pointer-left-side 70)
245(defconst x-pointer-left-tee 72)
246(defconst x-pointer-leftbutton 74)
247(defconst x-pointer-ll-angle 76)
248(defconst x-pointer-lr-angle 78)
249(defconst x-pointer-man 80)
250(defconst x-pointer-middlebutton 82)
251(defconst x-pointer-mouse 84)
252(defconst x-pointer-pencil 86)
253(defconst x-pointer-pirate 88)
254(defconst x-pointer-plus 90)
255(defconst x-pointer-question-arrow 92)
256(defconst x-pointer-right-ptr 94)
257(defconst x-pointer-right-side 96)
258(defconst x-pointer-right-tee 98)
259(defconst x-pointer-rightbutton 100)
260(defconst x-pointer-rtl-logo 102)
261(defconst x-pointer-sailboat 104)
262(defconst x-pointer-sb-down-arrow 106)
263(defconst x-pointer-sb-h-double-arrow 108)
264(defconst x-pointer-sb-left-arrow 110)
265(defconst x-pointer-sb-right-arrow 112)
266(defconst x-pointer-sb-up-arrow 114)
267(defconst x-pointer-sb-v-double-arrow 116)
268(defconst x-pointer-shuttle 118)
269(defconst x-pointer-sizing 120)
270(defconst x-pointer-spider 122)
271(defconst x-pointer-spraycan 124)
272(defconst x-pointer-star 126)
273(defconst x-pointer-target 128)
274(defconst x-pointer-tcross 130)
275(defconst x-pointer-top-left-arrow 132)
276(defconst x-pointer-top-left-corner 134)
277(defconst x-pointer-top-right-corner 136)
278(defconst x-pointer-top-side 138)
279(defconst x-pointer-top-tee 140)
280(defconst x-pointer-trek 142)
281(defconst x-pointer-ul-angle 144)
282(defconst x-pointer-umbrella 146)
283(defconst x-pointer-ur-angle 148)
284(defconst x-pointer-watch 150)
285(defconst x-pointer-xterm 152)
286\f
287;;
288;; Available colors
289;;
290
291(defvar x-colors '("aquamarine"
292 "Aquamarine"
293 "medium aquamarine"
294 "MediumAquamarine"
295 "black"
296 "Black"
297 "blue"
298 "Blue"
299 "cadet blue"
300 "CadetBlue"
301 "cornflower blue"
302 "CornflowerBlue"
303 "dark slate blue"
304 "DarkSlateBlue"
305 "light blue"
306 "LightBlue"
307 "light steel blue"
308 "LightSteelBlue"
309 "medium blue"
310 "MediumBlue"
311 "medium slate blue"
312 "MediumSlateBlue"
313 "midnight blue"
314 "MidnightBlue"
315 "navy blue"
316 "NavyBlue"
317 "navy"
318 "Navy"
319 "sky blue"
320 "SkyBlue"
321 "slate blue"
322 "SlateBlue"
323 "steel blue"
324 "SteelBlue"
325 "coral"
326 "Coral"
327 "cyan"
328 "Cyan"
329 "firebrick"
330 "Firebrick"
331 "brown"
332 "Brown"
333 "gold"
334 "Gold"
335 "goldenrod"
336 "Goldenrod"
63f77899
JB
337 "green"
338 "Green"
339 "dark green"
340 "DarkGreen"
341 "dark olive green"
342 "DarkOliveGreen"
343 "forest green"
344 "ForestGreen"
345 "lime green"
346 "LimeGreen"
63f77899
JB
347 "medium sea green"
348 "MediumSeaGreen"
349 "medium spring green"
350 "MediumSpringGreen"
351 "pale green"
352 "PaleGreen"
353 "sea green"
354 "SeaGreen"
355 "spring green"
356 "SpringGreen"
357 "yellow green"
358 "YellowGreen"
359 "dark slate grey"
360 "DarkSlateGrey"
361 "dark slate gray"
362 "DarkSlateGray"
363 "dim grey"
364 "DimGrey"
365 "dim gray"
366 "DimGray"
367 "light grey"
368 "LightGrey"
369 "light gray"
370 "LightGray"
371 "gray"
372 "grey"
373 "Gray"
374 "Grey"
375 "khaki"
376 "Khaki"
377 "magenta"
378 "Magenta"
379 "maroon"
380 "Maroon"
381 "orange"
382 "Orange"
383 "orchid"
384 "Orchid"
385 "dark orchid"
386 "DarkOrchid"
387 "medium orchid"
388 "MediumOrchid"
389 "pink"
390 "Pink"
391 "plum"
392 "Plum"
393 "red"
394 "Red"
395 "indian red"
396 "IndianRed"
397 "medium violet red"
398 "MediumVioletRed"
399 "orange red"
400 "OrangeRed"
401 "violet red"
402 "VioletRed"
403 "salmon"
404 "Salmon"
405 "sienna"
406 "Sienna"
407 "tan"
408 "Tan"
409 "thistle"
410 "Thistle"
411 "turquoise"
412 "Turquoise"
413 "dark turquoise"
414 "DarkTurquoise"
415 "medium turquoise"
416 "MediumTurquoise"
417 "violet"
418 "Violet"
419 "blue violet"
420 "BlueViolet"
421 "wheat"
422 "Wheat"
423 "white"
424 "White"
425 "yellow"
426 "Yellow"
427 "green yellow"
428 "GreenYellow")
5db9a09f 429 "The list of X colors from the `rgb.txt' file.")
63f77899 430
891eb3fe
RS
431(defun x-defined-colors (&optional frame)
432 "Return a list of colors supported for a particular frame.
433The argument FRAME specifies which frame to try.
434The value may be different for frames on different X displays."
435 (or frame (setq frame (selected-frame)))
63f77899
JB
436 (let ((all-colors x-colors)
437 (this-color nil)
438 (defined-colors nil))
439 (while all-colors
440 (setq this-color (car all-colors)
441 all-colors (cdr all-colors))
891eb3fe 442 (and (face-color-supported-p frame this-color t)
63f77899
JB
443 (setq defined-colors (cons this-color defined-colors))))
444 defined-colors))
63f77899 445\f
98bf0c8d
JB
446;;;; Function keys
447
2d7bfcc3
RS
448(defun iconify-or-deiconify-frame ()
449 "Iconify the selected frame, or deiconify if it's currently an icon."
450 (interactive)
451 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
452 (iconify-frame)
19479ae2 453 (make-frame-visible)))
2d7bfcc3
RS
454
455(substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
456 global-map)
e9de784c 457
3d80ef3f
RS
458;; Map certain keypad keys into ASCII characters
459;; that people usually expect.
460(define-key function-key-map [backspace] [127])
461(define-key function-key-map [delete] [127])
462(define-key function-key-map [tab] [?\t])
463(define-key function-key-map [linefeed] [?\n])
b8e9a326
RS
464(define-key function-key-map [clear] [?\C-l])
465(define-key function-key-map [return] [?\C-m])
3d80ef3f
RS
466(define-key function-key-map [escape] [?\e])
467(define-key function-key-map [M-backspace] [?\M-\d])
468(define-key function-key-map [M-delete] [?\M-\d])
469(define-key function-key-map [M-tab] [?\M-\t])
470(define-key function-key-map [M-linefeed] [?\M-\n])
b8e9a326
RS
471(define-key function-key-map [M-clear] [?\M-\C-l])
472(define-key function-key-map [M-return] [?\M-\C-m])
3d80ef3f 473(define-key function-key-map [M-escape] [?\M-\e])
87c033db 474(define-key function-key-map [iso-lefttab] [backtab])
3d80ef3f
RS
475
476;; These tell read-char how to convert
477;; these special chars to ASCII.
478(put 'backspace 'ascii-character 127)
479(put 'delete 'ascii-character 127)
480(put 'tab 'ascii-character ?\t)
481(put 'linefeed 'ascii-character ?\n)
482(put 'clear 'ascii-character 12)
483(put 'return 'ascii-character 13)
484(put 'escape 'ascii-character ?\e)
afa43349 485
9b4234ae
RS
486(defun vendor-specific-keysyms (vendor)
487 "Return the appropriate value of system-key-alist for VENDOR.
488VENDOR is a string containing the name of the X Server's vendor,
489as returned by (x-server-vendor)."
490 (cond ((string-equal vendor "Apollo Computer Inc.")
491 '((65280 . linedel)
492 (65281 . chardel)
493 (65282 . copy)
494 (65283 . cut)
495 (65284 . paste)
496 (65285 . move)
497 (65286 . grow)
498 (65287 . cmd)
499 (65288 . shell)
500 (65289 . leftbar)
501 (65290 . rightbar)
502 (65291 . leftbox)
503 (65292 . rightbox)
504 (65293 . upbox)
505 (65294 . downbox)
506 (65295 . pop)
507 (65296 . read)
508 (65297 . edit)
509 (65298 . save)
510 (65299 . exit)
511 (65300 . repeat)))
3f18a142
KH
512 ((or (string-equal vendor "Hewlett-Packard Incorporated")
513 (string-equal vendor "Hewlett-Packard Company"))
9b4234ae
RS
514 '(( 168 . mute-acute)
515 ( 169 . mute-grave)
516 ( 170 . mute-asciicircum)
517 ( 171 . mute-diaeresis)
518 ( 172 . mute-asciitilde)
519 ( 175 . lira)
520 ( 190 . guilder)
521 ( 252 . block)
522 ( 256 . longminus)
523 (65388 . reset)
524 (65389 . system)
525 (65390 . user)
526 (65391 . clearline)
527 (65392 . insertline)
528 (65393 . deleteline)
529 (65394 . insertchar)
530 (65395 . deletechar)
531 (65396 . backtab)
532 (65397 . kp-backtab)))
04486a2d
KH
533 ((or (string-equal vendor "X11/NeWS - Sun Microsystems Inc.")
534 (string-equal vendor "X Consortium"))
51a8e1cc
KH
535 '((392976 . f36)
536 (392977 . f37)
9b4234ae
RS
537 (393056 . req)
538 ;; These are for Sun under X11R6
539 (393072 . props)
540 (393073 . front)
541 (393074 . copy)
542 (393075 . open)
543 (393076 . paste)
544 (393077 . cut)))
545 (t
546 ;; This is used by DEC's X server.
547 '((65280 . remove)))))
548
2fb263f6
JB
549\f
550;;;; Selections and cut buffers
67c86cfc 551
daa37602
JB
552;;; We keep track of the last text selected here, so we can check the
553;;; current selection against it, and avoid passing back our own text
554;;; from x-cut-buffer-or-selection-value.
555(defvar x-last-selected-text nil)
556
2666a6a5 557;;; It is said that overlarge strings are slow to put into the cut buffer.
ef599142
RS
558;;; Note this value is overridden below.
559(defvar x-cut-buffer-max 20000
2666a6a5
RS
560 "Max number of characters to put in the cut buffer.")
561
dc20df95
RS
562(defvar x-select-enable-clipboard nil
563 "Non-nil means cutting and pasting uses the clipboard.
564This is in addition to the primary selection.")
565
2666a6a5 566;;; Make TEXT, a string, the primary X selection.
492878e4 567;;; Also, set the value of X cut buffer 0, for backward compatibility
d81fd0bf 568;;; with older X applications.
2666a6a5
RS
569;;; gildea@lcs.mit.edu says it's not desirable to put kills
570;;; in the clipboard.
0e2f4e59 571(defun x-select-text (text &optional push)
785080c5
RS
572 ;; Don't send the cut buffer too much text.
573 ;; It becomes slow, and if really big it causes errors.
574 (if (< (length text) x-cut-buffer-max)
2666a6a5 575 (x-set-cut-buffer text push)
14324c4d 576 (x-set-cut-buffer "" push))
c8c72d6b 577 (x-set-selection 'PRIMARY text)
dc20df95
RS
578 (if x-select-enable-clipboard
579 (x-set-selection 'CLIPBOARD text))
daa37602 580 (setq x-last-selected-text text))
492878e4 581
4390cc9c
KH
582;;; Return the value of the current X selection.
583;;; Consult the selection, then the cut buffer. Treat empty strings
584;;; as if they were unset.
d854d839
RS
585;;; If this function is called twice and finds the same text,
586;;; it returns nil the second time. This is so that a single
587;;; selection won't be added to the kill ring over and over.
492878e4 588(defun x-cut-buffer-or-selection-value ()
f6c7b4e7
JB
589 (let (text)
590
4390cc9c
KH
591 ;; Don't die if x-get-selection signals an error.
592 (condition-case c
8ba13581 593 (setq text (x-get-selection 'PRIMARY 'COMPOUND_TEXT))
5fd72a24 594 (error nil))
dc64c739
RS
595 (if (null text)
596 (condition-case c
597 (setq text (x-get-selection 'PRIMARY 'STRING))
598 (error nil)))
f6c7b4e7 599 (if (string= text "") (setq text nil))
8ba13581 600 (when x-select-enable-clipboard
dc64c739
RS
601 (if (null text)
602 (condition-case c
603 (setq text (x-get-selection 'CLIPBOARD 'COMPOUND_TEXT))
604 (error nil)))
605 (if (null text)
606 (condition-case c
607 (setq text (x-get-selection 'CLIPBOARD 'STRING))
608 (error nil)))
8ba13581
RS
609 (if (string= text "") (setq text nil)))
610
ef599142 611 (or text (setq text (x-get-cut-buffer 0)))
2666a6a5 612 (if (string= text "") (setq text nil))
f6c7b4e7
JB
613
614 (cond
615 ((not text) nil)
616 ((eq text x-last-selected-text) nil)
617 ((string= text x-last-selected-text)
618 ;; Record the newer string, so subsequent calls can use the `eq' test.
619 (setq x-last-selected-text text)
620 nil)
621 (t
622 (setq x-last-selected-text text)))))
492878e4 623
2fb263f6
JB
624\f
625;;; Do the actual X Windows setup here; the above code just defines
626;;; functions and variables that we use now.
627
628(setq command-line-args (x-handle-args command-line-args))
800642d2
JB
629
630;;; Make sure we have a valid resource name.
631(or (stringp x-resource-name)
632 (let (i)
633 (setq x-resource-name (invocation-name))
634
635 ;; Change any . or * characters in x-resource-name to hyphens,
636 ;; so as not to choke when we use it in X resource queries.
637 (while (setq i (string-match "[.*]" x-resource-name))
638 (aset x-resource-name i ?-))))
639
f1b648d6
KH
640;; For the benefit of older Emacses (19.27 and earlier) that are sharing
641;; the same lisp directory, don't pass the third argument unless we seem
642;; to have the multi-display support.
643(if (fboundp 'x-close-connection)
644 (x-open-connection (or x-display-name
645 (setq x-display-name (getenv "DISPLAY")))
646 x-command-line-resources
647 ;; Exit Emacs with fatal error if this fails.
648 t)
649 (x-open-connection (or x-display-name
650 (setq x-display-name (getenv "DISPLAY")))
651 x-command-line-resources))
2fb263f6 652
ffe1dd7a 653(setq frame-creation-function 'x-create-frame-with-faces)
3d80ef3f 654
ef599142
RS
655(setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
656 x-cut-buffer-max))
657
5afb8c58
RS
658(if (fboundp 'new-fontset)
659 (progn
9899214c 660 ;; Create the standard fontset.
25c343b2 661 (create-fontset-from-fontset-spec standard-fontset-spec t)
5afb8c58 662
b28ecb7d 663 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
5afb8c58
RS
664 (create-fontset-from-x-resource)
665
b28ecb7d
KH
666 ;; Try to create a fontset from a font specification which comes
667 ;; from initial-frame-alist, default-frame-alist, or X resource.
668 ;; A font specification in command line argument (i.e. -fn XXXX)
669 ;; should be already in default-frame-alist as a `font'
670 ;; parameter. However, any font specifications in site-start
671 ;; library, user's init file (.emacs), and default.el are not
672 ;; yet handled here.
5afb8c58
RS
673
674 (let ((font (or (cdr (assq 'font initial-frame-alist))
675 (cdr (assq 'font default-frame-alist))
b28ecb7d 676 (x-get-resource "font" "Font")))
68404bed 677 xlfd-fields resolved-name)
5afb8c58
RS
678 (if (and font
679 (not (query-fontset font))
68404bed 680 (setq resolved-name (x-resolve-font-name font))
1ca07425 681 (setq xlfd-fields (x-decompose-font-name font)))
9899214c
KH
682 (if (string= "fontset"
683 (aref xlfd-fields xlfd-regexp-registry-subnum))
684 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
12755baf
KH
685 ;; Create a fontset from FONT. The fontset name is
686 ;; generated from FONT. Create style variants of the
687 ;; fontset too. Font names in the variants are
688 ;; generated automatially unless X resources
689 ;; XXX.attribyteFont explicitly specify them.
690 (let ((styles (mapcar 'car x-style-funcs-alist))
691 (faces '(bold italic bold-italic))
692 face face-font fontset fontset-spec)
693 (while faces
694 (setq face (car faces))
695 (setq face-font (x-get-resource (concat (symbol-name face)
696 ".attributeFont")
697 "Face.AttributeFont"))
698 (if face-font
699 (setq styles (cons (cons face face-font)
700 (delq face styles))))
701 (setq faces (cdr faces)))
9899214c
KH
702 (aset xlfd-fields xlfd-regexp-foundry-subnum nil)
703 (aset xlfd-fields xlfd-regexp-family-subnum nil)
9899214c
KH
704 (aset xlfd-fields xlfd-regexp-registry-subnum "fontset")
705 (aset xlfd-fields xlfd-regexp-encoding-subnum "startup")
68404bed
KH
706 ;; The fontset name should have concrete values in
707 ;; weight and slant field.
708 (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
709 (slant (aref xlfd-fields xlfd-regexp-slant-subnum))
710 xlfd-temp)
711 (if (or (not weight) (string-match "[*?]*" weight))
712 (progn
713 (setq xlfd-temp (x-decompose-font-name resolved-name))
714 (aset xlfd-fields xlfd-regexp-weight-subnum
715 (aref xlfd-temp xlfd-regexp-weight-subnum))))
716 (if (or (not slant) (string-match "[*?]*" slant))
717 (progn
718 (or xlfd-temp
719 (setq xlfd-temp
720 (x-decompose-font-name resolved-name)))
721 (aset xlfd-fields xlfd-regexp-slant-subnum
722 (aref xlfd-temp xlfd-regexp-slant-subnum)))))
9899214c 723 (setq fontset (x-compose-font-name xlfd-fields))
12755baf
KH
724 (create-fontset-from-fontset-spec
725 (concat fontset ", ascii:" font) styles)
726 ))))))
f90080d4 727
5b0b2316 728;; Sun expects the menu bar cut and paste commands to use the clipboard.
5b3dd5e8 729;; This has ,? to match both on Sunos and on Solaris.
f81dbe56 730(if (string-match "Sun Microsystems,? Inc\\."
5b0b2316
RS
731 (x-server-vendor))
732 (menu-bar-enable-clipboard))
733
5d20eba6
JB
734;; Apply a geometry resource to the initial frame. Put it at the end
735;; of the alist, so that anything specified on the command line takes
736;; precedence.
e42a4b86
RS
737(let* ((res-geometry (x-get-resource "geometry" "Geometry"))
738 parsed)
5d20eba6 739 (if res-geometry
e42a4b86
RS
740 (progn
741 (setq parsed (x-parse-geometry res-geometry))
9b4234ae
RS
742 ;; If the resource specifies a position,
743 ;; call the position and size "user-specified".
744 (if (or (assq 'top parsed) (assq 'left parsed))
745 (setq parsed (cons '(user-position . t)
746 (cons '(user-size . t) parsed))))
e42a4b86
RS
747 ;; All geometry parms apply to the initial frame.
748 (setq initial-frame-alist (append initial-frame-alist parsed))
749 ;; The size parms apply to all frames.
750 (if (assq 'height parsed)
751 (setq default-frame-alist
752 (cons (cons 'height (cdr (assq 'height parsed)))
753 default-frame-alist)))
754 (if (assq 'width parsed)
755 (setq default-frame-alist
756 (cons (cons 'width (cdr (assq 'width parsed)))
757 default-frame-alist))))))
5d20eba6 758
88046be2 759;; Check the reverseVideo resource.
800642d2
JB
760(let ((case-fold-search t))
761 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
762 (if (and rv
763 (string-match "^\\(true\\|yes\\|on\\)$" rv))
764 (setq default-frame-alist
765 (cons '(reverse . t) default-frame-alist)))))
88046be2 766
553624bf
RS
767;; Set x-selection-timeout, measured in milliseconds.
768(let ((res-selection-timeout
769 (x-get-resource "selectionTimeout" "SelectionTimeout")))
5c2867e0 770 (setq x-selection-timeout 20000)
553624bf
RS
771 (if res-selection-timeout
772 (setq x-selection-timeout (string-to-number res-selection-timeout))))
773
3d80ef3f
RS
774(defun x-win-suspend-error ()
775 (error "Suspending an emacs running under X makes no sense"))
c8c72d6b
JB
776(add-hook 'suspend-hook 'x-win-suspend-error)
777
492878e4
JB
778;;; Arrange for the kill and yank functions to set and check the clipboard.
779(setq interprogram-cut-function 'x-select-text)
780(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
63c86e17 781
0cc6db57
JB
782;;; Turn off window-splitting optimization; X is usually fast enough
783;;; that this is only annoying.
784(setq split-window-keep-point t)
5cdb3f1e 785
53631723 786;; Don't show the frame name; that's redundant with X.
982fa4e5 787(setq-default mode-line-frame-identification " ")
53631723 788
740e13b3
RS
789;;; Motif direct handling of f10 wasn't working right,
790;;; So temporarily we've turned it off in lwlib-Xm.c
791;;; and turned the Emacs f10 back on.
792;;; ;; Motif normally handles f10 itself, so don't try to handle it a second time.
793;;; (if (featurep 'motif)
794;;; (global-set-key [f10] 'ignore))
9541a441 795
5cdb3f1e 796;;; x-win.el ends here