Commit | Line | Data |
---|---|---|
5cdb3f1e | 1 | ;;; x-win.el --- parse switches controlling interface with X window system |
cbc336a2 | 2 | ;; Copyright (C) 1993 Free Software Foundation, Inc. |
5cdb3f1e ER |
3 | |
4 | ;; Author: FSF | |
5 | ;; Keywords: terminals | |
6 | ||
cbc336a2 RS |
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. | |
63f77899 | 22 | |
5cdb3f1e | 23 | ;;; Commentary: |
63f77899 JB |
24 | |
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. | |
29 | ||
30 | ;; startup.el will then examine startup files, and eventually call the hooks | |
31 | ;; which create the first window (s). | |
5cdb3f1e ER |
32 | |
33 | ;;; Code: | |
63f77899 JB |
34 | \f |
35 | ;; These are the standard X switches from the Xt Initialize.c file of | |
36 | ;; Release 4. | |
37 | ||
38 | ;; Command line Resource Manager string | |
39 | ||
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 | |
db176f55 JB |
54 | ;; -i .iconType |
55 | ;; -itype .iconType | |
63f77899 JB |
56 | ;; -iconic .iconic |
57 | ;; -name .name | |
58 | ;; -reverse *reverseVideo | |
59 | ;; -rv *reverseVideo | |
60 | ;; -selectionTimeout .selectionTimeout | |
61 | ;; -synchronous *synchronous | |
63f77899 JB |
62 | ;; -xrm |
63 | ||
63f77899 JB |
64 | ;; An alist of X options and the function which handles them. See |
65 | ;; ../startup.el. | |
66 | ||
63c86e17 | 67 | (if (not (eq window-system 'x)) |
800642d2 | 68 | (error "%s: Loading x-win.el but not compiled for X" (invocation-name))) |
63c86e17 | 69 | |
0cc89026 | 70 | (require 'frame) |
3eb43f71 | 71 | (require 'mouse) |
b16795eb | 72 | (require 'scroll-bar) |
ffe1dd7a JB |
73 | (require 'faces) |
74 | (require 'select) | |
290cb602 | 75 | (require 'menu-bar) |
63c86e17 | 76 | |
19b08de9 RS |
77 | (defvar x-invocation-args) |
78 | ||
f6f6d98c RS |
79 | (defvar x-command-line-resources nil) |
80 | ||
63f77899 | 81 | (setq command-switch-alist |
708c60f8 | 82 | (append '(("-bw" . x-handle-numeric-switch) |
63c86e17 JB |
83 | ("-d" . x-handle-display) |
84 | ("-display" . x-handle-display) | |
800642d2 JB |
85 | ("-name" . x-handle-name-rn-switch) |
86 | ("-rn" . x-handle-name-rn-switch) | |
63c86e17 JB |
87 | ("-T" . x-handle-switch) |
88 | ("-r" . x-handle-switch) | |
89 | ("-rv" . x-handle-switch) | |
90 | ("-reverse" . x-handle-switch) | |
91 | ("-fn" . x-handle-switch) | |
92 | ("-font" . x-handle-switch) | |
878a0827 | 93 | ("-ib" . x-handle-numeric-switch) |
63c86e17 JB |
94 | ("-g" . x-handle-geometry) |
95 | ("-geometry" . x-handle-geometry) | |
96 | ("-fg" . x-handle-switch) | |
97 | ("-foreground". x-handle-switch) | |
98 | ("-bg" . x-handle-switch) | |
99 | ("-background". x-handle-switch) | |
100 | ("-ms" . x-handle-switch) | |
7b937caf | 101 | ("-itype" . x-handle-switch) |
db176f55 | 102 | ("-i" . x-handle-switch) |
ef599142 | 103 | ("-iconic" . x-handle-iconic) |
800642d2 | 104 | ("-xrm" . x-handle-xrm-switch) |
63c86e17 JB |
105 | ("-cr" . x-handle-switch) |
106 | ("-vb" . x-handle-switch) | |
107 | ("-hb" . x-handle-switch) | |
108 | ("-bd" . x-handle-switch)) | |
63f77899 JB |
109 | command-switch-alist)) |
110 | ||
63f77899 JB |
111 | (defconst x-switch-definitions |
112 | '(("-name" name) | |
113 | ("-T" name) | |
e6299e30 JB |
114 | ("-r" reverse t) |
115 | ("-rv" reverse t) | |
116 | ("-reverse" reverse t) | |
63f77899 JB |
117 | ("-fn" font) |
118 | ("-font" font) | |
119 | ("-ib" internal-border-width) | |
120 | ("-fg" foreground-color) | |
121 | ("-foreground" foreground-color) | |
122 | ("-bg" background-color) | |
123 | ("-background" background-color) | |
124 | ("-ms" mouse-color) | |
125 | ("-cr" cursor-color) | |
7b937caf | 126 | ("-itype" icon-type t) |
db176f55 | 127 | ("-i" icon-type t) |
0a68e87b JB |
128 | ("-vb" vertical-scroll-bars t) |
129 | ("-hb" horizontal-scroll-bars t) | |
63f77899 JB |
130 | ("-bd" border-color) |
131 | ("-bw" border-width))) | |
132 | ||
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) | |
0cc89026 | 138 | (setq default-frame-alist |
63f77899 | 139 | (cons (cons (nth 1 aelt) (nth 2 aelt)) |
0cc89026 JB |
140 | default-frame-alist)) |
141 | (setq default-frame-alist | |
63f77899 JB |
142 | (cons (cons (nth 1 aelt) |
143 | (car x-invocation-args)) | |
0cc89026 | 144 | default-frame-alist) |
63f77899 JB |
145 | x-invocation-args (cdr x-invocation-args)))))) |
146 | ||
ef599142 RS |
147 | ;; Make -iconic apply only to the initial frame! |
148 | (defun x-handle-iconic (switch) | |
149 | (setq initial-frame-alist | |
150 | (cons '(visibility . icon) initial-frame-alist))) | |
151 | ||
63f77899 JB |
152 | ;; Handler for switches of the form "-switch n" |
153 | (defun x-handle-numeric-switch (switch) | |
154 | (let ((aelt (assoc switch x-switch-definitions))) | |
155 | (if aelt | |
0cc89026 | 156 | (setq default-frame-alist |
63f77899 JB |
157 | (cons (cons (nth 1 aelt) |
158 | (string-to-int (car x-invocation-args))) | |
0cc89026 | 159 | default-frame-alist) |
63f77899 JB |
160 | x-invocation-args |
161 | (cdr x-invocation-args))))) | |
162 | ||
800642d2 JB |
163 | ;; Handle the -xrm option. |
164 | (defun x-handle-xrm-switch (switch) | |
165 | (or (consp x-invocation-args) | |
166 | (error "%s: missing argument to `%s' option" (invocation-name) switch)) | |
f6f6d98c RS |
167 | (setq x-command-line-resources (car x-invocation-args)) |
168 | (setq x-invocation-args (cdr x-invocation-args))) | |
169 | ||
63f77899 JB |
170 | ;; Handle the geometry option |
171 | (defun x-handle-geometry (switch) | |
847f5dab JB |
172 | (setq initial-frame-alist |
173 | (append initial-frame-alist | |
174 | (x-parse-geometry (car x-invocation-args))) | |
63f77899 JB |
175 | x-invocation-args (cdr x-invocation-args))) |
176 | ||
800642d2 JB |
177 | ;; Handle the -name and -rn options. Set the variable x-resource-name |
178 | ;; to the option's operand; if the switch was `-name', set the name of | |
179 | ;; the initial frame, too. | |
180 | (defun x-handle-name-rn-switch (switch) | |
181 | (or (consp x-invocation-args) | |
182 | (error "%s: missing argument to `%s' option" (invocation-name) switch)) | |
183 | (setq x-resource-name (car x-invocation-args) | |
184 | x-invocation-args (cdr x-invocation-args)) | |
185 | (if (string= switch "-name") | |
186 | (setq initial-frame-alist (cons (cons 'name x-resource-name) | |
187 | initial-frame-alist)))) | |
188 | ||
63f77899 | 189 | (defvar x-display-name nil |
0cc89026 | 190 | "The X display name specifying server and X frame.") |
63f77899 JB |
191 | |
192 | (defun x-handle-display (switch) | |
193 | (setq x-display-name (car x-invocation-args) | |
194 | x-invocation-args (cdr x-invocation-args))) | |
195 | ||
63f77899 JB |
196 | (defvar x-invocation-args nil) |
197 | ||
8769d648 JB |
198 | (defun x-handle-args (args) |
199 | "Here the X-related command line options in ARGS are processed, | |
200 | before the user's startup file is loaded. They are copied to | |
201 | x-invocation args from which the X-related things are extracted, first | |
202 | the switch (e.g., \"-fg\") in the following code, and possible values | |
203 | (e.g., \"black\") in the option handler code (e.g., x-handle-switch). | |
204 | This returns ARGS with the arguments that have been processed removed." | |
63c86e17 JB |
205 | (setq x-invocation-args args |
206 | args nil) | |
207 | (while x-invocation-args | |
208 | (let* ((this-switch (car x-invocation-args)) | |
209 | (aelt (assoc this-switch command-switch-alist))) | |
210 | (setq x-invocation-args (cdr x-invocation-args)) | |
211 | (if aelt | |
212 | (funcall (cdr aelt) this-switch) | |
213 | (setq args (cons this-switch args))))) | |
214 | (setq args (nreverse args))) | |
215 | ||
b54621ea | 216 | |
63f77899 JB |
217 | \f |
218 | ;; | |
219 | ;; Standard X cursor shapes, courtesy of Mr. Fox, who wanted ALL of them. | |
220 | ;; | |
221 | ||
222 | (defconst x-pointer-X-cursor 0) | |
223 | (defconst x-pointer-arrow 2) | |
224 | (defconst x-pointer-based-arrow-down 4) | |
225 | (defconst x-pointer-based-arrow-up 6) | |
226 | (defconst x-pointer-boat 8) | |
227 | (defconst x-pointer-bogosity 10) | |
228 | (defconst x-pointer-bottom-left-corner 12) | |
229 | (defconst x-pointer-bottom-right-corner 14) | |
230 | (defconst x-pointer-bottom-side 16) | |
231 | (defconst x-pointer-bottom-tee 18) | |
232 | (defconst x-pointer-box-spiral 20) | |
233 | (defconst x-pointer-center-ptr 22) | |
234 | (defconst x-pointer-circle 24) | |
235 | (defconst x-pointer-clock 26) | |
236 | (defconst x-pointer-coffee-mug 28) | |
237 | (defconst x-pointer-cross 30) | |
238 | (defconst x-pointer-cross-reverse 32) | |
239 | (defconst x-pointer-crosshair 34) | |
240 | (defconst x-pointer-diamond-cross 36) | |
241 | (defconst x-pointer-dot 38) | |
242 | (defconst x-pointer-dotbox 40) | |
243 | (defconst x-pointer-double-arrow 42) | |
244 | (defconst x-pointer-draft-large 44) | |
245 | (defconst x-pointer-draft-small 46) | |
246 | (defconst x-pointer-draped-box 48) | |
247 | (defconst x-pointer-exchange 50) | |
248 | (defconst x-pointer-fleur 52) | |
249 | (defconst x-pointer-gobbler 54) | |
250 | (defconst x-pointer-gumby 56) | |
251 | (defconst x-pointer-hand1 58) | |
252 | (defconst x-pointer-hand2 60) | |
253 | (defconst x-pointer-heart 62) | |
254 | (defconst x-pointer-icon 64) | |
255 | (defconst x-pointer-iron-cross 66) | |
256 | (defconst x-pointer-left-ptr 68) | |
257 | (defconst x-pointer-left-side 70) | |
258 | (defconst x-pointer-left-tee 72) | |
259 | (defconst x-pointer-leftbutton 74) | |
260 | (defconst x-pointer-ll-angle 76) | |
261 | (defconst x-pointer-lr-angle 78) | |
262 | (defconst x-pointer-man 80) | |
263 | (defconst x-pointer-middlebutton 82) | |
264 | (defconst x-pointer-mouse 84) | |
265 | (defconst x-pointer-pencil 86) | |
266 | (defconst x-pointer-pirate 88) | |
267 | (defconst x-pointer-plus 90) | |
268 | (defconst x-pointer-question-arrow 92) | |
269 | (defconst x-pointer-right-ptr 94) | |
270 | (defconst x-pointer-right-side 96) | |
271 | (defconst x-pointer-right-tee 98) | |
272 | (defconst x-pointer-rightbutton 100) | |
273 | (defconst x-pointer-rtl-logo 102) | |
274 | (defconst x-pointer-sailboat 104) | |
275 | (defconst x-pointer-sb-down-arrow 106) | |
276 | (defconst x-pointer-sb-h-double-arrow 108) | |
277 | (defconst x-pointer-sb-left-arrow 110) | |
278 | (defconst x-pointer-sb-right-arrow 112) | |
279 | (defconst x-pointer-sb-up-arrow 114) | |
280 | (defconst x-pointer-sb-v-double-arrow 116) | |
281 | (defconst x-pointer-shuttle 118) | |
282 | (defconst x-pointer-sizing 120) | |
283 | (defconst x-pointer-spider 122) | |
284 | (defconst x-pointer-spraycan 124) | |
285 | (defconst x-pointer-star 126) | |
286 | (defconst x-pointer-target 128) | |
287 | (defconst x-pointer-tcross 130) | |
288 | (defconst x-pointer-top-left-arrow 132) | |
289 | (defconst x-pointer-top-left-corner 134) | |
290 | (defconst x-pointer-top-right-corner 136) | |
291 | (defconst x-pointer-top-side 138) | |
292 | (defconst x-pointer-top-tee 140) | |
293 | (defconst x-pointer-trek 142) | |
294 | (defconst x-pointer-ul-angle 144) | |
295 | (defconst x-pointer-umbrella 146) | |
296 | (defconst x-pointer-ur-angle 148) | |
297 | (defconst x-pointer-watch 150) | |
298 | (defconst x-pointer-xterm 152) | |
299 | \f | |
300 | ;; | |
301 | ;; Available colors | |
302 | ;; | |
303 | ||
304 | (defvar x-colors '("aquamarine" | |
305 | "Aquamarine" | |
306 | "medium aquamarine" | |
307 | "MediumAquamarine" | |
308 | "black" | |
309 | "Black" | |
310 | "blue" | |
311 | "Blue" | |
312 | "cadet blue" | |
313 | "CadetBlue" | |
314 | "cornflower blue" | |
315 | "CornflowerBlue" | |
316 | "dark slate blue" | |
317 | "DarkSlateBlue" | |
318 | "light blue" | |
319 | "LightBlue" | |
320 | "light steel blue" | |
321 | "LightSteelBlue" | |
322 | "medium blue" | |
323 | "MediumBlue" | |
324 | "medium slate blue" | |
325 | "MediumSlateBlue" | |
326 | "midnight blue" | |
327 | "MidnightBlue" | |
328 | "navy blue" | |
329 | "NavyBlue" | |
330 | "navy" | |
331 | "Navy" | |
332 | "sky blue" | |
333 | "SkyBlue" | |
334 | "slate blue" | |
335 | "SlateBlue" | |
336 | "steel blue" | |
337 | "SteelBlue" | |
338 | "coral" | |
339 | "Coral" | |
340 | "cyan" | |
341 | "Cyan" | |
342 | "firebrick" | |
343 | "Firebrick" | |
344 | "brown" | |
345 | "Brown" | |
346 | "gold" | |
347 | "Gold" | |
348 | "goldenrod" | |
349 | "Goldenrod" | |
350 | "medium goldenrod" | |
351 | "MediumGoldenrod" | |
352 | "green" | |
353 | "Green" | |
354 | "dark green" | |
355 | "DarkGreen" | |
356 | "dark olive green" | |
357 | "DarkOliveGreen" | |
358 | "forest green" | |
359 | "ForestGreen" | |
360 | "lime green" | |
361 | "LimeGreen" | |
362 | "medium forest green" | |
363 | "MediumForestGreen" | |
364 | "medium sea green" | |
365 | "MediumSeaGreen" | |
366 | "medium spring green" | |
367 | "MediumSpringGreen" | |
368 | "pale green" | |
369 | "PaleGreen" | |
370 | "sea green" | |
371 | "SeaGreen" | |
372 | "spring green" | |
373 | "SpringGreen" | |
374 | "yellow green" | |
375 | "YellowGreen" | |
376 | "dark slate grey" | |
377 | "DarkSlateGrey" | |
378 | "dark slate gray" | |
379 | "DarkSlateGray" | |
380 | "dim grey" | |
381 | "DimGrey" | |
382 | "dim gray" | |
383 | "DimGray" | |
384 | "light grey" | |
385 | "LightGrey" | |
386 | "light gray" | |
387 | "LightGray" | |
388 | "gray" | |
389 | "grey" | |
390 | "Gray" | |
391 | "Grey" | |
392 | "khaki" | |
393 | "Khaki" | |
394 | "magenta" | |
395 | "Magenta" | |
396 | "maroon" | |
397 | "Maroon" | |
398 | "orange" | |
399 | "Orange" | |
400 | "orchid" | |
401 | "Orchid" | |
402 | "dark orchid" | |
403 | "DarkOrchid" | |
404 | "medium orchid" | |
405 | "MediumOrchid" | |
406 | "pink" | |
407 | "Pink" | |
408 | "plum" | |
409 | "Plum" | |
410 | "red" | |
411 | "Red" | |
412 | "indian red" | |
413 | "IndianRed" | |
414 | "medium violet red" | |
415 | "MediumVioletRed" | |
416 | "orange red" | |
417 | "OrangeRed" | |
418 | "violet red" | |
419 | "VioletRed" | |
420 | "salmon" | |
421 | "Salmon" | |
422 | "sienna" | |
423 | "Sienna" | |
424 | "tan" | |
425 | "Tan" | |
426 | "thistle" | |
427 | "Thistle" | |
428 | "turquoise" | |
429 | "Turquoise" | |
430 | "dark turquoise" | |
431 | "DarkTurquoise" | |
432 | "medium turquoise" | |
433 | "MediumTurquoise" | |
434 | "violet" | |
435 | "Violet" | |
436 | "blue violet" | |
437 | "BlueViolet" | |
438 | "wheat" | |
439 | "Wheat" | |
440 | "white" | |
441 | "White" | |
442 | "yellow" | |
443 | "Yellow" | |
444 | "green yellow" | |
445 | "GreenYellow") | |
446 | "The full list of X colors from the rgb.text file.") | |
447 | ||
448 | (defun x-defined-colors () | |
449 | "Return a list of colors supported by the current X-Display." | |
450 | (let ((all-colors x-colors) | |
451 | (this-color nil) | |
452 | (defined-colors nil)) | |
453 | (while all-colors | |
454 | (setq this-color (car all-colors) | |
455 | all-colors (cdr all-colors)) | |
847f5dab | 456 | (and (x-color-defined-p this-color) |
63f77899 JB |
457 | (setq defined-colors (cons this-color defined-colors)))) |
458 | defined-colors)) | |
63f77899 | 459 | \f |
98bf0c8d JB |
460 | ;;;; Function keys |
461 | ||
2d7bfcc3 RS |
462 | (defun iconify-or-deiconify-frame () |
463 | "Iconify the selected frame, or deiconify if it's currently an icon." | |
464 | (interactive) | |
465 | (if (eq (cdr (assq 'visibility (frame-parameters))) t) | |
466 | (iconify-frame) | |
8a96eef3 | 467 | (let ((foo (selected-frame))) |
2bd866cd | 468 | (make-frame-invisible foo t) |
8a96eef3 | 469 | (make-frame-visible foo)))) |
2d7bfcc3 RS |
470 | |
471 | (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame | |
472 | global-map) | |
e9de784c | 473 | |
3d80ef3f RS |
474 | ;; Map certain keypad keys into ASCII characters |
475 | ;; that people usually expect. | |
476 | (define-key function-key-map [backspace] [127]) | |
477 | (define-key function-key-map [delete] [127]) | |
478 | (define-key function-key-map [tab] [?\t]) | |
479 | (define-key function-key-map [linefeed] [?\n]) | |
480 | (define-key function-key-map [clear] [11]) | |
481 | (define-key function-key-map [return] [13]) | |
482 | (define-key function-key-map [escape] [?\e]) | |
483 | (define-key function-key-map [M-backspace] [?\M-\d]) | |
484 | (define-key function-key-map [M-delete] [?\M-\d]) | |
485 | (define-key function-key-map [M-tab] [?\M-\t]) | |
486 | (define-key function-key-map [M-linefeed] [?\M-\n]) | |
487 | (define-key function-key-map [M-clear] [?\M-\013]) | |
488 | (define-key function-key-map [M-return] [?\M-\015]) | |
489 | (define-key function-key-map [M-escape] [?\M-\e]) | |
490 | ||
491 | ;; These tell read-char how to convert | |
492 | ;; these special chars to ASCII. | |
493 | (put 'backspace 'ascii-character 127) | |
494 | (put 'delete 'ascii-character 127) | |
495 | (put 'tab 'ascii-character ?\t) | |
496 | (put 'linefeed 'ascii-character ?\n) | |
497 | (put 'clear 'ascii-character 12) | |
498 | (put 'return 'ascii-character 13) | |
499 | (put 'escape 'ascii-character ?\e) | |
afa43349 | 500 | |
96d63b2c RS |
501 | ;; Set up to recognize vendor-specific keysyms. |
502 | ;; Unless/until there is a real conflict, | |
503 | ;; we need not try to make this list depend on | |
504 | ;; the type of X server in use. | |
52f04d46 | 505 | (setq system-key-alist |
afa43349 RS |
506 | '( |
507 | ;; These are some HP keys. | |
96d63b2c RS |
508 | ( 168 . mute-acute) |
509 | ( 169 . mute-grave) | |
510 | ( 170 . mute-asciicircum) | |
511 | ( 171 . mute-diaeresis) | |
512 | ( 172 . mute-asciitilde) | |
513 | ( 175 . lira) | |
514 | ( 190 . guilder) | |
515 | ( 252 . block) | |
516 | ( 256 . longminus) | |
afa43349 RS |
517 | (65388 . reset) |
518 | (65389 . system) | |
519 | (65390 . user) | |
520 | (65391 . clearline) | |
521 | (65392 . insertline) | |
522 | (65393 . deleteline) | |
523 | (65394 . insertchar) | |
524 | (65395 . deletechar) | |
525 | (65396 . backtab) | |
526 | (65397 . kp-backtab) | |
527 | ;; This is used on some system or other. | |
528 | (0 . remove) | |
96d63b2c RS |
529 | ;; These are for Sun. |
530 | (392976 . f35) | |
531 | (392977 . f36) | |
b03f6d38 | 532 | (393056 . req) |
afa43349 | 533 | )) |
2fb263f6 JB |
534 | \f |
535 | ;;;; Selections and cut buffers | |
67c86cfc | 536 | |
daa37602 JB |
537 | ;;; We keep track of the last text selected here, so we can check the |
538 | ;;; current selection against it, and avoid passing back our own text | |
539 | ;;; from x-cut-buffer-or-selection-value. | |
540 | (defvar x-last-selected-text nil) | |
541 | ||
2666a6a5 | 542 | ;;; It is said that overlarge strings are slow to put into the cut buffer. |
ef599142 RS |
543 | ;;; Note this value is overridden below. |
544 | (defvar x-cut-buffer-max 20000 | |
2666a6a5 RS |
545 | "Max number of characters to put in the cut buffer.") |
546 | ||
547 | ;;; Make TEXT, a string, the primary X selection. | |
492878e4 | 548 | ;;; Also, set the value of X cut buffer 0, for backward compatibility |
d81fd0bf | 549 | ;;; with older X applications. |
2666a6a5 RS |
550 | ;;; gildea@lcs.mit.edu says it's not desirable to put kills |
551 | ;;; in the clipboard. | |
0e2f4e59 | 552 | (defun x-select-text (text &optional push) |
785080c5 RS |
553 | ;; Don't send the cut buffer too much text. |
554 | ;; It becomes slow, and if really big it causes errors. | |
555 | (if (< (length text) x-cut-buffer-max) | |
2666a6a5 | 556 | (x-set-cut-buffer text push) |
14324c4d | 557 | (x-set-cut-buffer "" push)) |
c8c72d6b | 558 | (x-set-selection 'PRIMARY text) |
daa37602 | 559 | (setq x-last-selected-text text)) |
492878e4 JB |
560 | |
561 | ;;; Return the value of the current X selection. For compatibility | |
562 | ;;; with older X applications, this checks cut buffer 0 before | |
563 | ;;; retrieving the value of the primary selection. | |
564 | (defun x-cut-buffer-or-selection-value () | |
f6c7b4e7 JB |
565 | (let (text) |
566 | ||
2666a6a5 | 567 | ;; Consult the selection, then the cut buffer. Treat empty strings |
f6c7b4e7 | 568 | ;; as if they were unset. |
ef599142 | 569 | (setq text (x-get-selection 'PRIMARY)) |
f6c7b4e7 | 570 | (if (string= text "") (setq text nil)) |
ef599142 | 571 | (or text (setq text (x-get-cut-buffer 0))) |
2666a6a5 | 572 | (if (string= text "") (setq text nil)) |
f6c7b4e7 JB |
573 | |
574 | (cond | |
575 | ((not text) nil) | |
576 | ((eq text x-last-selected-text) nil) | |
577 | ((string= text x-last-selected-text) | |
578 | ;; Record the newer string, so subsequent calls can use the `eq' test. | |
579 | (setq x-last-selected-text text) | |
580 | nil) | |
581 | (t | |
582 | (setq x-last-selected-text text))))) | |
492878e4 | 583 | |
2fb263f6 JB |
584 | \f |
585 | ;;; Do the actual X Windows setup here; the above code just defines | |
586 | ;;; functions and variables that we use now. | |
587 | ||
588 | (setq command-line-args (x-handle-args command-line-args)) | |
800642d2 JB |
589 | |
590 | ;;; Make sure we have a valid resource name. | |
591 | (or (stringp x-resource-name) | |
592 | (let (i) | |
593 | (setq x-resource-name (invocation-name)) | |
594 | ||
595 | ;; Change any . or * characters in x-resource-name to hyphens, | |
596 | ;; so as not to choke when we use it in X resource queries. | |
597 | (while (setq i (string-match "[.*]" x-resource-name)) | |
598 | (aset x-resource-name i ?-)))) | |
599 | ||
2fb263f6 | 600 | (x-open-connection (or x-display-name |
f6f6d98c RS |
601 | (setq x-display-name (getenv "DISPLAY"))) |
602 | x-command-line-resources) | |
2fb263f6 | 603 | |
ffe1dd7a | 604 | (setq frame-creation-function 'x-create-frame-with-faces) |
3d80ef3f | 605 | |
ef599142 RS |
606 | (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100) |
607 | x-cut-buffer-max)) | |
608 | ||
5d20eba6 JB |
609 | ;; Apply a geometry resource to the initial frame. Put it at the end |
610 | ;; of the alist, so that anything specified on the command line takes | |
611 | ;; precedence. | |
612 | (let ((res-geometry (x-get-resource "geometry" "Geometry"))) | |
613 | (if res-geometry | |
614 | (setq initial-frame-alist (append initial-frame-alist | |
615 | (x-parse-geometry res-geometry))))) | |
616 | ||
88046be2 | 617 | ;; Check the reverseVideo resource. |
800642d2 JB |
618 | (let ((case-fold-search t)) |
619 | (let ((rv (x-get-resource "reverseVideo" "ReverseVideo"))) | |
620 | (if (and rv | |
621 | (string-match "^\\(true\\|yes\\|on\\)$" rv)) | |
622 | (setq default-frame-alist | |
623 | (cons '(reverse . t) default-frame-alist))))) | |
88046be2 | 624 | |
553624bf RS |
625 | ;; Set x-selection-timeout, measured in milliseconds. |
626 | (let ((res-selection-timeout | |
627 | (x-get-resource "selectionTimeout" "SelectionTimeout"))) | |
5c2867e0 | 628 | (setq x-selection-timeout 20000) |
553624bf RS |
629 | (if res-selection-timeout |
630 | (setq x-selection-timeout (string-to-number res-selection-timeout)))) | |
631 | ||
3d80ef3f RS |
632 | (defun x-win-suspend-error () |
633 | (error "Suspending an emacs running under X makes no sense")) | |
c8c72d6b JB |
634 | (add-hook 'suspend-hook 'x-win-suspend-error) |
635 | ||
492878e4 JB |
636 | ;;; Arrange for the kill and yank functions to set and check the clipboard. |
637 | (setq interprogram-cut-function 'x-select-text) | |
638 | (setq interprogram-paste-function 'x-cut-buffer-or-selection-value) | |
63c86e17 | 639 | |
0cc6db57 JB |
640 | ;;; Turn off window-splitting optimization; X is usually fast enough |
641 | ;;; that this is only annoying. | |
642 | (setq split-window-keep-point t) | |
5cdb3f1e ER |
643 | |
644 | ;;; x-win.el ends here |