comparison lisp/term/x-win.el @ 83716:a73440d2f146 merge-multi-tty-to-trunk

Merge multi-tty branch Revision: emacs@sv.gnu.org/emacs--devo--0--patch-866
author Miles Bader <miles@gnu.org>
date Wed, 29 Aug 2007 05:28:10 +0000
parents 18c1a2214c41 65663fcd2caa
children 0ee0c5be8e9a
comparison
equal deleted inserted replaced
82950:ed8435ec5652 83716:a73440d2f146
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA. 24 ;; Boston, MA 02110-1301, USA.
25 25
26 ;;; Commentary: 26 ;;; Commentary:
27 27
28 ;; X-win.el: this file is loaded from ../lisp/startup.el when it recognizes 28 ;; X-win.el: this file defines functions to initialize the X window
29 ;; that X windows are to be used. Command line switches are parsed and those 29 ;; system and process X-specific command line parameters before
30 ;; pertaining to X are processed and removed from the command line. The 30 ;; creating the first X frame.
31 ;; X display is opened and hooks are set for popping up the initial window. 31
32 ;; Note that contrary to previous Emacs versions, the act of loading
33 ;; this file should not have the side effect of initializing the
34 ;; window system or processing command line arguments (this file is
35 ;; now loaded in loadup.el). See the variables
36 ;; `handle-args-function-alist' and
37 ;; `window-system-initialization-alist' for more details.
32 38
33 ;; startup.el will then examine startup files, and eventually call the hooks 39 ;; startup.el will then examine startup files, and eventually call the hooks
34 ;; which create the first window(s). 40 ;; which create the first window(s).
35 41
36 ;;; Code: 42 ;;; Code:
63 ;; -xrm 69 ;; -xrm
64 70
65 ;; An alist of X options and the function which handles them. See 71 ;; An alist of X options and the function which handles them. See
66 ;; ../startup.el. 72 ;; ../startup.el.
67 73
68 (if (not (eq window-system 'x)) 74 (if (not (fboundp 'x-create-frame))
69 (error "%s: Loading x-win.el but not compiled for X" (invocation-name))) 75 (error "%s: Loading x-win.el but not compiled for X" (invocation-name)))
70 76
71 (require 'frame) 77 (require 'frame)
72 (require 'mouse) 78 (require 'mouse)
73 (require 'scroll-bar) 79 (require 'scroll-bar)
1168 (setq defined-colors (cons this-color defined-colors)))) 1174 (setq defined-colors (cons this-color defined-colors))))
1169 defined-colors)) 1175 defined-colors))
1170 1176
1171 ;;;; Function keys 1177 ;;;; Function keys
1172 1178
1173 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame 1179 (defun x-setup-function-keys (frame)
1174 global-map) 1180 "Set up `function-key-map' on FRAME for the X window system."
1175 1181 ;; Don't do this twice on the same display, or it would break
1176 ;; Map certain keypad keys into ASCII characters 1182 ;; normal-erase-is-backspace-mode.
1177 ;; that people usually expect. 1183 (unless (terminal-parameter frame 'x-setup-function-keys)
1178 (define-key function-key-map [backspace] [127]) 1184 ;; Map certain keypad keys into ASCII characters that people usually expect.
1179 (define-key function-key-map [delete] [127]) 1185 (with-selected-frame frame
1180 (define-key function-key-map [tab] [?\t]) 1186 (define-key local-function-key-map [backspace] [127])
1181 (define-key function-key-map [linefeed] [?\n]) 1187 (define-key local-function-key-map [delete] [127])
1182 (define-key function-key-map [clear] [?\C-l]) 1188 (define-key local-function-key-map [tab] [?\t])
1183 (define-key function-key-map [return] [?\C-m]) 1189 (define-key local-function-key-map [linefeed] [?\n])
1184 (define-key function-key-map [escape] [?\e]) 1190 (define-key local-function-key-map [clear] [?\C-l])
1185 (define-key function-key-map [M-backspace] [?\M-\d]) 1191 (define-key local-function-key-map [return] [?\C-m])
1186 (define-key function-key-map [M-delete] [?\M-\d]) 1192 (define-key local-function-key-map [escape] [?\e])
1187 (define-key function-key-map [M-tab] [?\M-\t]) 1193 (define-key local-function-key-map [M-backspace] [?\M-\d])
1188 (define-key function-key-map [M-linefeed] [?\M-\n]) 1194 (define-key local-function-key-map [M-delete] [?\M-\d])
1189 (define-key function-key-map [M-clear] [?\M-\C-l]) 1195 (define-key local-function-key-map [M-tab] [?\M-\t])
1190 (define-key function-key-map [M-return] [?\M-\C-m]) 1196 (define-key local-function-key-map [M-linefeed] [?\M-\n])
1191 (define-key function-key-map [M-escape] [?\M-\e]) 1197 (define-key local-function-key-map [M-clear] [?\M-\C-l])
1192 (define-key function-key-map [iso-lefttab] [backtab]) 1198 (define-key local-function-key-map [M-return] [?\M-\C-m])
1193 (define-key function-key-map [S-iso-lefttab] [backtab]) 1199 (define-key local-function-key-map [M-escape] [?\M-\e])
1200 (define-key local-function-key-map [iso-lefttab] [backtab])
1201 (define-key local-function-key-map [S-iso-lefttab] [backtab]))
1202 (set-terminal-parameter frame 'x-setup-function-keys t)))
1194 1203
1195 ;; These tell read-char how to convert 1204 ;; These tell read-char how to convert
1196 ;; these special chars to ASCII. 1205 ;; these special chars to ASCII.
1197 (put 'backspace 'ascii-character 127) 1206 (put 'backspace 'ascii-character 127)
1198 (put 'delete 'ascii-character 127) 1207 (put 'delete 'ascii-character 127)
2391 ;; primary had been set the cut buffer would essentially never be 2400 ;; primary had been set the cut buffer would essentially never be
2392 ;; checked again). 2401 ;; checked again).
2393 (or clip-text primary-text cut-text) 2402 (or clip-text primary-text cut-text)
2394 )) 2403 ))
2395 2404
2396
2397 ;; Do the actual X Windows setup here; the above code just defines
2398 ;; functions and variables that we use now.
2399
2400 (setq command-line-args (x-handle-args command-line-args))
2401
2402 ;; Make sure we have a valid resource name.
2403 (or (stringp x-resource-name)
2404 (let (i)
2405 (setq x-resource-name (invocation-name))
2406
2407 ;; Change any . or * characters in x-resource-name to hyphens,
2408 ;; so as not to choke when we use it in X resource queries.
2409 (while (setq i (string-match "[.*]" x-resource-name))
2410 (aset x-resource-name i ?-))))
2411
2412 (x-open-connection (or x-display-name
2413 (setq x-display-name (getenv "DISPLAY")))
2414 x-command-line-resources
2415 ;; Exit Emacs with fatal error if this fails.
2416 t)
2417
2418 (setq frame-creation-function 'x-create-frame-with-faces)
2419
2420 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
2421 x-cut-buffer-max))
2422
2423 ;; Setup the default fontset.
2424 (setup-default-fontset)
2425
2426 ;; Create the standard fontset.
2427 (create-fontset-from-fontset-spec standard-fontset-spec t)
2428
2429 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
2430 (create-fontset-from-x-resource)
2431
2432 ;; Try to create a fontset from a font specification which comes
2433 ;; from initial-frame-alist, default-frame-alist, or X resource.
2434 ;; A font specification in command line argument (i.e. -fn XXXX)
2435 ;; should be already in default-frame-alist as a `font'
2436 ;; parameter. However, any font specifications in site-start
2437 ;; library, user's init file (.emacs), and default.el are not
2438 ;; yet handled here.
2439
2440 (let ((font (or (cdr (assq 'font initial-frame-alist))
2441 (cdr (assq 'font default-frame-alist))
2442 (x-get-resource "font" "Font")))
2443 xlfd-fields resolved-name)
2444 (if (and font
2445 (not (query-fontset font))
2446 (setq resolved-name (x-resolve-font-name font))
2447 (setq xlfd-fields (x-decompose-font-name font)))
2448 (if (string= "fontset" (aref xlfd-fields xlfd-regexp-registry-subnum))
2449 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
2450 ;; Create a fontset from FONT. The fontset name is
2451 ;; generated from FONT.
2452 (create-fontset-from-ascii-font font resolved-name "startup"))))
2453
2454 ;; Apply a geometry resource to the initial frame. Put it at the end
2455 ;; of the alist, so that anything specified on the command line takes
2456 ;; precedence.
2457 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
2458 parsed)
2459 (if res-geometry
2460 (progn
2461 (setq parsed (x-parse-geometry res-geometry))
2462 ;; If the resource specifies a position,
2463 ;; call the position and size "user-specified".
2464 (if (or (assq 'top parsed) (assq 'left parsed))
2465 (setq parsed (cons '(user-position . t)
2466 (cons '(user-size . t) parsed))))
2467 ;; All geometry parms apply to the initial frame.
2468 (setq initial-frame-alist (append initial-frame-alist parsed))
2469 ;; The size parms apply to all frames. Don't set it if there are
2470 ;; sizes there already (from command line).
2471 (if (and (assq 'height parsed)
2472 (not (assq 'height default-frame-alist)))
2473 (setq default-frame-alist
2474 (cons (cons 'height (cdr (assq 'height parsed)))
2475 default-frame-alist)))
2476 (if (and (assq 'width parsed)
2477 (not (assq 'width default-frame-alist)))
2478 (setq default-frame-alist
2479 (cons (cons 'width (cdr (assq 'width parsed)))
2480 default-frame-alist))))))
2481
2482 ;; Check the reverseVideo resource.
2483 (let ((case-fold-search t))
2484 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
2485 (if (and rv
2486 (string-match "^\\(true\\|yes\\|on\\)$" rv))
2487 (setq default-frame-alist
2488 (cons '(reverse . t) default-frame-alist)))))
2489
2490 ;; Set x-selection-timeout, measured in milliseconds.
2491 (let ((res-selection-timeout
2492 (x-get-resource "selectionTimeout" "SelectionTimeout")))
2493 (setq x-selection-timeout 20000)
2494 (if res-selection-timeout
2495 (setq x-selection-timeout (string-to-number res-selection-timeout))))
2496
2497 ;; Set scroll bar mode to right if set by X resources. Default is left.
2498 (if (equal (x-get-resource "verticalScrollBars" "ScrollBars") "right")
2499 (customize-set-variable 'scroll-bar-mode 'right))
2500
2501 (defun x-win-suspend-error ()
2502 (error "Suspending an Emacs running under X makes no sense"))
2503 (add-hook 'suspend-hook 'x-win-suspend-error)
2504
2505 ;; Arrange for the kill and yank functions to set and check the clipboard.
2506 (setq interprogram-cut-function 'x-select-text)
2507 (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
2508
2509 ;; Turn off window-splitting optimization; X is usually fast enough
2510 ;; that this is only annoying.
2511 (setq split-window-keep-point t)
2512
2513 ;; Don't show the frame name; that's redundant with X.
2514 (setq-default mode-line-frame-identification " ")
2515
2516 ;; Motif direct handling of f10 wasn't working right,
2517 ;; So temporarily we've turned it off in lwlib-Xm.c
2518 ;; and turned the Emacs f10 back on.
2519 ;; ;; Motif normally handles f10 itself, so don't try to handle it a second time.
2520 ;; (if (featurep 'motif)
2521 ;; (global-set-key [f10] 'ignore))
2522
2523 ;; Turn on support for mouse wheels.
2524 (mouse-wheel-mode 1)
2525
2526
2527 ;; Enable CLIPBOARD copy/paste through menu bar commands.
2528 (menu-bar-enable-clipboard)
2529
2530 ;; Override Paste so it looks at CLIPBOARD first.
2531 (defun x-clipboard-yank () 2405 (defun x-clipboard-yank ()
2532 "Insert the clipboard contents, or the last stretch of killed text." 2406 "Insert the clipboard contents, or the last stretch of killed text."
2533 (interactive "*") 2407 (interactive "*")
2534 (let ((clipboard-text (x-selection-value 'CLIPBOARD)) 2408 (let ((clipboard-text (x-selection-value 'CLIPBOARD))
2535 (x-select-enable-clipboard t)) 2409 (x-select-enable-clipboard t))
2536 (if (and clipboard-text (> (length clipboard-text) 0)) 2410 (if (and clipboard-text (> (length clipboard-text) 0))
2537 (kill-new clipboard-text)) 2411 (kill-new clipboard-text))
2538 (yank))) 2412 (yank)))
2539 2413
2540 (define-key menu-bar-edit-menu [paste] 2414 (defun x-menu-bar-open (&optional frame)
2541 '(menu-item "Paste" x-clipboard-yank 2415 "Open the menu bar if `menu-bar-mode' is on. otherwise call `tmm-menubar'."
2542 :enable (not buffer-read-only) 2416 (interactive "i")
2543 :help "Paste (yank) text most recently cut/copied")) 2417 (if menu-bar-mode (accelerate-menu frame)
2418 (tmm-menubar)))
2419
2420
2421 ;;; Window system initialization.
2422
2423 (defun x-win-suspend-error ()
2424 (error "Suspending an Emacs running under X makes no sense"))
2425
2426 (defvar x-initialized nil
2427 "Non-nil if the X window system has been initialized.")
2428
2429 (defun x-initialize-window-system ()
2430 "Initialize Emacs for X frames and open the first connection to an X server."
2431 ;; Make sure we have a valid resource name.
2432 (or (stringp x-resource-name)
2433 (let (i)
2434 (setq x-resource-name (invocation-name))
2435
2436 ;; Change any . or * characters in x-resource-name to hyphens,
2437 ;; so as not to choke when we use it in X resource queries.
2438 (while (setq i (string-match "[.*]" x-resource-name))
2439 (aset x-resource-name i ?-))))
2440
2441 (x-open-connection (or x-display-name
2442 (setq x-display-name (or (getenv "DISPLAY" (selected-frame))
2443 (getenv "DISPLAY"))))
2444 x-command-line-resources
2445 ;; Exit Emacs with fatal error if this fails and we
2446 ;; are the initial display.
2447 (eq initial-window-system 'x))
2448
2449 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
2450 x-cut-buffer-max))
2451
2452 ;; Setup the default fontset.
2453 (setup-default-fontset)
2454
2455 ;; Create the standard fontset.
2456 (create-fontset-from-fontset-spec standard-fontset-spec t)
2457
2458 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
2459 (create-fontset-from-x-resource)
2460
2461 ;; Try to create a fontset from a font specification which comes
2462 ;; from initial-frame-alist, default-frame-alist, or X resource.
2463 ;; A font specification in command line argument (i.e. -fn XXXX)
2464 ;; should be already in default-frame-alist as a `font'
2465 ;; parameter. However, any font specifications in site-start
2466 ;; library, user's init file (.emacs), and default.el are not
2467 ;; yet handled here.
2468
2469 (let ((font (or (cdr (assq 'font initial-frame-alist))
2470 (cdr (assq 'font default-frame-alist))
2471 (x-get-resource "font" "Font")))
2472 xlfd-fields resolved-name)
2473 (if (and font
2474 (not (query-fontset font))
2475 (setq resolved-name (x-resolve-font-name font))
2476 (setq xlfd-fields (x-decompose-font-name font)))
2477 (if (string= "fontset" (aref xlfd-fields xlfd-regexp-registry-subnum))
2478 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
2479 ;; Create a fontset from FONT. The fontset name is
2480 ;; generated from FONT.
2481 (create-fontset-from-ascii-font font resolved-name "startup"))))
2482
2483 ;; Set scroll bar mode to right if set by X resources. Default is left.
2484 (if (equal (x-get-resource "verticalScrollBars" "ScrollBars") "right")
2485 (customize-set-variable 'scroll-bar-mode 'right))
2486
2487 ;; Apply a geometry resource to the initial frame. Put it at the end
2488 ;; of the alist, so that anything specified on the command line takes
2489 ;; precedence.
2490 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
2491 parsed)
2492 (if res-geometry
2493 (progn
2494 (setq parsed (x-parse-geometry res-geometry))
2495 ;; If the resource specifies a position,
2496 ;; call the position and size "user-specified".
2497 (if (or (assq 'top parsed) (assq 'left parsed))
2498 (setq parsed (cons '(user-position . t)
2499 (cons '(user-size . t) parsed))))
2500 ;; All geometry parms apply to the initial frame.
2501 (setq initial-frame-alist (append initial-frame-alist parsed))
2502 ;; The size parms apply to all frames. Don't set it if there are
2503 ;; sizes there already (from command line).
2504 (if (and (assq 'height parsed)
2505 (not (assq 'height default-frame-alist)))
2506 (setq default-frame-alist
2507 (cons (cons 'height (cdr (assq 'height parsed)))
2508 default-frame-alist)))
2509 (if (and (assq 'width parsed)
2510 (not (assq 'width default-frame-alist)))
2511 (setq default-frame-alist
2512 (cons (cons 'width (cdr (assq 'width parsed)))
2513 default-frame-alist))))))
2514
2515 ;; Check the reverseVideo resource.
2516 (let ((case-fold-search t))
2517 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
2518 (if (and rv
2519 (string-match "^\\(true\\|yes\\|on\\)$" rv))
2520 (setq default-frame-alist
2521 (cons '(reverse . t) default-frame-alist)))))
2522
2523 ;; Set x-selection-timeout, measured in milliseconds.
2524 (let ((res-selection-timeout
2525 (x-get-resource "selectionTimeout" "SelectionTimeout")))
2526 (setq x-selection-timeout 20000)
2527 (if res-selection-timeout
2528 (setq x-selection-timeout (string-to-number res-selection-timeout))))
2529
2530 ;; Don't let Emacs suspend under X.
2531 (add-hook 'suspend-hook 'x-win-suspend-error)
2532
2533 ;; Turn off window-splitting optimization; X is usually fast enough
2534 ;; that this is only annoying.
2535 (setq split-window-keep-point t)
2536
2537 ;; Motif direct handling of f10 wasn't working right,
2538 ;; So temporarily we've turned it off in lwlib-Xm.c
2539 ;; and turned the Emacs f10 back on.
2540 ;; ;; Motif normally handles f10 itself, so don't try to handle it a second time.
2541 ;; (if (featurep 'motif)
2542 ;; (global-set-key [f10] 'ignore))
2543
2544 ;; Turn on support for mouse wheels.
2545 (mouse-wheel-mode 1)
2546
2547 ;; Enable CLIPBOARD copy/paste through menu bar commands.
2548 (menu-bar-enable-clipboard)
2549
2550 ;; Override Paste so it looks at CLIPBOARD first.
2551 (define-key menu-bar-edit-menu [paste]
2552 (append '(menu-item "Paste" x-clipboard-yank
2553 :enable (not buffer-read-only)
2554 :help "Paste (yank) text most recently cut/copied")
2555 nil))
2556
2557 (setq x-initialized t))
2558
2559 (add-to-list 'handle-args-function-alist '(x . x-handle-args))
2560 (add-to-list 'frame-creation-function-alist '(x . x-create-frame-with-faces))
2561 (add-to-list 'window-system-initialization-alist '(x . x-initialize-window-system))
2562
2563 (provide 'x-win)
2544 2564
2545 ;; Initiate drag and drop 2565 ;; Initiate drag and drop
2546 (add-hook 'after-make-frame-functions 'x-dnd-init-frame) 2566 (add-hook 'after-make-frame-functions 'x-dnd-init-frame)
2547 (define-key special-event-map [drag-n-drop] 'x-dnd-handle-drag-n-drop-event) 2567 (define-key special-event-map [drag-n-drop] 'x-dnd-handle-drag-n-drop-event)
2548 2568