comparison lisp/x11/x-init.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;;; x-init.el --- initialization code for X windows
2 ;; Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
3 ;; Copyright (C) 1995 Board of Trustees, University of Illinois.
4 ;; Copyright (C) 1995, 1996 Ben Wing.
5
6 ;; Author: various
7 ;; Keywords: terminals
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 ;;; If you want to change this variable, this is the place you must do it.
30 ;;; Do not set it to a string containing periods. X doesn't like that.
31 ;(setq x-emacs-application-class "Emacs")
32
33 ;;; selections and active regions
34
35 ;;; If and only if zmacs-regions is true:
36 ;;;
37 ;;; When a mark is pushed and the region goes into the "active" state, we
38 ;;; assert it as the Primary selection. This causes it to be hilighted.
39 ;;; When the region goes into the "inactive" state, we disown the Primary
40 ;;; selection, causing the region to be dehilighted.
41 ;;;
42 ;;; Note that it is possible for the region to be in the "active" state
43 ;;; and not be hilighted, if it is in the active state and then some other
44 ;;; application asserts the selection. This is probably not a big deal.
45
46 (defun x-activate-region-as-selection ()
47 (if (marker-buffer (mark-marker t))
48 (x-own-selection (cons (point-marker t) (mark-marker t)))))
49
50 ;;; OpenWindows-like "find" processing. These functions are really Sunisms,
51 ;;; but we put them here instead of in x-win-sun.el in case someone wants
52 ;;; to use them when not running on a Sun console (presumably after adding
53 ;;; the to different keys, or putting them on menus.)
54
55 (defvar ow-find-last-string nil)
56 (defvar ow-find-last-clipboard nil)
57
58 (defun ow-find (&optional backward-p)
59 "Search forward the next occurrence of the text of the selection."
60 (interactive)
61 (let ((sel (condition-case () (x-get-selection) (error nil)))
62 (clip (condition-case () (x-get-clipboard) (error nil)))
63 text)
64 (setq text (cond
65 (sel)
66 ((not (equal clip ow-find-last-clipboard))
67 (setq ow-find-last-clipboard clip))
68 (ow-find-last-string)
69 (t (error "No selection available"))))
70 (setq ow-find-last-string text)
71 (cond (backward-p
72 (search-backward text)
73 (set-mark (+ (point) (length text))))
74 (t
75 (search-forward text)
76 (set-mark (- (point) (length text)))))
77 (zmacs-activate-region)))
78
79 (defun ow-find-backward ()
80 "Search backward the previous occurence of the text of the selection."
81 (interactive)
82 (ow-find t))
83
84 ;;; Load X-server specific code.
85 ;;; Specifically, load some code to repair the grievous damage that MIT and
86 ;;; Sun have done to the default keymap for the Sun keyboards.
87
88 (defun x-initialize-keyboard ()
89 "Don't call this."
90 (cond (;; This is some heuristic junk that tries to guess whether this is
91 ;; a Sun keyboard.
92 ;;
93 ;; One way of implementing this (which would require C support) would
94 ;; be to examine the X keymap itself and see if the layout looks even
95 ;; remotely like a Sun - check for the Find key on a particular
96 ;; keycode, for example. It'd be nice to have a table of this to
97 ;; recognize various keyboards; see also xkeycaps.
98 ;;
99 (let ((vendor (x-server-vendor)))
100 (or (string-match "Sun Microsystems" vendor)
101 ;; MIT losingly fails to tell us what hardware the X server
102 ;; is managing, so assume all MIT displays are Suns... HA HA!
103 (string-equal "MIT X Consortium" vendor)
104 (string-equal "X Consortium" vendor)))
105 ;;
106 ;; Ok, we think this could be a Sun keyboard. Load the Sun code.
107 ;;
108 (or (load "x-win-sun" t t)
109 (warn "Unable to load term file x-win-sun"))
110 )
111 ((string-match "XFree86" (x-server-vendor))
112 ;; Those XFree86 people do some weird keysym stuff, too.
113 (or (load "x-win-xfree86" t t)
114 (warn "Unable to load term file x-win-xfree86")))
115 ))
116
117
118 (defvar pre-x-win-initted nil)
119
120 (defun init-pre-x-win ()
121 "Initialize X Windows at startup (pre). Don't call this."
122 (if (not pre-x-win-initted)
123 (progn
124 (require 'x-iso8859-1)
125 (setq character-set-property 'x-iso8859/1) ; see x-iso8859-1.el
126
127 (setq initial-frame-plist (if initial-frame-unmapped-p
128 '(initially-unmapped t)
129 nil))
130 (setq pre-x-win-initted t))))
131
132 (defvar x-win-initted nil)
133
134 (defun init-x-win ()
135 "Initialize X Windows at startup. Don't call this."
136 (if (not x-win-initted)
137 (progn
138 (init-pre-x-win)
139
140 ;; Open the X display when this file is loaded
141 ;; (Note that the first frame is created later.)
142 (setq x-initial-argv-list (cons (car command-line-args)
143 command-line-args-left))
144 (make-x-device nil)
145 (setq command-line-args-left (cdr x-initial-argv-list))
146 (setq x-win-initted t))))
147
148 (defvar post-x-win-initted nil)
149
150 (defun init-post-x-win ()
151 "Initialize X Windows at startup (post). Don't call this."
152 (if (not post-x-win-initted)
153 (progn
154 ;; We can't load this until after the initial X device is created
155 ;; because the icon initialization needs to access the display to get
156 ;; any toolbar-related color resources.
157 (if (featurep 'toolbar)
158 (init-x-toolbar))
159 ;; these are only ever called if zmacs-regions is true.
160 (add-hook 'zmacs-deactivate-region-hook 'x-disown-selection)
161 (add-hook 'zmacs-activate-region-hook 'x-activate-region-as-selection)
162 (add-hook 'zmacs-update-region-hook 'x-activate-region-as-selection)
163
164 ;; Motif-ish bindings
165 ;; The following two were generally unliked.
166 ;;(define-key global-map '(shift delete)
167 ;; 'x-kill-primary-selection)
168 ;;(define-key global-map '(control delete)
169 ;; 'x-delete-primary-selection)
170 (define-key global-map '(shift insert) 'x-yank-clipboard-selection)
171 (define-key global-map '(control insert) 'x-copy-primary-selection)
172 ;; (Are these Sunisms?)
173 (define-key global-map 'copy 'x-copy-primary-selection)
174 (define-key global-map 'paste 'x-yank-clipboard-selection)
175 (define-key global-map 'cut 'x-kill-primary-selection)
176
177 (define-key global-map 'menu 'popup-mode-menu)
178 ;;(define-key global-map '(shift menu) 'x-goto-menubar) ;NYI
179
180 ;; This runs after the first frame has been created (we can't
181 ;; talk to the X server before that) but before the
182 ;; site-start-file or .emacs file, so sites and users have a
183 ;; chance to override it.
184 (add-hook 'before-init-hook 'x-initialize-keyboard)
185
186 (setq post-x-win-initted t))))
187
188 (defun make-frame-on-display (display &optional parms)
189 "Create a frame on the X display named DISPLAY.
190 DISPLAY should be a standard display string such as \"unix:0\",
191 or nil for the display specified on the command line or in the
192 DISPLAY environment variable.
193
194 PROPS should be an plist of properties, as in the call to `make-frame'.
195
196 This function opens a connection to the display or reuses an existing
197 connection.
198
199 This function is a trivial wrapper around `make-frame-on-device'."
200 (interactive "sMake frame on display: ")
201 (if (equal display "") (setq display nil))
202 (make-frame-on-device 'x display parms))
203
204 ;;; x-init.el ends here