1 ;;; x-win.el --- parse switches controlling interface with X window system
3 ;; Copyright (C) 1993, 1994, 2001, 2002 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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)
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.
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.
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.
32 ;; startup.el will then examine startup files, and eventually call the hooks
33 ;; which create the first window (s).
37 ;; These are the standard X switches from the Xt Initialize.c file of
40 ;; Command line Resource Manager string
43 ;; +synchronous *synchronous
44 ;; -background *background
47 ;; -bordercolor *borderColor
48 ;; -borderwidth .borderWidth
54 ;; -foreground *foreground
55 ;; -geometry .geometry
60 ;; -reverse *reverseVideo
62 ;; -selectionTimeout .selectionTimeout
63 ;; -synchronous *synchronous
66 ;; An alist of X options and the function which handles them. See
69 (if (not (eq window-system
'x
))
70 (error "%s: Loading x-win.el but not compiled for X" (invocation-name)))
78 (if (fboundp 'new-fontset
)
81 (defvar x-invocation-args
)
83 (defvar x-command-line-resources nil
)
85 ;; Handler for switches of the form "-switch value" or "-switch".
86 (defun x-handle-switch (switch)
87 (let ((aelt (assoc switch command-line-x-option-alist
)))
89 (let ((param (nth 3 aelt
))
92 (setq default-frame-alist
93 (cons (cons param value
)
95 (setq default-frame-alist
97 (car x-invocation-args
))
99 x-invocation-args
(cdr x-invocation-args
)))))))
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
)))
105 (let ((param (nth 3 aelt
)))
106 (setq default-frame-alist
108 (string-to-int (car x-invocation-args
)))
111 (cdr x-invocation-args
))))))
113 ;; Handle options that apply to initial frame only
114 (defun x-handle-initial-switch (switch)
115 (let ((aelt (assoc switch command-line-x-option-alist
)))
117 (let ((param (nth 3 aelt
))
118 (value (nth 4 aelt
)))
120 (setq initial-frame-alist
121 (cons (cons param value
)
122 initial-frame-alist
))
123 (setq initial-frame-alist
125 (car x-invocation-args
))
127 x-invocation-args
(cdr x-invocation-args
)))))))
129 ;; Make -iconic apply only to the initial frame!
130 (defun x-handle-iconic (switch)
131 (setq initial-frame-alist
132 (cons '(visibility . icon
) initial-frame-alist
)))
134 ;; Handle the -xrm option.
135 (defun x-handle-xrm-switch (switch)
136 (unless (consp x-invocation-args
)
137 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
138 (setq x-command-line-resources
139 (if (null x-command-line-resources
)
140 (car x-invocation-args
)
141 (concat x-command-line-resources
"\n" (car x-invocation-args
))))
142 (setq x-invocation-args
(cdr x-invocation-args
)))
144 ;; Handle the geometry option
145 (defun x-handle-geometry (switch)
146 (let* ((geo (x-parse-geometry (car x-invocation-args
)))
147 (left (assq 'left geo
))
148 (top (assq 'top geo
))
149 (height (assq 'height geo
))
150 (width (assq 'width geo
)))
151 (if (or height width
)
152 (setq default-frame-alist
153 (append default-frame-alist
155 (if height
(list height
))
156 (if width
(list width
)))
158 (append initial-frame-alist
160 (if height
(list height
))
161 (if width
(list width
)))))
163 (setq initial-frame-alist
164 (append initial-frame-alist
165 '((user-position . t
))
166 (if left
(list left
))
167 (if top
(list top
)))))
168 (setq x-invocation-args
(cdr x-invocation-args
))))
170 ;; Handle the -name option. Set the variable x-resource-name
171 ;; to the option's operand; set the name of
172 ;; the initial frame, too.
173 (defun x-handle-name-switch (switch)
174 (or (consp x-invocation-args
)
175 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
176 (setq x-resource-name
(car x-invocation-args
)
177 x-invocation-args
(cdr x-invocation-args
))
178 (setq initial-frame-alist
(cons (cons 'name x-resource-name
)
179 initial-frame-alist
)))
181 (defvar x-display-name nil
182 "The X display name specifying server and X frame.")
184 (defun x-handle-display (switch)
185 (setq x-display-name
(car x-invocation-args
)
186 x-invocation-args
(cdr x-invocation-args
))
187 ;; Make subshell programs see the same DISPLAY value Emacs really uses.
188 ;; Note that this isn't completely correct, since Emacs can use
189 ;; multiple displays. However, there is no way to tell an already
190 ;; running subshell which display the user is currently typing on.
191 (setenv "DISPLAY" x-display-name
))
193 (defun x-handle-args (args)
194 "Process the X-related command line options in ARGS.
195 This is done before the user's startup file is loaded. They are copied to
196 `x-invocation-args', from which the X-related things are extracted, first
197 the switch (e.g., \"-fg\") in the following code, and possible values
198 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
199 This function returns ARGS minus the arguments that have been processed."
200 ;; We use ARGS to accumulate the args that we don't handle here, to return.
201 (setq x-invocation-args args
203 (while (and x-invocation-args
204 (not (equal (car x-invocation-args
) "--")))
205 (let* ((this-switch (car x-invocation-args
))
206 (orig-this-switch this-switch
)
207 completion argval aelt handler
)
208 (setq x-invocation-args
(cdr x-invocation-args
))
209 ;; Check for long options with attached arguments
210 ;; and separate out the attached option argument into argval.
211 (if (string-match "^--[^=]*=" this-switch
)
212 (setq argval
(substring this-switch
(match-end 0))
213 this-switch
(substring this-switch
0 (1- (match-end 0)))))
214 ;; Complete names of long options.
215 (if (string-match "^--" this-switch
)
217 (setq completion
(try-completion this-switch command-line-x-option-alist
))
218 (if (eq completion t
)
219 ;; Exact match for long option.
221 (if (stringp completion
)
222 (let ((elt (assoc completion command-line-x-option-alist
)))
223 ;; Check for abbreviated long option.
225 (error "Option `%s' is ambiguous" this-switch
))
226 (setq this-switch completion
))))))
227 (setq aelt
(assoc this-switch command-line-x-option-alist
))
228 (if aelt
(setq handler
(nth 2 aelt
)))
231 (let ((x-invocation-args
232 (cons argval x-invocation-args
)))
233 (funcall handler this-switch
))
234 (funcall handler this-switch
))
235 (setq args
(cons orig-this-switch args
)))))
236 (nconc (nreverse args
) x-invocation-args
))
238 ;; Handle the --smid switch. This is used by the session manager
239 ;; to give us back our session id we had on the previous run.
240 (defun x-handle-smid (switch)
241 (or (consp x-invocation-args
)
242 (error "%s: missing argument to `%s' option" (invocation-name) switch
))
243 (setq x-session-previous-id
(car x-invocation-args
)
244 x-invocation-args
(cdr x-invocation-args
)))
246 (defvar emacs-save-session-functions nil
247 "Functions to run when a save-session event occurs.
248 The functions does not get any argument.
249 Functions can return non-nil to inform the session manager that the
250 window system shutdown should be aborted.
252 See also `emacs-session-save'.")
254 (defun emacs-session-filename (session-id)
255 "Construct a filename to save the session in based on SESSION-ID.
256 If the directory ~/.emacs.d exists, we make a filename in there, otherwise
257 a file in the home directory."
258 (let ((basename (concat "session." session-id
))
259 (emacs-dir "~/.emacs.d/"))
260 (expand-file-name (if (file-directory-p emacs-dir
)
261 (concat emacs-dir basename
)
262 (concat "~/.emacs-" basename
)))))
264 (defun emacs-session-save ()
265 "This function is called when the window system is shutting down.
266 If this function returns non-nil, the window system shutdown is cancelled.
268 When a session manager tells Emacs that the window system is shutting
269 down, this function is called. It calls the functions in the hook
270 `emacs-save-session-functions'. Functions are called with the current
271 buffer set to a temporary buffer. Functions should use `insert' to insert
272 lisp code to save the session state. The buffer is saved
273 in a file in the home directory of the user running Emacs. The file
274 is evaluated when Emacs is restarted by the session manager.
276 If any of the functions returns non-nil, no more functions are called
277 and this function returns non-nil. This will inform the session manager
278 that it should abort the window system shutdown."
279 (let ((filename (emacs-session-filename x-session-id
))
280 (buf (get-buffer-create (concat " *SES " x-session-id
))))
281 (when (file-exists-p filename
)
282 (delete-file filename
))
283 (with-current-buffer buf
284 (let ((cancel-shutdown (condition-case nil
285 ;; A return of t means cancel the shutdown.
286 (run-hook-with-args-until-success
287 'emacs-save-session-functions
)
289 (unless cancel-shutdown
290 (write-file filename
))
294 (defun emacs-session-restore (previous-session-id)
295 "Restore the Emacs session if started by a session manager.
296 The file saved by `emacs-session-save' is evaluated and deleted if it
298 (let ((filename (emacs-session-filename previous-session-id
)))
299 (when (file-exists-p filename
)
301 (delete-file filename
)
302 (message "Restored session data"))))
308 ;; Standard X cursor shapes, courtesy of Mr. Fox, who wanted ALL of them.
311 (defconst x-pointer-X-cursor
0)
312 (defconst x-pointer-arrow
2)
313 (defconst x-pointer-based-arrow-down
4)
314 (defconst x-pointer-based-arrow-up
6)
315 (defconst x-pointer-boat
8)
316 (defconst x-pointer-bogosity
10)
317 (defconst x-pointer-bottom-left-corner
12)
318 (defconst x-pointer-bottom-right-corner
14)
319 (defconst x-pointer-bottom-side
16)
320 (defconst x-pointer-bottom-tee
18)
321 (defconst x-pointer-box-spiral
20)
322 (defconst x-pointer-center-ptr
22)
323 (defconst x-pointer-circle
24)
324 (defconst x-pointer-clock
26)
325 (defconst x-pointer-coffee-mug
28)
326 (defconst x-pointer-cross
30)
327 (defconst x-pointer-cross-reverse
32)
328 (defconst x-pointer-crosshair
34)
329 (defconst x-pointer-diamond-cross
36)
330 (defconst x-pointer-dot
38)
331 (defconst x-pointer-dotbox
40)
332 (defconst x-pointer-double-arrow
42)
333 (defconst x-pointer-draft-large
44)
334 (defconst x-pointer-draft-small
46)
335 (defconst x-pointer-draped-box
48)
336 (defconst x-pointer-exchange
50)
337 (defconst x-pointer-fleur
52)
338 (defconst x-pointer-gobbler
54)
339 (defconst x-pointer-gumby
56)
340 (defconst x-pointer-hand1
58)
341 (defconst x-pointer-hand2
60)
342 (defconst x-pointer-heart
62)
343 (defconst x-pointer-icon
64)
344 (defconst x-pointer-iron-cross
66)
345 (defconst x-pointer-left-ptr
68)
346 (defconst x-pointer-left-side
70)
347 (defconst x-pointer-left-tee
72)
348 (defconst x-pointer-leftbutton
74)
349 (defconst x-pointer-ll-angle
76)
350 (defconst x-pointer-lr-angle
78)
351 (defconst x-pointer-man
80)
352 (defconst x-pointer-middlebutton
82)
353 (defconst x-pointer-mouse
84)
354 (defconst x-pointer-pencil
86)
355 (defconst x-pointer-pirate
88)
356 (defconst x-pointer-plus
90)
357 (defconst x-pointer-question-arrow
92)
358 (defconst x-pointer-right-ptr
94)
359 (defconst x-pointer-right-side
96)
360 (defconst x-pointer-right-tee
98)
361 (defconst x-pointer-rightbutton
100)
362 (defconst x-pointer-rtl-logo
102)
363 (defconst x-pointer-sailboat
104)
364 (defconst x-pointer-sb-down-arrow
106)
365 (defconst x-pointer-sb-h-double-arrow
108)
366 (defconst x-pointer-sb-left-arrow
110)
367 (defconst x-pointer-sb-right-arrow
112)
368 (defconst x-pointer-sb-up-arrow
114)
369 (defconst x-pointer-sb-v-double-arrow
116)
370 (defconst x-pointer-shuttle
118)
371 (defconst x-pointer-sizing
120)
372 (defconst x-pointer-spider
122)
373 (defconst x-pointer-spraycan
124)
374 (defconst x-pointer-star
126)
375 (defconst x-pointer-target
128)
376 (defconst x-pointer-tcross
130)
377 (defconst x-pointer-top-left-arrow
132)
378 (defconst x-pointer-top-left-corner
134)
379 (defconst x-pointer-top-right-corner
136)
380 (defconst x-pointer-top-side
138)
381 (defconst x-pointer-top-tee
140)
382 (defconst x-pointer-trek
142)
383 (defconst x-pointer-ul-angle
144)
384 (defconst x-pointer-umbrella
146)
385 (defconst x-pointer-ur-angle
148)
386 (defconst x-pointer-watch
150)
387 (defconst x-pointer-xterm
152)
393 (defvar x-colors
'("LightGreen"
992 "LightGoldenrodYellow"
993 "light goldenrod yellow"
1010 "medium spring green"
1145 "The list of X colors from the `rgb.txt' file.
1146 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1148 (defun xw-defined-colors (&optional frame
)
1149 "Internal function called by `defined-colors', which see."
1150 (or frame
(setq frame
(selected-frame)))
1151 (let ((all-colors x-colors
)
1153 (defined-colors nil
))
1155 (setq this-color
(car all-colors
)
1156 all-colors
(cdr all-colors
))
1157 (and (color-supported-p this-color frame t
)
1158 (setq defined-colors
(cons this-color defined-colors
))))
1163 (defun iconify-or-deiconify-frame ()
1164 "Iconify the selected frame, or deiconify if it's currently an icon."
1166 (if (eq (cdr (assq 'visibility
(frame-parameters))) t
)
1168 (make-frame-visible)))
1170 (substitute-key-definition 'suspend-emacs
'iconify-or-deiconify-frame
1173 ;; Map certain keypad keys into ASCII characters
1174 ;; that people usually expect.
1175 (define-key function-key-map
[backspace] [127])
1176 (define-key function-key-map [delete] [127])
1177 (define-key function-key-map [tab] [?\t])
1178 (define-key function-key-map [linefeed] [?\n])
1179 (define-key function-key-map [clear] [?\C-l])
1180 (define-key function-key-map [return] [?\C-m])
1181 (define-key function-key-map [escape] [?\e])
1182 (define-key function-key-map [M-backspace] [?\M-\d])
1183 (define-key function-key-map [M-delete] [?\M-\d])
1184 (define-key function-key-map [M-tab] [?\M-\t])
1185 (define-key function-key-map [M-linefeed] [?\M-\n])
1186 (define-key function-key-map [M-clear] [?\M-\C-l])
1187 (define-key function-key-map [M-return] [?\M-\C-m])
1188 (define-key function-key-map [M-escape] [?\M-\e])
1189 (define-key function-key-map [iso-lefttab] [backtab])
1190 (define-key function-key-map [S-iso-lefttab] [backtab])
1192 ;; These tell read-char how to convert
1193 ;; these special chars to ASCII.
1194 (put 'backspace 'ascii-character 127)
1195 (put 'delete 'ascii-character 127)
1196 (put 'tab 'ascii-character ?\t)
1197 (put 'linefeed 'ascii-character ?\n)
1198 (put 'clear 'ascii-character 12)
1199 (put 'return 'ascii-character 13)
1200 (put 'escape 'ascii-character ?\e)
1202 (defun vendor-specific-keysyms (vendor)
1203 "Return the appropriate value of system-key-alist for VENDOR.
1204 VENDOR is a string containing the name of the X Server's vendor,
1205 as returned by (x-server-vendor)."
1206 (cond ((string-equal vendor "Apollo Computer Inc.")
1228 ((or (string-equal vendor "Hewlett-Packard Incorporated")
1229 (string-equal vendor "Hewlett-Packard Company"))
1230 '(( 168 . mute-acute)
1232 ( 170 . mute-asciicircum)
1233 ( 171 . mute-diaeresis)
1234 ( 172 . mute-asciitilde)
1243 (65392 . insertline)
1244 (65393 . deleteline)
1245 (65394 . insertchar)
1246 (65395 . deletechar)
1248 (65397 . kp-backtab)))
1249 ((or (string-equal vendor "X11/NeWS - Sun Microsystems Inc.")
1250 (string-equal vendor "X Consortium"))
1254 ;; These are for Sun under X11R6
1262 ;; This is used by DEC's X server.
1263 '((65280 . remove)))))
1266 ;;;; Selections and cut buffers
1268 ;;; We keep track of the last text selected here, so we can check the
1269 ;;; current selection against it, and avoid passing back our own text
1270 ;;; from x-cut-buffer-or-selection-value. We track all three
1271 ;;; seperately in case another X application only sets one of them
1272 ;;; (say the cut buffer) we aren't fooled by the PRIMARY or
1273 ;;; CLIPBOARD selection staying the same.
1274 (defvar x-last-selected-text-clipboard nil
1275 "The value of the CLIPBOARD X selection last time we selected or
1277 (defvar x-last-selected-text-primary nil
1278 "The value of the PRIMARY X selection last time we selected or
1280 (defvar x-last-selected-text-cut nil
1281 "The vaue of the X cut buffer last time we selected or
1284 ;;; It is said that overlarge strings are slow to put into the cut buffer.
1285 ;;; Note this value is overridden below.
1286 (defvar x-cut-buffer-max 20000
1287 "Max number of characters to put in the cut buffer.")
1289 (defcustom x-select-enable-clipboard nil
1290 "Non-nil means cutting and pasting uses the clipboard.
1291 This is in addition to, but in preference to, the primary selection."
1295 ;;; Make TEXT, a string, the primary X selection.
1296 ;;; Also, set the value of X cut buffer 0, for backward compatibility
1297 ;;; with older X applications.
1298 ;;; gildea@stop.mail-abuse.org says it's not desirable to put kills
1299 ;;; in the clipboard.
1300 (defun x-select-text (text &optional push)
1301 ;; Don't send the cut buffer too much text.
1302 ;; It becomes slow, and if really big it causes errors.
1303 (cond ((>= (length text) x-cut-buffer-max)
1304 (x-set-cut-buffer "" push)
1305 (setq x-last-selected-text-cut ""))
1307 (x-set-cut-buffer text push)
1308 (setq x-last-selected-text-cut text)))
1309 (x-set-selection 'PRIMARY text)
1310 (setq x-last-selected-text-primary text)
1311 (when x-select-enable-clipboard
1312 (x-set-selection 'CLIPBOARD text)
1313 (setq x-last-selected-text-clipboard text))
1316 ;;; Return the value of the current X selection.
1317 ;;; Consult the selection, and the cut buffer. Treat empty strings
1318 ;;; as if they were unset.
1319 ;;; If this function is called twice and finds the same text,
1320 ;;; it returns nil the second time. This is so that a single
1321 ;;; selection won't be added to the kill ring over and over.
1322 (defun x-cut-buffer-or-selection-value ()
1323 (let (clip-text primary-text cut-text)
1324 (when x-select-enable-clipboard
1325 ;; Don't die if x-get-selection signals an error.
1326 (if (null clip-text)
1328 (setq clip-text (x-get-selection 'CLIPBOARD 'COMPOUND_TEXT))
1330 (if (null clip-text)
1332 (setq clip-text (x-get-selection 'CLIPBOARD 'STRING))
1334 (if (string= clip-text "") (setq clip-text nil))
1336 ;; Check the CLIPBOARD selection for 'newness', is it different
1337 ;; from what we remebered them to be last time we did a
1338 ;; cut/paste operation.
1340 (cond;; check clipboard
1341 ((or (not clip-text) (string= clip-text ""))
1342 (setq x-last-selected-text-clipboard nil))
1343 ((eq clip-text x-last-selected-text-clipboard) nil)
1344 ((string= clip-text x-last-selected-text-clipboard)
1345 ;; Record the newer string,
1346 ;; so subsequent calls can use the `eq' test.
1347 (setq x-last-selected-text-clipboard clip-text)
1350 (setq x-last-selected-text-clipboard clip-text))))
1353 ;; Don't die if x-get-selection signals an error.
1354 (if (null primary-text)
1356 (setq primary-text (x-get-selection 'PRIMARY 'COMPOUND_TEXT))
1358 (if (null primary-text)
1360 (setq primary-text (x-get-selection 'PRIMARY 'STRING))
1362 ;; Check the PRIMARY selection for 'newness', is it different
1363 ;; from what we remebered them to be last time we did a
1364 ;; cut/paste operation.
1366 (cond;; check primary selection
1367 ((or (not primary-text) (string= primary-text ""))
1368 (setq x-last-selected-text-primary nil))
1369 ((eq primary-text x-last-selected-text-primary) nil)
1370 ((string= primary-text x-last-selected-text-primary)
1371 ;; Record the newer string,
1372 ;; so subsequent calls can use the `eq' test.
1373 (setq x-last-selected-text-primary primary-text)
1376 (setq x-last-selected-text-primary primary-text))))
1378 (setq cut-text (x-get-cut-buffer 0))
1380 ;; Check the x cut buffer for 'newness', is it different
1381 ;; from what we remebered them to be last time we did a
1382 ;; cut/paste operation.
1384 (cond;; check primary selection
1385 ((or (not cut-text) (string= cut-text ""))
1386 (setq x-last-selected-text-cut nil))
1387 ((eq cut-text x-last-selected-text-cut) nil)
1388 ((string= cut-text x-last-selected-text-cut)
1389 ;; Record the newer string,
1390 ;; so subsequent calls can use the `eq' test.
1391 (setq x-last-selected-text-cut cut-text)
1394 (setq x-last-selected-text-cut cut-text))))
1396 ;; At this point we have recorded the current values for the
1397 ;; selection from clipboard (if we are supposed to) primary,
1398 ;; and cut buffer. So return the first one that has changed
1399 ;; (which is the first non-null one).
1401 ;; NOTE: There will be cases where more than one of these has
1402 ;; changed and the new values differ. This indicates that
1403 ;; something like the following has happened since the last time
1404 ;; we looked at the selections: Application X set all the
1405 ;; selections, then Application Y set only one or two of them (say
1406 ;; just the cut-buffer). In this case since we don't have
1407 ;; timestamps there is no way to know what the 'correct' value to
1408 ;; return is. The nice thing to do would be to tell the user we
1409 ;; saw multiple possible selections and ask the user which was the
1411 ;; This code is still a big improvement because now the user can
1412 ;; futz with the current selection and get emacs to pay attention
1413 ;; to the cut buffer again (previously as soon as clipboard or
1414 ;; primary had been set the cut buffer would essentially never be
1416 (or clip-text primary-text cut-text)
1420 ;;; Do the actual X Windows setup here; the above code just defines
1421 ;;; functions and variables that we use now.
1423 (setq command-line-args (x-handle-args command-line-args))
1425 ;;; Make sure we have a valid resource name.
1426 (or (stringp x-resource-name)
1428 (setq x-resource-name (invocation-name))
1430 ;; Change any . or * characters in x-resource-name to hyphens,
1431 ;; so as not to choke when we use it in X resource queries.
1432 (while (setq i (string-match "[.*]" x-resource-name))
1433 (aset x-resource-name i ?-))))
1435 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1436 ;; the same lisp directory, don't pass the third argument unless we seem
1437 ;; to have the multi-display support.
1438 (if (fboundp 'x-close-connection)
1439 (x-open-connection (or x-display-name
1440 (setq x-display-name (getenv "DISPLAY")))
1441 x-command-line-resources
1442 ;; Exit Emacs with fatal error if this fails.
1444 (x-open-connection (or x-display-name
1445 (setq x-display-name (getenv "DISPLAY")))
1446 x-command-line-resources))
1448 (setq frame-creation-function 'x-create-frame-with-faces)
1450 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1453 (if (fboundp 'new-fontset)
1455 ;; Create the standard fontset.
1456 (create-fontset-from-fontset-spec standard-fontset-spec t)
1458 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
1459 (create-fontset-from-x-resource)
1461 ;; Try to create a fontset from a font specification which comes
1462 ;; from initial-frame-alist, default-frame-alist, or X resource.
1463 ;; A font specification in command line argument (i.e. -fn XXXX)
1464 ;; should be already in default-frame-alist as a `font'
1465 ;; parameter. However, any font specifications in site-start
1466 ;; library, user's init file (.emacs), and default.el are not
1467 ;; yet handled here.
1469 (let ((font (or (cdr (assq 'font initial-frame-alist))
1470 (cdr (assq 'font default-frame-alist))
1471 (x-get-resource "font" "Font")))
1472 xlfd-fields resolved-name)
1474 (not (query-fontset font))
1475 (setq resolved-name (x-resolve-font-name font))
1476 (setq xlfd-fields (x-decompose-font-name font)))
1477 (if (string= "fontset"
1478 (aref xlfd-fields xlfd-regexp-registry-subnum))
1479 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
1480 ;; Create a fontset from FONT. The fontset name is
1481 ;; generated from FONT.
1482 (create-fontset-from-ascii-font font
1483 resolved-name "startup"))))))
1485 ;; Sun expects the menu bar cut and paste commands to use the clipboard.
1486 ;; This has ,? to match both on Sunos and on Solaris.
1487 (if (string-match "Sun Microsystems,? Inc\\."
1489 (menu-bar-enable-clipboard))
1491 ;; Apply a geometry resource to the initial frame. Put it at the end
1492 ;; of the alist, so that anything specified on the command line takes
1494 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1498 (setq parsed (x-parse-geometry res-geometry))
1499 ;; If the resource specifies a position,
1500 ;; call the position and size "user-specified".
1501 (if (or (assq 'top parsed) (assq 'left parsed))
1502 (setq parsed (cons '(user-position . t)
1503 (cons '(user-size . t) parsed))))
1504 ;; All geometry parms apply to the initial frame.
1505 (setq initial-frame-alist (append initial-frame-alist parsed))
1506 ;; The size parms apply to all frames.
1507 (if (assq 'height parsed)
1508 (setq default-frame-alist
1509 (cons (cons 'height (cdr (assq 'height parsed)))
1510 default-frame-alist)))
1511 (if (assq 'width parsed)
1512 (setq default-frame-alist
1513 (cons (cons 'width (cdr (assq 'width parsed)))
1514 default-frame-alist))))))
1516 ;; Check the reverseVideo resource.
1517 (let ((case-fold-search t))
1518 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1520 (string-match "^\\(true\\|yes\\|on\\)$" rv))
1521 (setq default-frame-alist
1522 (cons '(reverse . t) default-frame-alist)))))
1524 ;; Set x-selection-timeout, measured in milliseconds.
1525 (let ((res-selection-timeout
1526 (x-get-resource "selectionTimeout" "SelectionTimeout")))
1527 (setq x-selection-timeout 20000)
1528 (if res-selection-timeout
1529 (setq x-selection-timeout (string-to-number res-selection-timeout))))
1531 (defun x-win-suspend-error ()
1532 (error "Suspending an emacs running under X makes no sense"))
1533 (add-hook 'suspend-hook 'x-win-suspend-error)
1535 ;;; Arrange for the kill and yank functions to set and check the clipboard.
1536 (setq interprogram-cut-function 'x-select-text)
1537 (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
1539 ;;; Turn off window-splitting optimization; X is usually fast enough
1540 ;;; that this is only annoying.
1541 (setq split-window-keep-point t)
1543 ;; Don't show the frame name; that's redundant with X.
1544 (setq-default mode-line-frame-identification " ")
1546 ;;; Motif direct handling of f10 wasn't working right,
1547 ;;; So temporarily we've turned it off in lwlib-Xm.c
1548 ;;; and turned the Emacs f10 back on.
1549 ;;; ;; Motif normally handles f10 itself, so don't try to handle it a second time.
1550 ;;; (if (featurep 'motif)
1551 ;;; (global-set-key [f10] 'ignore))
1553 ;;; x-win.el ends here