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