0
|
1 ;;; x-win-sun.el --- runtime initialization for Sun X servers and keyboards
|
|
2 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; Authors: jwz@netscape.com, wing@666.com, mrb@eng.sun.com
|
|
5 ;; Keywords: terminals
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
22
|
|
23 ;;; Commentary:
|
|
24
|
|
25 ;; This file is loaded by x-win.el at run-time when we are sure that XEmacs
|
|
26 ;; is running on the display of a Sun.
|
|
27
|
|
28 ;; The Sun X server (both the MIT and OpenWindows varieties) have extremely
|
|
29 ;; stupid names for their keypad and function keys. For example, the key
|
|
30 ;; labeled 3 / PgDn, with R15 written on the front, is actually called F35.
|
|
31
|
|
32 ;; There are 3 methods of dealing with the Sun key brokenness:
|
|
33 ;;
|
|
34 ;; - Use xmodmap to give all keys more sensible names for all apps:
|
|
35 ;; I use this shell script:
|
|
36 ;;
|
|
37 ;; for i in 0 1 2 3 4 5 6 7 8 9 Add Subtract Multiply Divide Decimal ; do
|
|
38 ;; echo "keysym KP_$i = KP_$i"
|
|
39 ;; done
|
|
40 ;;
|
|
41 ;; Clearly, as a good X11 citizen, we can't do this.
|
|
42 ;;
|
|
43 ;; - Use keyboard-translate-table to remap the keybindings at a low level.
|
|
44 ;; This approach is taken in the function `sun-x11-keyboard-translate'.
|
|
45 ;; This is like running xmodmap within XEmacs only.
|
|
46 ;; This is not the default, however, so that legacy keybindings in users'
|
|
47 ;; .emacs files like (global-set-key [(f35)] 'foo) continue to work
|
|
48 ;;
|
|
49 ;; - Use keyboard macros to provide indirection for keybindings.
|
|
50 ;; If we do (global-set-key [(f35)] [(kp_3)]), then the user's keybindings
|
|
51 ;; work whether he uses `f35' or `kp_3'.
|
|
52 ;; This is also compatible with FSF Emacs and other X11 apps.
|
|
53 ;; Although this has the disadvantage that these remappings
|
|
54 ;; only work with the global key map, we use this as the default.
|
|
55 ;;
|
|
56 ;; - The Right Way to do this remains to be written...
|
|
57
|
|
58 ;; OK, here's another try at doing things the right way.
|
|
59
|
|
60 ;; We use function-key-map, which honors explicit key-bindings for the
|
|
61 ;; stupid Sun names, but also allows indirection if no explicit
|
|
62 ;; key-binding exists.
|
|
63
|
|
64 ;;; Code:
|
|
65
|
|
66 (defun x11-remap-keysyms-using-function-key-map (mapping)
|
|
67 (while mapping
|
|
68 (let ((k1 (caar mapping))
|
|
69 (k2 (cdar mapping)))
|
|
70 (mapc #'(lambda (prefix)
|
|
71 (define-key function-key-map
|
|
72 (append prefix (list k1))
|
|
73 (vector (append prefix (list k2)))))
|
|
74 '(() (shift) (control) (meta) (alt)
|
|
75 (shift control) (shift alt) (shift meta)
|
|
76 (control alt) (control meta) (alt meta)
|
|
77 (shift control alt) (shift control meta)
|
|
78 (shift alt meta) (control alt meta)
|
|
79 (shift control alt meta))
|
|
80 ))
|
|
81 (setq mapping (cdr mapping))))
|
|
82
|
|
83 (x11-remap-keysyms-using-function-key-map
|
|
84 ;; help is ok
|
|
85 ;; num_lock is ok
|
|
86 ;; up is ok
|
|
87 ;; left is ok
|
|
88 ;; right is ok
|
|
89 ;; kp_add is ok
|
|
90 ;; down is ok
|
|
91 ;; insert is ok
|
|
92 ;; delete is ok
|
|
93 ;; kp_enter is ok
|
|
94 (append
|
|
95 ;; Sun Function keys
|
2
|
96 (cond ((x-keysym-on-keyboard-p "F21")
|
|
97 '((f21 . pause)
|
|
98 (f22 . print)
|
|
99 (f23 . scroll_lock))))
|
|
100
|
0
|
101 (cond ((x-keysym-on-keyboard-p "SunCut") ; X11 R6 mappings
|
|
102 '((SunProps . props) (Undo . undo)
|
|
103 (SunFront . front) (SunCopy . copy)
|
|
104 (SunOpen . open) (SunPaste . paste)
|
|
105 (SunFind . find) (SunCut . cut)
|
|
106 (cancel . stop)))
|
|
107
|
|
108 ((x-keysym-on-keyboard-p "F20")
|
|
109 '((f13 . props) (f14 . undo)
|
|
110 (f15 . front) (f16 . copy)
|
|
111 (f17 . open) (f18 . paste)
|
|
112 (f19 . find) (f20 . cut))))
|
|
113
|
|
114 (if (x-keysym-on-keyboard-p "F25") ; Sun Sparc keyboards
|
|
115 (append
|
|
116 '((f21 . pause)
|
|
117 (f22 . prsc)
|
|
118 (f23 . scroll)
|
|
119 (f25 . kp_divide)
|
|
120 (f26 . kp_multiply)
|
|
121 (f31 . kp_5))
|
2
|
122
|
|
123 ;; Map f33 and r13 to end or kp_end
|
|
124 (cond
|
|
125 ((not (x-keysym-on-keyboard-p "End"))
|
|
126 '((f33 . end) (r13 . end)))
|
|
127 ((not (x-keysym-on-keyboard-p "KP_End"))
|
|
128 '((f33 . kp_end) (r13 . kp_end))))
|
|
129
|
0
|
130 (if (x-keysym-on-keyboard-p "F36")
|
|
131 '((f36 . stop) (f37 . again)) ; MIT Type 5 name
|
2
|
132 '((f11 . stop) (f12 . again))) ; Sun name or MIT Type 4 name
|
0
|
133
|
2
|
134 ;; Type 4 keyboards have a real kp_subtract and a f24 labelled `='
|
|
135 ;; Type 5 keyboards have no key labelled `=' and a f24 labelled `-'
|
|
136 (if (x-keysym-on-keyboard-p "F24")
|
|
137 (if (x-keysym-on-keyboard-p "KP_Subtract")
|
|
138 '((f24 . kp_equal))
|
|
139 '((f24 . kp_subtract))))
|
0
|
140
|
2
|
141 ;; Map f27 to home or kp_home, as appropriate
|
|
142 (cond ((not (x-keysym-on-keyboard-p "Home")) '((f27 . home)))
|
|
143 ((not (x-keysym-on-keyboard-p "KP_Home")) '((f27 . kp_home))))
|
0
|
144
|
2
|
145 ;; Map f29 to prior or kp_prior, as appropriate
|
|
146 (cond ((not (x-keysym-on-keyboard-p "Prior")) '((f29 . prior)))
|
|
147 ((not (x-keysym-on-keyboard-p "KP_Prior")) '((f29 . kp_prior))))
|
0
|
148
|
2
|
149 ;; Map f35 to next or kp_next, as appropriate
|
|
150 (cond ((not (x-keysym-on-keyboard-p "Next")) '((f35 . next)))
|
|
151 ((not (x-keysym-on-keyboard-p "KP_Next")) '((f35 . kp_next))))
|
|
152 ))
|
0
|
153
|
|
154 (cond ((x-keysym-on-keyboard-p "apRead") ; SunOS 4.1.1
|
|
155 '((apRead . f11) (apEdit . f12)))
|
|
156 ((x-keysym-on-keyboard-p "SunF36") ; SunOS 5
|
|
157 '((SunF36 . f11) (SunF37 . f12))))
|
2
|
158
|
|
159 ;; !@#$ SunOS 4 with SunOS5 X server
|
|
160 (if (string-match "sunos4.1" system-configuration)
|
|
161 '((unknown_keysym_0xFF9A . kp_prior)
|
|
162 (unknown_keysym_0xFF9B . kp_next)
|
|
163 (unknown_keysym_0xFF95 . kp_home)
|
|
164 (unknown_keysym_0xFF9C . kp_end)
|
|
165 (unknown_keysym_0xFF96 . kp_left)
|
|
166 (unknown_keysym_0xFF97 . kp_up)
|
|
167 (unknown_keysym_0xFF98 . kp_right)
|
|
168 (unknown_keysym_0xFF99 . kp_down)
|
|
169 (unknown_keysym_0xFF9E . kp_insert)))
|
0
|
170 ))
|
|
171
|
|
172 (fmakunbound 'x11-remap-keysyms-using-function-key-map)
|
|
173
|
|
174
|
|
175 ;; for each element in the left column of the above table, alias it
|
|
176 ;; to the thing in the right column. Then do the same for mamy, but
|
|
177 ;; not all, modifier combinations.
|
|
178 ;;
|
|
179 ;; (Well, we omit hyper and super. #### Handle this some other way!)
|
|
180 ; (while mapping
|
|
181 ; (let ((mods '(() (shift) (control) (meta) (alt))))
|
|
182 ; (while mods
|
|
183 ; (let ((k1 (vector (append (car mods) (list (car (car mapping))))))
|
|
184 ; (k2 (vector (append (car mods) (list (cdr (car mapping)))))))
|
|
185 ; (define-key global-map k1 k2))
|
|
186 ; (setq mods (cdr mods))))
|
|
187 ; (setq mapping (cdr mapping))))
|
|
188
|
|
189 ;;; I've extended keyboard-translate-table to work over keysyms.
|
|
190 ;;; [FSF Emacs has something called `system-key-alist' that is
|
|
191 ;;; supposed to accomplish approximately the same thing. Unfortunately,
|
|
192 ;;; it's brain-dead in the typically FSF way, and associates *numbers*
|
|
193 ;;; (who knows where the hell they come from?) with symbols.] --ben
|
|
194
|
|
195 ;;; And I've made it into a function which is not called by default --mrb
|
|
196
|
|
197 (defun sun-x11-keyboard-translate ()
|
|
198 "Remap Sun's X11 keyboard.
|
|
199 Keys with names like `f35' are remapped, at a low level,
|
|
200 to more mnemonic ones,like `kp_3'."
|
|
201 (interactive)
|
|
202
|
|
203 (keyboard-translate
|
|
204 'f11 'stop ; the type4 keyboard Sun/MIT name
|
|
205 'f36 'stop ; the type5 keyboard Sun name
|
|
206 'cancel 'stop ; R6 binding
|
|
207 'f12 'again ; the type4 keyboard Sun/MIT name
|
|
208 'f37 'again ; the type5 keyboard Sun name
|
|
209 'f13 'props ;
|
|
210 'SunProps 'props ; R6 binding
|
|
211 'f14 'undo ;
|
|
212 'f15 'front ;
|
|
213 'SunFront 'front ; R6 binding
|
|
214 'f16 'copy ;
|
|
215 'SunCopy 'copy ; R6 binding
|
|
216 'f17 'open ;
|
|
217 'SunOpen 'open ; R6 binding
|
|
218 'f18 'paste ;
|
|
219 'SunPaste 'paste ; R6 binding
|
|
220 'f19 'find ;
|
|
221 'f20 'cut ;
|
|
222 'SunCut 'cut ; R6 binding
|
|
223 ;; help is ok
|
|
224 'f21 'pause
|
|
225 'f22 'prsc
|
|
226 'f23 'scroll
|
|
227 ;; num_lock is ok
|
|
228 ;;'f24 'kp_equal) ; type4 only!
|
|
229 'f25 'kp_divide ;
|
|
230 'f26 'kp_multiply ;
|
|
231 'f24 'kp_subtract ; type5 only!
|
|
232 'f27 'kp_7 ;
|
|
233 ;; up is ok
|
|
234 'f29 'kp_9
|
|
235 ;; left is ok
|
|
236 'f31 'kp_5
|
|
237 ;; right is ok
|
|
238 ;; kp_add is ok
|
|
239 'f33 'kp_1 ; the Sun name
|
|
240 'r13 'end ; the MIT name
|
|
241 ;; down is ok
|
|
242 'f35 'kp_3
|
|
243 ;; insert is ok
|
|
244 ;; delete is ok
|
|
245 ;; kp_enter is ok
|
|
246 'SunF36 'f11 ; Type 5 keyboards
|
|
247 'SunF37 'f12 ; Used to be Stop & Again
|
|
248 ))
|
|
249
|
|
250
|
|
251 ;;; OpenWindows-like "find" processing.
|
|
252 ;;; As far as I know, the `find' key is a Sunism, so we do that binding
|
|
253 ;;; here. This is the only Sun-specific keybinding. (The functions
|
|
254 ;;; themselves are in x-win.el in case someone wants to use them when
|
|
255 ;;; not running on a Sun display.)
|
|
256
|
|
257 (define-key global-map 'find 'ow-find)
|
|
258 (define-key global-map '(shift find) 'ow-find-backward)
|
|
259
|
|
260 ;;; x-win-sun.el ends here
|