Wed Jul 29 17:27:44 2020 UTC ()
Fix LED defintions to match xkb/xkbInit.c.

Now CapsLock and NumLock LEDs work correctly.
XXX: No ScrollLock LED


(tsutsui)
diff -r1.1 -r1.2 xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c

cvs diff -r1.1 -r1.2 xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c (switch to unified diff)

--- xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c 2020/07/22 20:38:29 1.1
+++ xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c 2020/07/29 17:27:44 1.2
@@ -1,824 +1,853 @@ @@ -1,824 +1,853 @@
1/* $Xorg: sunKbd.c,v 1.3 2000/08/17 19:48:30 cpqbld Exp $ */ 1/* $Xorg: sunKbd.c,v 1.3 2000/08/17 19:48:30 cpqbld Exp $ */
2/*- 2/*-
3 * Copyright 1987 by the Regents of the University of California 3 * Copyright 1987 by the Regents of the University of California
4 * 4 *
5 * Permission to use, copy, modify, and distribute this 5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without 6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright 7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies. The University of California 8 * notice appear in all copies. The University of California
9 * makes no representations about the suitability of this 9 * makes no representations about the suitability of this
10 * software for any purpose. It is provided "as is" without 10 * software for any purpose. It is provided "as is" without
11 * express or implied warranty. 11 * express or implied warranty.
12 */ 12 */
13 13
14/************************************************************ 14/************************************************************
15Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 15Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
16 16
17 All Rights Reserved 17 All Rights Reserved
18 18
19Permission to use, copy, modify, and distribute this 19Permission to use, copy, modify, and distribute this
20software and its documentation for any purpose and without 20software and its documentation for any purpose and without
21fee is hereby granted, provided that the above copyright no- 21fee is hereby granted, provided that the above copyright no-
22tice appear in all copies and that both that copyright no- 22tice appear in all copies and that both that copyright no-
23tice and this permission notice appear in supporting docu- 23tice and this permission notice appear in supporting docu-
24mentation, and that the names of Sun or The Open Group 24mentation, and that the names of Sun or The Open Group
25not be used in advertising or publicity pertaining to 25not be used in advertising or publicity pertaining to
26distribution of the software without specific prior 26distribution of the software without specific prior
27written permission. Sun and The Open Group make no 27written permission. Sun and The Open Group make no
28representations about the suitability of this software for 28representations about the suitability of this software for
29any purpose. It is provided "as is" without any express or 29any purpose. It is provided "as is" without any express or
30implied warranty. 30implied warranty.
31 31
32SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 32SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
33INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 33INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
34NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 34NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
35ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 35ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
36ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 36ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
37PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 37PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
38OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 38OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
39THE USE OR PERFORMANCE OF THIS SOFTWARE. 39THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 40
41********************************************************/ 41********************************************************/
42/* $XFree86: xc/programs/Xserver/hw/sun/sunKbd.c,v 1.9 2003/11/17 22:20:36 dawes Exp $ */ 42/* $XFree86: xc/programs/Xserver/hw/sun/sunKbd.c,v 1.9 2003/11/17 22:20:36 dawes Exp $ */
43 43
44#define NEED_EVENTS 44#define NEED_EVENTS
45#include "sun.h" 45#include "sun.h"
46#include <X11/keysym.h> 46#include <X11/keysym.h>
47#include <X11/Sunkeysym.h> 47#include <X11/Sunkeysym.h>
48#include "mi.h" 48#include "mi.h"
49 49
50#include <X11/extensions/XKB.h> 50#include <X11/extensions/XKB.h>
51#include "xkbsrv.h" 51#include "xkbsrv.h"
52#include "xkbstr.h" 52#include "xkbstr.h"
53 53
 54#ifdef __sun
54#define SUN_LED_MASK 0x0f 55#define SUN_LED_MASK 0x0f
 56#else
 57#define SUN_LED_MASK 0x07
 58#endif
55#define MIN_KEYCODE 7 /* necessary to avoid the mouse buttons */ 59#define MIN_KEYCODE 7 /* necessary to avoid the mouse buttons */
56#define MAX_KEYCODE 255 /* limited by the protocol */ 60#define MAX_KEYCODE 255 /* limited by the protocol */
57#ifndef KB_SUN4 61#ifndef KB_SUN4
58#define KB_SUN4 4 62#define KB_SUN4 4
59#endif 63#endif
60 64
61#define tvminus(tv, tv1, tv2) /* tv = tv1 - tv2 */ \ 65#define tvminus(tv, tv1, tv2) /* tv = tv1 - tv2 */ \
62 if ((tv1).tv_usec < (tv2).tv_usec) { \ 66 if ((tv1).tv_usec < (tv2).tv_usec) { \
63 (tv1).tv_usec += 1000000; \ 67 (tv1).tv_usec += 1000000; \
64 (tv1).tv_sec -= 1; \ 68 (tv1).tv_sec -= 1; \
65 } \ 69 } \
66 (tv).tv_usec = (tv1).tv_usec - (tv2).tv_usec; \ 70 (tv).tv_usec = (tv1).tv_usec - (tv2).tv_usec; \
67 (tv).tv_sec = (tv1).tv_sec - (tv2).tv_sec; 71 (tv).tv_sec = (tv1).tv_sec - (tv2).tv_sec;
68 72
69#define tvplus(tv, tv1, tv2) /* tv = tv1 + tv2 */ \ 73#define tvplus(tv, tv1, tv2) /* tv = tv1 + tv2 */ \
70 (tv).tv_sec = (tv1).tv_sec + (tv2).tv_sec; \ 74 (tv).tv_sec = (tv1).tv_sec + (tv2).tv_sec; \
71 (tv).tv_usec = (tv1).tv_usec + (tv2).tv_usec; \ 75 (tv).tv_usec = (tv1).tv_usec + (tv2).tv_usec; \
72 if ((tv).tv_usec > 1000000) { \ 76 if ((tv).tv_usec > 1000000) { \
73 (tv).tv_usec -= 1000000; \ 77 (tv).tv_usec -= 1000000; \
74 (tv).tv_sec += 1; \ 78 (tv).tv_sec += 1; \
75 } 79 }
76 80
77static void sunKbdHandlerNotify(int, int, void *); 81static void sunKbdHandlerNotify(int, int, void *);
78static void SwapLKeys(KeySymsRec *); 82static void SwapLKeys(KeySymsRec *);
79static void SetLights(KeybdCtrl *, int); 83static void SetLights(KeybdCtrl *, int);
80static KeyCode LookupKeyCode(KeySym, XkbDescPtr, KeySymsPtr); 84static KeyCode LookupKeyCode(KeySym, XkbDescPtr, KeySymsPtr);
81static void pseudoKey(DeviceIntPtr, Bool, KeyCode); 85static void pseudoKey(DeviceIntPtr, Bool, KeyCode);
82static void DoLEDs(DeviceIntPtr, KeybdCtrl *, sunKbdPrivPtr); 86static void DoLEDs(DeviceIntPtr, KeybdCtrl *, sunKbdPrivPtr);
83 87
84DeviceIntPtr sunKeyboardDevice = NULL; 88DeviceIntPtr sunKeyboardDevice = NULL;
85 89
86static void 90static void
87sunKbdHandlerNotify(int fd __unused, int ready __unused, void *data __unused) 91sunKbdHandlerNotify(int fd __unused, int ready __unused, void *data __unused)
88{ 92{
89} 93}
90 94
91void 95void
92sunKbdWait(void) 96sunKbdWait(void)
93{ 97{
94 static struct timeval lastChngKbdTransTv; 98 static struct timeval lastChngKbdTransTv;
95 struct timeval tv; 99 struct timeval tv;
96 struct timeval lastChngKbdDeltaTv; 100 struct timeval lastChngKbdDeltaTv;
97 unsigned int lastChngKbdDelta; 101 unsigned int lastChngKbdDelta;
98 102
99 X_GETTIMEOFDAY(&tv); 103 X_GETTIMEOFDAY(&tv);
100 if (!lastChngKbdTransTv.tv_sec) 104 if (!lastChngKbdTransTv.tv_sec)
101 lastChngKbdTransTv = tv; 105 lastChngKbdTransTv = tv;
102 tvminus(lastChngKbdDeltaTv, tv, lastChngKbdTransTv); 106 tvminus(lastChngKbdDeltaTv, tv, lastChngKbdTransTv);
103 lastChngKbdDelta = TVTOMILLI(lastChngKbdDeltaTv); 107 lastChngKbdDelta = TVTOMILLI(lastChngKbdDeltaTv);
104 if (lastChngKbdDelta < 750) { 108 if (lastChngKbdDelta < 750) {
105 unsigned wait; 109 unsigned wait;
106 /* 110 /*
107 * We need to guarantee at least 750 milliseconds between 111 * We need to guarantee at least 750 milliseconds between
108 * calls to KIOCTRANS. YUCK! 112 * calls to KIOCTRANS. YUCK!
109 */ 113 */
110 wait = (750L - lastChngKbdDelta) * 1000L; 114 wait = (750L - lastChngKbdDelta) * 1000L;
111 usleep (wait); 115 usleep (wait);
112 X_GETTIMEOFDAY(&tv); 116 X_GETTIMEOFDAY(&tv);
113 } 117 }
114 lastChngKbdTransTv = tv; 118 lastChngKbdTransTv = tv;
115} 119}
116 120
117static 121static
118void SwapLKeys(KeySymsRec* keysyms) 122void SwapLKeys(KeySymsRec* keysyms)
119{ 123{
120 unsigned int i; 124 unsigned int i;
121 KeySym k; 125 KeySym k;
122 126
123 for (i = 2; i < keysyms->maxKeyCode * keysyms->mapWidth; i++) 127 for (i = 2; i < keysyms->maxKeyCode * keysyms->mapWidth; i++)
124 if (keysyms->map[i] == XK_L1 || 128 if (keysyms->map[i] == XK_L1 ||
125 keysyms->map[i] == XK_L2 || 129 keysyms->map[i] == XK_L2 ||
126 keysyms->map[i] == XK_L3 || 130 keysyms->map[i] == XK_L3 ||
127 keysyms->map[i] == XK_L4 || 131 keysyms->map[i] == XK_L4 ||
128 keysyms->map[i] == XK_L5 || 132 keysyms->map[i] == XK_L5 ||
129 keysyms->map[i] == XK_L6 || 133 keysyms->map[i] == XK_L6 ||
130 keysyms->map[i] == XK_L7 || 134 keysyms->map[i] == XK_L7 ||
131 keysyms->map[i] == XK_L8 || 135 keysyms->map[i] == XK_L8 ||
132 keysyms->map[i] == XK_L9 || 136 keysyms->map[i] == XK_L9 ||
133 keysyms->map[i] == XK_L10) { 137 keysyms->map[i] == XK_L10) {
134 /* yes, I could have done a clever two line swap! */ 138 /* yes, I could have done a clever two line swap! */
135 k = keysyms->map[i - 2]; 139 k = keysyms->map[i - 2];
136 keysyms->map[i - 2] = keysyms->map[i]; 140 keysyms->map[i - 2] = keysyms->map[i];
137 keysyms->map[i] = k; 141 keysyms->map[i] = k;
138 } 142 }
139} 143}
140 144
141static void 145static void
142SetLights(KeybdCtrl* ctrl, int fd) 146SetLights(KeybdCtrl* ctrl, int fd)
143{ 147{
144#ifdef KIOCSLED 148#ifdef KIOCSLED
145 static unsigned char led_tab[16] = { 149 static unsigned char led_tab[16] = {
146 0, 150 0,
 151#ifdef __sun
147 LED_NUM_LOCK, 152 LED_NUM_LOCK,
148 LED_SCROLL_LOCK, 153 LED_SCROLL_LOCK,
149 LED_SCROLL_LOCK | LED_NUM_LOCK, 154 LED_SCROLL_LOCK | LED_NUM_LOCK,
150 LED_COMPOSE, 155 LED_COMPOSE,
151 LED_COMPOSE | LED_NUM_LOCK, 156 LED_COMPOSE | LED_NUM_LOCK,
152 LED_COMPOSE | LED_SCROLL_LOCK, 157 LED_COMPOSE | LED_SCROLL_LOCK,
153 LED_COMPOSE | LED_SCROLL_LOCK | LED_NUM_LOCK, 158 LED_COMPOSE | LED_SCROLL_LOCK | LED_NUM_LOCK,
154 LED_CAPS_LOCK, 159 LED_CAPS_LOCK,
155 LED_CAPS_LOCK | LED_NUM_LOCK, 160 LED_CAPS_LOCK | LED_NUM_LOCK,
156 LED_CAPS_LOCK | LED_SCROLL_LOCK, 161 LED_CAPS_LOCK | LED_SCROLL_LOCK,
157 LED_CAPS_LOCK | LED_SCROLL_LOCK | LED_NUM_LOCK, 162 LED_CAPS_LOCK | LED_SCROLL_LOCK | LED_NUM_LOCK,
158 LED_CAPS_LOCK | LED_COMPOSE, 163 LED_CAPS_LOCK | LED_COMPOSE,
159 LED_CAPS_LOCK | LED_COMPOSE | LED_NUM_LOCK, 164 LED_CAPS_LOCK | LED_COMPOSE | LED_NUM_LOCK,
160 LED_CAPS_LOCK | LED_COMPOSE | LED_SCROLL_LOCK, 165 LED_CAPS_LOCK | LED_COMPOSE | LED_SCROLL_LOCK,
161 LED_CAPS_LOCK | LED_COMPOSE | LED_SCROLL_LOCK | LED_NUM_LOCK 166 LED_CAPS_LOCK | LED_COMPOSE | LED_SCROLL_LOCK | LED_NUM_LOCK
 167#else
 168 LED_CAPS_LOCK,
 169 LED_NUM_LOCK,
 170 LED_NUM_LOCK | LED_CAPS_LOCK,
 171 LED_SCROLL_LOCK,
 172 LED_SCROLL_LOCK | LED_CAPS_LOCK,
 173 LED_SCROLL_LOCK | LED_NUM_LOCK,
 174 LED_SCROLL_LOCK | LED_NUM_LOCK | LED_CAPS_LOCK,
 175 LED_COMPOSE,
 176 LED_COMPOSE | LED_CAPS_LOCK,
 177 LED_COMPOSE | LED_NUM_LOCK,
 178 LED_COMPOSE | LED_NUM_LOCK | LED_CAPS_LOCK,
 179 LED_COMPOSE | LED_SCROLL_LOCK,
 180 LED_COMPOSE | LED_SCROLL_LOCK | LED_CAPS_LOCK,
 181 LED_COMPOSE | LED_SCROLL_LOCK | LED_NUM_LOCK,
 182 LED_COMPOSE | LED_SCROLL_LOCK | LED_NUM_LOCK | LED_CAPS_LOCK,
 183#endif
162 }; 184 };
163 if (ioctl (fd, KIOCSLED, (caddr_t)&led_tab[ctrl->leds & 0x0f]) == -1) 185 if (ioctl (fd, KIOCSLED, (caddr_t)&led_tab[ctrl->leds & SUN_LED_MASK]) == -1)
164 ErrorF("Failed to set keyboard lights"); 186 ErrorF("Failed to set keyboard lights");
165#endif 187#endif
166} 188}
167 189
168 190
169/*- 191/*-
170 *----------------------------------------------------------------------- 192 *-----------------------------------------------------------------------
171 * sunBell -- 193 * sunBell --
172 * Ring the terminal/keyboard bell 194 * Ring the terminal/keyboard bell
173 * 195 *
174 * Results: 196 * Results:
175 * Ring the keyboard bell for an amount of time proportional to 197 * Ring the keyboard bell for an amount of time proportional to
176 * "loudness." 198 * "loudness."
177 * 199 *
178 * Side Effects: 200 * Side Effects:
179 * None, really... 201 * None, really...
180 * 202 *
181 *----------------------------------------------------------------------- 203 *-----------------------------------------------------------------------
182 */ 204 */
183 205
184static void 206static void
185bell(int fd, int duration) 207bell(int fd, int duration)
186{ 208{
187 int kbdCmd; /* Command to give keyboard */ 209 int kbdCmd; /* Command to give keyboard */
188 210
189 kbdCmd = KBD_CMD_BELL; 211 kbdCmd = KBD_CMD_BELL;
190 if (ioctl (fd, KIOCCMD, &kbdCmd) == -1) { 212 if (ioctl (fd, KIOCCMD, &kbdCmd) == -1) {
191 ErrorF("Failed to activate bell"); 213 ErrorF("Failed to activate bell");
192 return; 214 return;
193 } 215 }
194 if (duration) usleep (duration); 216 if (duration) usleep (duration);
195 kbdCmd = KBD_CMD_NOBELL; 217 kbdCmd = KBD_CMD_NOBELL;
196 if (ioctl (fd, KIOCCMD, &kbdCmd) == -1) 218 if (ioctl (fd, KIOCCMD, &kbdCmd) == -1)
197 ErrorF("Failed to deactivate bell"); 219 ErrorF("Failed to deactivate bell");
198} 220}
199 221
200static void 222static void
201sunBell(int percent, DeviceIntPtr device, void *ctrl, int unused) 223sunBell(int percent, DeviceIntPtr device, void *ctrl, int unused)
202{ 224{
203 KeybdCtrl* kctrl = (KeybdCtrl*) ctrl; 225 KeybdCtrl* kctrl = (KeybdCtrl*) ctrl;
204 sunKbdPrivPtr pPriv = (sunKbdPrivPtr) device->public.devicePrivate; 226 sunKbdPrivPtr pPriv = (sunKbdPrivPtr) device->public.devicePrivate;
205 227
206 if (percent == 0 || kctrl->bell == 0) 228 if (percent == 0 || kctrl->bell == 0)
207 return; 229 return;
208 230
209 bell (pPriv->fd, kctrl->bell_duration * 1000); 231 bell (pPriv->fd, kctrl->bell_duration * 1000);
210} 232}
211 233
212void 234void
213DDXRingBell(int volume, int pitch, int duration) 235DDXRingBell(int volume, int pitch, int duration)
214{ 236{
215 DeviceIntPtr pKeyboard; 237 DeviceIntPtr pKeyboard;
216 sunKbdPrivPtr pPriv; 238 sunKbdPrivPtr pPriv;
217 239
218 pKeyboard = sunKeyboardDevice; 240 pKeyboard = sunKeyboardDevice;
219 if (pKeyboard != NULL) { 241 if (pKeyboard != NULL) {
220 pPriv = (sunKbdPrivPtr)pKeyboard->public.devicePrivate; 242 pPriv = (sunKbdPrivPtr)pKeyboard->public.devicePrivate;
221 bell(pPriv->fd, duration * 1000); 243 bell(pPriv->fd, duration * 1000);
222 } 244 }
223} 245}
224 246
225 247
 248#ifdef __sun
226#define XLED_NUM_LOCK 0x1 249#define XLED_NUM_LOCK 0x1
227#define XLED_COMPOSE 0x4 250#define XLED_COMPOSE 0x4
228#define XLED_SCROLL_LOCK 0x2 251#define XLED_SCROLL_LOCK 0x2
229#define XLED_CAPS_LOCK 0x8 252#define XLED_CAPS_LOCK 0x8
 253#else
 254#define XLED_NUM_LOCK 0x2
 255#define XLED_COMPOSE 0x8
 256#define XLED_SCROLL_LOCK 0x4
 257#define XLED_CAPS_LOCK 0x1
 258#endif
230 259
231static KeyCode 260static KeyCode
232LookupKeyCode(KeySym keysym, XkbDescPtr xkb, KeySymsPtr syms) 261LookupKeyCode(KeySym keysym, XkbDescPtr xkb, KeySymsPtr syms)
233{ 262{
234 KeyCode i; 263 KeyCode i;
235 int ii, index = 0; 264 int ii, index = 0;
236 265
237 for (i = xkb->min_key_code; i < xkb->max_key_code; i++) 266 for (i = xkb->min_key_code; i < xkb->max_key_code; i++)
238 for (ii = 0; ii < syms->mapWidth; ii++) 267 for (ii = 0; ii < syms->mapWidth; ii++)
239 if (syms->map[index++] == keysym) 268 if (syms->map[index++] == keysym)
240 return i; 269 return i;
241 return 0; 270 return 0;
242} 271}
243 272
244static void 273static void
245pseudoKey(DeviceIntPtr device, Bool down, KeyCode keycode) 274pseudoKey(DeviceIntPtr device, Bool down, KeyCode keycode)
246{ 275{
247 int bit; 276 int bit;
248 CARD8 modifiers; 277 CARD8 modifiers;
249 CARD16 mask; 278 CARD16 mask;
250 BYTE* kptr; 279 BYTE* kptr;
251 280
252 kptr = &device->key->down[keycode >> 3]; 281 kptr = &device->key->down[keycode >> 3];
253 bit = 1 << (keycode & 7); 282 bit = 1 << (keycode & 7);
254 modifiers = device->key->xkbInfo->desc->map->modmap[keycode]; 283 modifiers = device->key->xkbInfo->desc->map->modmap[keycode];
255 if (down) { 284 if (down) {
256 /* fool dix into thinking this key is now "down" */ 285 /* fool dix into thinking this key is now "down" */
257 int i; 286 int i;
258 *kptr |= bit; 287 *kptr |= bit;
259 for (i = 0, mask = 1; modifiers; i++, mask <<= 1) 288 for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
260 if (mask & modifiers) { 289 if (mask & modifiers) {
261 device->key->modifierKeyCount[i]++; 290 device->key->modifierKeyCount[i]++;
262 modifiers &= ~mask; 291 modifiers &= ~mask;
263 } 292 }
264 } else { 293 } else {
265 /* fool dix into thinking this key is now "up" */ 294 /* fool dix into thinking this key is now "up" */
266 if (*kptr & bit) { 295 if (*kptr & bit) {
267 int i; 296 int i;
268 *kptr &= ~bit; 297 *kptr &= ~bit;
269 for (i = 0, mask = 1; modifiers; i++, mask <<= 1) 298 for (i = 0, mask = 1; modifiers; i++, mask <<= 1)
270 if (mask & modifiers) { 299 if (mask & modifiers) {
271 if (--device->key->modifierKeyCount[i] <= 0) { 300 if (--device->key->modifierKeyCount[i] <= 0) {
272 device->key->modifierKeyCount[i] = 0; 301 device->key->modifierKeyCount[i] = 0;
273 } 302 }
274 modifiers &= ~mask; 303 modifiers &= ~mask;
275 } 304 }
276 } 305 }
277 } 306 }
278} 307}
279 308
280static void 309static void
281DoLEDs( 310DoLEDs(
282 DeviceIntPtr device, /* Keyboard to alter */ 311 DeviceIntPtr device, /* Keyboard to alter */
283 KeybdCtrl* ctrl, 312 KeybdCtrl* ctrl,
284 sunKbdPrivPtr pPriv 313 sunKbdPrivPtr pPriv
285) 314)
286{ 315{
287 XkbDescPtr xkb; 316 XkbDescPtr xkb;
288 KeySymsPtr syms; 317 KeySymsPtr syms;
289 318
290 xkb = device->key->xkbInfo->desc; 319 xkb = device->key->xkbInfo->desc;
291 syms = XkbGetCoreMap(device); 320 syms = XkbGetCoreMap(device);
292 if (!syms) 321 if (!syms)
293 return; /* XXX */ 322 return; /* XXX */
294 323
295 if ((ctrl->leds & XLED_CAPS_LOCK) && !(pPriv->leds & XLED_CAPS_LOCK)) 324 if ((ctrl->leds & XLED_CAPS_LOCK) && !(pPriv->leds & XLED_CAPS_LOCK))
296 pseudoKey(device, TRUE, 325 pseudoKey(device, TRUE,
297 LookupKeyCode(XK_Caps_Lock, xkb, syms)); 326 LookupKeyCode(XK_Caps_Lock, xkb, syms));
298 327
299 if (!(ctrl->leds & XLED_CAPS_LOCK) && (pPriv->leds & XLED_CAPS_LOCK)) 328 if (!(ctrl->leds & XLED_CAPS_LOCK) && (pPriv->leds & XLED_CAPS_LOCK))
300 pseudoKey(device, FALSE, 329 pseudoKey(device, FALSE,
301 LookupKeyCode(XK_Caps_Lock, xkb, syms)); 330 LookupKeyCode(XK_Caps_Lock, xkb, syms));
302 331
303 if ((ctrl->leds & XLED_NUM_LOCK) && !(pPriv->leds & XLED_NUM_LOCK)) 332 if ((ctrl->leds & XLED_NUM_LOCK) && !(pPriv->leds & XLED_NUM_LOCK))
304 pseudoKey(device, TRUE, 333 pseudoKey(device, TRUE,
305 LookupKeyCode(XK_Num_Lock, xkb, syms)); 334 LookupKeyCode(XK_Num_Lock, xkb, syms));
306 335
307 if (!(ctrl->leds & XLED_NUM_LOCK) && (pPriv->leds & XLED_NUM_LOCK)) 336 if (!(ctrl->leds & XLED_NUM_LOCK) && (pPriv->leds & XLED_NUM_LOCK))
308 pseudoKey(device, FALSE, 337 pseudoKey(device, FALSE,
309 LookupKeyCode(XK_Num_Lock, xkb, syms)); 338 LookupKeyCode(XK_Num_Lock, xkb, syms));
310 339
311 if ((ctrl->leds & XLED_SCROLL_LOCK) && !(pPriv->leds & XLED_SCROLL_LOCK)) 340 if ((ctrl->leds & XLED_SCROLL_LOCK) && !(pPriv->leds & XLED_SCROLL_LOCK))
312 pseudoKey(device, TRUE, 341 pseudoKey(device, TRUE,
313 LookupKeyCode(XK_Scroll_Lock, xkb, syms)); 342 LookupKeyCode(XK_Scroll_Lock, xkb, syms));
314 343
315 if (!(ctrl->leds & XLED_SCROLL_LOCK) && (pPriv->leds & XLED_SCROLL_LOCK)) 344 if (!(ctrl->leds & XLED_SCROLL_LOCK) && (pPriv->leds & XLED_SCROLL_LOCK))
316 pseudoKey(device, FALSE, 345 pseudoKey(device, FALSE,
317 LookupKeyCode(XK_Scroll_Lock, xkb, syms)); 346 LookupKeyCode(XK_Scroll_Lock, xkb, syms));
318 347
319 if ((ctrl->leds & XLED_COMPOSE) && !(pPriv->leds & XLED_COMPOSE)) 348 if ((ctrl->leds & XLED_COMPOSE) && !(pPriv->leds & XLED_COMPOSE))
320 pseudoKey(device, TRUE, 349 pseudoKey(device, TRUE,
321 LookupKeyCode(SunXK_Compose, xkb, syms)); 350 LookupKeyCode(SunXK_Compose, xkb, syms));
322 351
323 if (!(ctrl->leds & XLED_COMPOSE) && (pPriv->leds & XLED_COMPOSE)) 352 if (!(ctrl->leds & XLED_COMPOSE) && (pPriv->leds & XLED_COMPOSE))
324 pseudoKey(device, FALSE, 353 pseudoKey(device, FALSE,
325 LookupKeyCode(SunXK_Compose, xkb, syms)); 354 LookupKeyCode(SunXK_Compose, xkb, syms));
326 355
327 pPriv->leds = ctrl->leds & 0x0f; 356 pPriv->leds = ctrl->leds & SUN_LED_MASK;
328 SetLights (ctrl, pPriv->fd); 357 SetLights (ctrl, pPriv->fd);
329 free(syms->map); 358 free(syms->map);
330 free(syms); 359 free(syms);
331} 360}
332 361
333/*- 362/*-
334 *----------------------------------------------------------------------- 363 *-----------------------------------------------------------------------
335 * sunKbdCtrl -- 364 * sunKbdCtrl --
336 * Alter some of the keyboard control parameters 365 * Alter some of the keyboard control parameters
337 * 366 *
338 * Results: 367 * Results:
339 * None. 368 * None.
340 * 369 *
341 * Side Effects: 370 * Side Effects:
342 * Some... 371 * Some...
343 * 372 *
344 *----------------------------------------------------------------------- 373 *-----------------------------------------------------------------------
345 */ 374 */
346 375
347static void 376static void
348sunKbdCtrl(DeviceIntPtr device, KeybdCtrl* ctrl) 377sunKbdCtrl(DeviceIntPtr device, KeybdCtrl* ctrl)
349{ 378{
350 sunKbdPrivPtr pPriv = (sunKbdPrivPtr) device->public.devicePrivate; 379 sunKbdPrivPtr pPriv = (sunKbdPrivPtr) device->public.devicePrivate;
351 380
352 if (pPriv->fd < 0) return; 381 if (pPriv->fd < 0) return;
353 382
354 if (ctrl->click != pPriv->click) { 383 if (ctrl->click != pPriv->click) {
355 int kbdClickCmd; 384 int kbdClickCmd;
356 385
357 pPriv->click = ctrl->click; 386 pPriv->click = ctrl->click;
358 kbdClickCmd = pPriv->click ? KBD_CMD_CLICK : KBD_CMD_NOCLICK; 387 kbdClickCmd = pPriv->click ? KBD_CMD_CLICK : KBD_CMD_NOCLICK;
359 if (ioctl (pPriv->fd, KIOCCMD, &kbdClickCmd) == -1) 388 if (ioctl (pPriv->fd, KIOCCMD, &kbdClickCmd) == -1)
360 ErrorF("Failed to set keyclick"); 389 ErrorF("Failed to set keyclick");
361 } 390 }
362 if ((pPriv->type == KB_SUN4) && (pPriv->leds != (ctrl->leds & 0x0f))) 391 if ((pPriv->type == KB_SUN4) && (pPriv->leds != (ctrl->leds & SUN_LED_MASK)))
363 DoLEDs(device, ctrl, pPriv); 392 DoLEDs(device, ctrl, pPriv);
364} 393}
365 394
366/*- 395/*-
367 *----------------------------------------------------------------------- 396 *-----------------------------------------------------------------------
368 * sunInitKbdNames -- 397 * sunInitKbdNames --
369 * Handle the XKB initialization 398 * Handle the XKB initialization
370 * 399 *
371 * Results: 400 * Results:
372 * None. 401 * None.
373 * 402 *
374 * Comments: 403 * Comments:
375 * This function needs considerable work, in conjunctions with 404 * This function needs considerable work, in conjunctions with
376 * the need to add geometry descriptions of Sun Keyboards. 405 * the need to add geometry descriptions of Sun Keyboards.
377 * It would also be nice to have #defines for all the keyboard 406 * It would also be nice to have #defines for all the keyboard
378 * layouts so that we don't have to have these hard-coded 407 * layouts so that we don't have to have these hard-coded
379 * numbers. 408 * numbers.
380 * 409 *
381 *----------------------------------------------------------------------- 410 *-----------------------------------------------------------------------
382 */ 411 */
383static void 412static void
384sunInitKbdNames(XkbRMLVOSet *rmlvo, sunKbdPrivPtr pKbd) 413sunInitKbdNames(XkbRMLVOSet *rmlvo, sunKbdPrivPtr pKbd)
385{ 414{
386#if 0 /* XXX to be revisited later */ 415#if 0 /* XXX to be revisited later */
387#ifndef XKBBUFSIZE 416#ifndef XKBBUFSIZE
388#define XKBBUFSIZE 64 417#define XKBBUFSIZE 64
389#endif 418#endif
390 static char keycodesbuf[XKBBUFSIZE]; 419 static char keycodesbuf[XKBBUFSIZE];
391 static char geometrybuf[XKBBUFSIZE]; 420 static char geometrybuf[XKBBUFSIZE];
392 static char symbolsbuf[XKBBUFSIZE]; 421 static char symbolsbuf[XKBBUFSIZE];
393 422
394 names->keymap = NULL; 423 names->keymap = NULL;
395 names->compat = "compat/complete"; 424 names->compat = "compat/complete";
396 names->types = "types/complete"; 425 names->types = "types/complete";
397 names->keycodes = keycodesbuf; 426 names->keycodes = keycodesbuf;
398 names->geometry = geometrybuf; 427 names->geometry = geometrybuf;
399 names->symbols = symbolsbuf; 428 names->symbols = symbolsbuf;
400 (void) strcpy (keycodesbuf, "keycodes/"); 429 (void) strcpy (keycodesbuf, "keycodes/");
401 (void) strcpy (geometrybuf, "geometry/"); 430 (void) strcpy (geometrybuf, "geometry/");
402 (void) strcpy (symbolsbuf, "symbols/"); 431 (void) strcpy (symbolsbuf, "symbols/");
403 432
404 /* keycodes & geometry */ 433 /* keycodes & geometry */
405 switch (pKbd->type) { 434 switch (pKbd->type) {
406 case KB_SUN2: 435 case KB_SUN2:
407 (void) strcat (names->keycodes, "sun(type2)"); 436 (void) strcat (names->keycodes, "sun(type2)");
408 (void) strcat (names->geometry, "sun(type2)"); 437 (void) strcat (names->geometry, "sun(type2)");
409 (void) strcat (names->symbols, "us(sun2)"); 438 (void) strcat (names->symbols, "us(sun2)");
410 break; 439 break;
411 case KB_SUN3: 440 case KB_SUN3:
412 (void) strcat (names->keycodes, "sun(type3)"); 441 (void) strcat (names->keycodes, "sun(type3)");
413 (void) strcat (names->geometry, "sun(type3)"); 442 (void) strcat (names->geometry, "sun(type3)");
414 (void) strcat (names->symbols, "us(sun3)"); 443 (void) strcat (names->symbols, "us(sun3)");
415 break; 444 break;
416 case KB_SUN4: 445 case KB_SUN4:
417 /* First, catch "fully known" models */ 446 /* First, catch "fully known" models */
418 switch (pKbd->layout) { 447 switch (pKbd->layout) {
419 case 11: /* type4, Sweden */ 448 case 11: /* type4, Sweden */
420 (void) strcat (names->geometry, "sun(type4_se)"); 449 (void) strcat (names->geometry, "sun(type4_se)");
421 (void) strcat (names->keycodes, 450 (void) strcat (names->keycodes,
422 "sun(type4_se_swapctl)"); 451 "sun(type4_se_swapctl)");
423 (void) strcat (names->symbols, 452 (void) strcat (names->symbols,
424 "sun/se(sun4)+se(fixdollar)"); 453 "sun/se(sun4)+se(fixdollar)");
425 return; 454 return;
426 break; 455 break;
427 case 43: /* type5/5c, Sweden */ 456 case 43: /* type5/5c, Sweden */
428 (void) strcat (names->geometry, "sun(type5c_se)"); 457 (void) strcat (names->geometry, "sun(type5c_se)");
429 (void) strcat (names->keycodes, "sun(type5_se)"); 458 (void) strcat (names->keycodes, "sun(type5_se)");
430 (void) strcat (names->symbols, 459 (void) strcat (names->symbols,
431 "sun/se(sun5)+se(fixdollar)"); 460 "sun/se(sun5)+se(fixdollar)");
432 return; 461 return;
433 break; 462 break;
434 case 90: /* "Compact 1", Sweden (???) */ 463 case 90: /* "Compact 1", Sweden (???) */
435 break; /* No specific mapping, yet */ 464 break; /* No specific mapping, yet */
436 default: 465 default:
437 break; 466 break;
438 } 467 }
439 468
440 if (pKbd->layout == 19) { 469 if (pKbd->layout == 19) {
441 (void) strcat (names->keycodes, "sun(US101A)"); 470 (void) strcat (names->keycodes, "sun(US101A)");
442 (void) strcat (names->geometry, "pc101-NG"); /* XXX */ 471 (void) strcat (names->geometry, "pc101-NG"); /* XXX */
443 (void) strcat (names->symbols, "us(pc101)"); 472 (void) strcat (names->symbols, "us(pc101)");
444 } else if (pKbd->layout < 33) { 473 } else if (pKbd->layout < 33) {
445 (void) strcat (names->keycodes, "sun(type4)"); 474 (void) strcat (names->keycodes, "sun(type4)");
446 (void) strcat (names->geometry, "sun(type4)"); 475 (void) strcat (names->geometry, "sun(type4)");
447 if (sunSwapLkeys) 476 if (sunSwapLkeys)
448 (void) strcat (names->symbols, "sun/us(sun4ol)"); 477 (void) strcat (names->symbols, "sun/us(sun4ol)");
449 else 478 else
450 (void) strcat (names->symbols, "sun/us(sun4)"); 479 (void) strcat (names->symbols, "sun/us(sun4)");
451 } else { 480 } else {
452 switch (pKbd->layout) { 481 switch (pKbd->layout) {
453 case 33: case 80: /* U.S. */ 482 case 33: case 80: /* U.S. */
454 case 47: case 94: /* Korea */ 483 case 47: case 94: /* Korea */
455 case 48: case 95: /* Taiwan */ 484 case 48: case 95: /* Taiwan */
456 case 49: case 96: /* Japan */ 485 case 49: case 96: /* Japan */
457 (void) strcat (names->keycodes, "sun(type5)"); 486 (void) strcat (names->keycodes, "sun(type5)");
458 (void) strcat (names->geometry, "sun(type5)"); 487 (void) strcat (names->geometry, "sun(type5)");
459 break; 488 break;
460 case 34: case 81: /* U.S. Unix */ 489 case 34: case 81: /* U.S. Unix */
461 (void) strcat (names->keycodes, "sun(type5)"); 490 (void) strcat (names->keycodes, "sun(type5)");
462 (void) strcat (names->geometry, "sun(type5unix)"); 491 (void) strcat (names->geometry, "sun(type5unix)");
463 break; 492 break;
464 default: 493 default:
465 (void) strcat (names->keycodes, "sun(type5_euro)"); 494 (void) strcat (names->keycodes, "sun(type5_euro)");
466 (void) strcat (names->geometry, "sun(type5euro)"); 495 (void) strcat (names->geometry, "sun(type5euro)");
467 } 496 }
468 497
469 if (sunSwapLkeys) 498 if (sunSwapLkeys)
470 (void) strcat (names->symbols, "sun/us(sun5ol)"); 499 (void) strcat (names->symbols, "sun/us(sun5ol)");
471 else 500 else
472 (void) strcat (names->symbols, "sun/us(sun5)"); 501 (void) strcat (names->symbols, "sun/us(sun5)");
473 } 502 }
474 break; 503 break;
475 default: 504 default:
476 names->keycodes = names->geometry = NULL; 505 names->keycodes = names->geometry = NULL;
477 break; 506 break;
478 } 507 }
479 508
480 /* extra symbols */ 509 /* extra symbols */
481 510
482 if (pKbd->type == KB_SUN4) { 511 if (pKbd->type == KB_SUN4) {
483 switch (pKbd->layout) { 512 switch (pKbd->layout) {
484 case 4: case 36: case 83: 513 case 4: case 36: case 83:
485 case 5: case 37: case 84: 514 case 5: case 37: case 84:
486 case 6: case 38: case 85: 515 case 6: case 38: case 85:
487 case 8: case 40: case 87: 516 case 8: case 40: case 87:
488 case 9: case 41: case 88: 517 case 9: case 41: case 88:
489 case 10: case 42: case 89: 518 case 10: case 42: case 89:
490/* case 11: case 43: case 90: */ /* handled earlier */ 519/* case 11: case 43: case 90: */ /* handled earlier */
491 case 12: case 44: case 91: 520 case 12: case 44: case 91:
492 case 13: case 45: case 92: 521 case 13: case 45: case 92:
493 case 14: case 46: case 93: 522 case 14: case 46: case 93:
494 (void) strcat (names->symbols, "+iso9995-3(basic)"); break; 523 (void) strcat (names->symbols, "+iso9995-3(basic)"); break;
495 } 524 }
496 } 525 }
497 526
498 if (pKbd->type == KB_SUN4) { 527 if (pKbd->type == KB_SUN4) {
499 switch (pKbd->layout) { 528 switch (pKbd->layout) {
500 case 0: case 1: case 33: case 34: case 80: case 81: 529 case 0: case 1: case 33: case 34: case 80: case 81:
501 break; 530 break;
502 case 3: 531 case 3:
503 (void) strcat (names->symbols, "+ca"); break; 532 (void) strcat (names->symbols, "+ca"); break;
504 case 4: case 36: case 83: 533 case 4: case 36: case 83:
505 (void) strcat (names->symbols, "+dk"); break; 534 (void) strcat (names->symbols, "+dk"); break;
506 case 5: case 37: case 84: 535 case 5: case 37: case 84:
507 (void) strcat (names->symbols, "+de"); break; 536 (void) strcat (names->symbols, "+de"); break;
508 case 6: case 38: case 85: 537 case 6: case 38: case 85:
509 (void) strcat (names->symbols, "+it"); break; 538 (void) strcat (names->symbols, "+it"); break;
510 case 8: case 40: case 87: 539 case 8: case 40: case 87:
511 (void) strcat (names->symbols, "+no"); break; 540 (void) strcat (names->symbols, "+no"); break;
512 case 9: case 41: case 88: 541 case 9: case 41: case 88:
513 (void) strcat (names->symbols, "+pt"); break; 542 (void) strcat (names->symbols, "+pt"); break;
514 case 10: case 42: case 89: 543 case 10: case 42: case 89:
515 (void) strcat (names->symbols, "+es"); break; 544 (void) strcat (names->symbols, "+es"); break;
516 /* case 11: case 43: */ /* handled earlier */ 545 /* case 11: case 43: */ /* handled earlier */
517 case 90: 546 case 90:
518 (void) strcat (names->symbols, "+se"); break; 547 (void) strcat (names->symbols, "+se"); break;
519 case 12: case 44: case 91: 548 case 12: case 44: case 91:
520 (void) strcat (names->symbols, "+fr_CH"); break; 549 (void) strcat (names->symbols, "+fr_CH"); break;
521 case 13: case 45: case 92: 550 case 13: case 45: case 92:
522 (void) strcat (names->symbols, "+de_CH"); break; 551 (void) strcat (names->symbols, "+de_CH"); break;
523 case 14: case 46: case 93: 552 case 14: case 46: case 93:
524 (void) strcat (names->symbols, "+gb"); break; /* s/b en_UK */ 553 (void) strcat (names->symbols, "+gb"); break; /* s/b en_UK */
525 case 52: 554 case 52:
526 (void) strcat (names->symbols, "+pl"); break; 555 (void) strcat (names->symbols, "+pl"); break;
527 case 53: 556 case 53:
528 (void) strcat (names->symbols, "+cs"); break; 557 (void) strcat (names->symbols, "+cs"); break;
529 case 54: 558 case 54:
530 (void) strcat (names->symbols, "+ru"); break; 559 (void) strcat (names->symbols, "+ru"); break;
531#if 0 560#if 0
532 /* don't have symbols defined for these yet, let them default */ 561 /* don't have symbols defined for these yet, let them default */
533 case 2: 562 case 2:
534 (void) strcat (names->symbols, "+fr_BE"); break; 563 (void) strcat (names->symbols, "+fr_BE"); break;
535 case 7: case 39: case 86: 564 case 7: case 39: case 86:
536 (void) strcat (names->symbols, "+nl"); break; 565 (void) strcat (names->symbols, "+nl"); break;
537 case 50: case 97: 566 case 50: case 97:
538 (void) strcat (names->symbols, "+fr_CA"); break; 567 (void) strcat (names->symbols, "+fr_CA"); break;
539 case 16: case 47: case 94: 568 case 16: case 47: case 94:
540 (void) strcat (names->symbols, "+ko"); break; 569 (void) strcat (names->symbols, "+ko"); break;
541 case 17: case 48: case 95: 570 case 17: case 48: case 95:
542 (void) strcat (names->symbols, "+tw"); break; 571 (void) strcat (names->symbols, "+tw"); break;
543 case 32: case 49: case 96: 572 case 32: case 49: case 96:
544 (void) strcat (names->symbols, "+jp"); break; 573 (void) strcat (names->symbols, "+jp"); break;
545 case 51: 574 case 51:
546 (void) strcat (names->symbols, "+hu"); break; 575 (void) strcat (names->symbols, "+hu"); break;
547#endif 576#endif
548 /* 577 /*
549 * by setting the symbols to NULL XKB will use the symbols in 578 * by setting the symbols to NULL XKB will use the symbols in
550 * the "default" keymap. 579 * the "default" keymap.
551 */ 580 */
552 default: 581 default:
553 names->symbols = NULL; return; break; 582 names->symbols = NULL; return; break;
554 } 583 }
555 } 584 }
556#else 585#else
557 rmlvo->rules = "base"; 586 rmlvo->rules = "base";
558 rmlvo->model = NULL; 587 rmlvo->model = NULL;
559 rmlvo->layout = NULL; 588 rmlvo->layout = NULL;
560 rmlvo->variant = NULL; 589 rmlvo->variant = NULL;
561 rmlvo->options = NULL; 590 rmlvo->options = NULL;
562#endif 591#endif
563} 592}
564 593
565/*- 594/*-
566 *----------------------------------------------------------------------- 595 *-----------------------------------------------------------------------
567 * sunKbdProc -- 596 * sunKbdProc --
568 * Handle the initialization, etc. of a keyboard. 597 * Handle the initialization, etc. of a keyboard.
569 * 598 *
570 * Results: 599 * Results:
571 * None. 600 * None.
572 * 601 *
573 *----------------------------------------------------------------------- 602 *-----------------------------------------------------------------------
574 */ 603 */
575 604
576int 605int
577sunKbdProc(DeviceIntPtr device, int what) 606sunKbdProc(DeviceIntPtr device, int what)
578{ 607{
579 int i; 608 int i;
580 DevicePtr pKeyboard = (DevicePtr) device; 609 DevicePtr pKeyboard = (DevicePtr) device;
581 sunKbdPrivPtr pPriv; 610 sunKbdPrivPtr pPriv;
582 KeybdCtrl* ctrl = &device->kbdfeed->ctrl; 611 KeybdCtrl* ctrl = &device->kbdfeed->ctrl;
583 XkbRMLVOSet rmlvo; 612 XkbRMLVOSet rmlvo;
584 613
585 static CARD8 *workingModMap = NULL; 614 static CARD8 *workingModMap = NULL;
586 static KeySymsRec *workingKeySyms; 615 static KeySymsRec *workingKeySyms;
587 616
588 switch (what) { 617 switch (what) {
589 case DEVICE_INIT: 618 case DEVICE_INIT:
590 if (pKeyboard != (DevicePtr)sunKeyboardDevice) { 619 if (pKeyboard != (DevicePtr)sunKeyboardDevice) {
591 ErrorF ("Cannot open non-system keyboard\n"); 620 ErrorF ("Cannot open non-system keyboard\n");
592 return (!Success); 621 return (!Success);
593 } 622 }
594 623
595 if (!workingKeySyms) { 624 if (!workingKeySyms) {
596 workingKeySyms = &sunKeySyms[sunKbdPriv.type]; 625 workingKeySyms = &sunKeySyms[sunKbdPriv.type];
597 626
598 if (sunKbdPriv.type == KB_SUN4 && sunSwapLkeys) 627 if (sunKbdPriv.type == KB_SUN4 && sunSwapLkeys)
599 SwapLKeys(workingKeySyms); 628 SwapLKeys(workingKeySyms);
600 629
601 if (workingKeySyms->minKeyCode < MIN_KEYCODE) { 630 if (workingKeySyms->minKeyCode < MIN_KEYCODE) {
602 workingKeySyms->minKeyCode += MIN_KEYCODE; 631 workingKeySyms->minKeyCode += MIN_KEYCODE;
603 workingKeySyms->maxKeyCode += MIN_KEYCODE; 632 workingKeySyms->maxKeyCode += MIN_KEYCODE;
604 } 633 }
605 if (workingKeySyms->maxKeyCode > MAX_KEYCODE) 634 if (workingKeySyms->maxKeyCode > MAX_KEYCODE)
606 workingKeySyms->maxKeyCode = MAX_KEYCODE; 635 workingKeySyms->maxKeyCode = MAX_KEYCODE;
607 } 636 }
608 637
609 if (!workingModMap) { 638 if (!workingModMap) {
610 workingModMap = malloc(MAP_LENGTH); 639 workingModMap = malloc(MAP_LENGTH);
611 (void) memset(workingModMap, 0, MAP_LENGTH); 640 (void) memset(workingModMap, 0, MAP_LENGTH);
612 for(i=0; sunModMaps[sunKbdPriv.type][i].key != 0; i++) 641 for(i=0; sunModMaps[sunKbdPriv.type][i].key != 0; i++)
613 workingModMap[sunModMaps[sunKbdPriv.type][i].key + MIN_KEYCODE] = 642 workingModMap[sunModMaps[sunKbdPriv.type][i].key + MIN_KEYCODE] =
614 sunModMaps[sunKbdPriv.type][i].modifiers; 643 sunModMaps[sunKbdPriv.type][i].modifiers;
615 } 644 }
616 645
617 pKeyboard->devicePrivate = (void *)&sunKbdPriv; 646 pKeyboard->devicePrivate = (void *)&sunKbdPriv;
618 pKeyboard->on = FALSE; 647 pKeyboard->on = FALSE;
619 648
620 sunInitKbdNames(&rmlvo, pKeyboard->devicePrivate); 649 sunInitKbdNames(&rmlvo, pKeyboard->devicePrivate);
621#if 0 /* XXX needs more work for Xorg xkb */ 650#if 0 /* XXX needs more work for Xorg xkb */
622 InitKeyboardDeviceStruct(device, rmlvo, 651 InitKeyboardDeviceStruct(device, rmlvo,
623 sunBell, sunKbdCtrl); 652 sunBell, sunKbdCtrl);
624#else 653#else
625 InitKeyboardDeviceStruct(device, NULL, 654 InitKeyboardDeviceStruct(device, NULL,
626 sunBell, sunKbdCtrl); 655 sunBell, sunKbdCtrl);
627 XkbApplyMappingChange(device, workingKeySyms, 656 XkbApplyMappingChange(device, workingKeySyms,
628 workingKeySyms->minKeyCode, 657 workingKeySyms->minKeyCode,
629 workingKeySyms->maxKeyCode - 658 workingKeySyms->maxKeyCode -
630 workingKeySyms->minKeyCode + 1, 659 workingKeySyms->minKeyCode + 1,
631 workingModMap, serverClient); 660 workingModMap, serverClient);
632#endif 661#endif
633 break; 662 break;
634 663
635 case DEVICE_ON: 664 case DEVICE_ON:
636 pPriv = (sunKbdPrivPtr)pKeyboard->devicePrivate; 665 pPriv = (sunKbdPrivPtr)pKeyboard->devicePrivate;
637 /* 666 /*
638 * Set the keyboard into "direct" mode and turn on 667 * Set the keyboard into "direct" mode and turn on
639 * event translation. 668 * event translation.
640 */ 669 */
641 if (sunChangeKbdTranslation(pPriv->fd,TRUE) == -1) 670 if (sunChangeKbdTranslation(pPriv->fd,TRUE) == -1)
642 FatalError("Can't set keyboard translation\n"); 671 FatalError("Can't set keyboard translation\n");
643 SetNotifyFd(pPriv->fd, sunKbdHandlerNotify, X_NOTIFY_READ, NULL); 672 SetNotifyFd(pPriv->fd, sunKbdHandlerNotify, X_NOTIFY_READ, NULL);
644 pKeyboard->on = TRUE; 673 pKeyboard->on = TRUE;
645 break; 674 break;
646 675
647 case DEVICE_CLOSE: 676 case DEVICE_CLOSE:
648 case DEVICE_OFF: 677 case DEVICE_OFF:
649 pPriv = (sunKbdPrivPtr)pKeyboard->devicePrivate; 678 pPriv = (sunKbdPrivPtr)pKeyboard->devicePrivate;
650 if (pPriv->type == KB_SUN4) { 679 if (pPriv->type == KB_SUN4) {
651 /* dumb bug in Sun's keyboard! Turn off LEDS before resetting */ 680 /* dumb bug in Sun's keyboard! Turn off LEDS before resetting */
652 pPriv->leds = 0; 681 pPriv->leds = 0;
653 ctrl->leds = 0; 682 ctrl->leds = 0;
654 SetLights(ctrl, pPriv->fd); 683 SetLights(ctrl, pPriv->fd);
655 } 684 }
656 /* 685 /*
657 * Restore original keyboard directness and translation. 686 * Restore original keyboard directness and translation.
658 */ 687 */
659 if (sunChangeKbdTranslation(pPriv->fd,FALSE) == -1) 688 if (sunChangeKbdTranslation(pPriv->fd,FALSE) == -1)
660 FatalError("Can't reset keyboard translation\n"); 689 FatalError("Can't reset keyboard translation\n");
661 RemoveNotifyFd(pPriv->fd); 690 RemoveNotifyFd(pPriv->fd);
662 pKeyboard->on = FALSE; 691 pKeyboard->on = FALSE;
663 break; 692 break;
664 default: 693 default:
665 FatalError("Unknown keyboard operation\n"); 694 FatalError("Unknown keyboard operation\n");
666 } 695 }
667 return Success; 696 return Success;
668} 697}
669 698
670/*- 699/*-
671 *----------------------------------------------------------------------- 700 *-----------------------------------------------------------------------
672 * sunKbdGetEvents -- 701 * sunKbdGetEvents --
673 * Return the events waiting in the wings for the given keyboard. 702 * Return the events waiting in the wings for the given keyboard.
674 * 703 *
675 * Results: 704 * Results:
676 * A pointer to an array of Firm_events or (Firm_event *)0 if no events 705 * A pointer to an array of Firm_events or (Firm_event *)0 if no events
677 * The number of events contained in the array. 706 * The number of events contained in the array.
678 * A boolean as to whether more events might be available. 707 * A boolean as to whether more events might be available.
679 * 708 *
680 * Side Effects: 709 * Side Effects:
681 * None. 710 * None.
682 *----------------------------------------------------------------------- 711 *-----------------------------------------------------------------------
683 */ 712 */
684 713
685Firm_event * 714Firm_event *
686sunKbdGetEvents(int fd, Bool on, int *pNumEvents, Bool *pAgain) 715sunKbdGetEvents(int fd, Bool on, int *pNumEvents, Bool *pAgain)
687{ 716{
688 int nBytes; /* number of bytes of events available. */ 717 int nBytes; /* number of bytes of events available. */
689 static Firm_event evBuf[SUN_MAXEVENTS]; /* Buffer for Firm_events */ 718 static Firm_event evBuf[SUN_MAXEVENTS]; /* Buffer for Firm_events */
690 719
691 if ((nBytes = read (fd, evBuf, sizeof(evBuf))) == -1) { 720 if ((nBytes = read (fd, evBuf, sizeof(evBuf))) == -1) {
692 if (errno == EWOULDBLOCK) { 721 if (errno == EWOULDBLOCK) {
693 *pNumEvents = 0; 722 *pNumEvents = 0;
694 *pAgain = FALSE; 723 *pAgain = FALSE;
695 } else { 724 } else {
696 ErrorF("Reading keyboard"); 725 ErrorF("Reading keyboard");
697 FatalError ("Could not read the keyboard"); 726 FatalError ("Could not read the keyboard");
698 } 727 }
699 } else { 728 } else {
700 if (on) { 729 if (on) {
701 *pNumEvents = nBytes / sizeof (Firm_event); 730 *pNumEvents = nBytes / sizeof (Firm_event);
702 *pAgain = (nBytes == sizeof (evBuf)); 731 *pAgain = (nBytes == sizeof (evBuf));
703 } else { 732 } else {
704 *pNumEvents = 0; 733 *pNumEvents = 0;
705 *pAgain = FALSE; 734 *pAgain = FALSE;
706 } 735 }
707 } 736 }
708 return evBuf; 737 return evBuf;
709} 738}
710 739
711/*- 740/*-
712 *----------------------------------------------------------------------- 741 *-----------------------------------------------------------------------
713 * sunKbdEnqueueEvent -- 742 * sunKbdEnqueueEvent --
714 * 743 *
715 *----------------------------------------------------------------------- 744 *-----------------------------------------------------------------------
716 */ 745 */
717 746
718void 747void
719sunKbdEnqueueEvent(DeviceIntPtr device, Firm_event *fe) 748sunKbdEnqueueEvent(DeviceIntPtr device, Firm_event *fe)
720{ 749{
721 BYTE keycode; 750 BYTE keycode;
722 int type; 751 int type;
723 752
724 keycode = (fe->id & 0x7f) + MIN_KEYCODE; 753 keycode = (fe->id & 0x7f) + MIN_KEYCODE;
725 type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress); 754 type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress);
726 QueueKeyboardEvents(device, type, keycode); 755 QueueKeyboardEvents(device, type, keycode);
727} 756}
728 757
729 758
730/*- 759/*-
731 *----------------------------------------------------------------------- 760 *-----------------------------------------------------------------------
732 * sunChangeKbdTranslation 761 * sunChangeKbdTranslation
733 * Makes operating system calls to set keyboard translation 762 * Makes operating system calls to set keyboard translation
734 * and direction on or off. 763 * and direction on or off.
735 * 764 *
736 * Results: 765 * Results:
737 * -1 if failure, else 0. 766 * -1 if failure, else 0.
738 * 767 *
739 * Side Effects: 768 * Side Effects:
740 * Changes kernel management of keyboard. 769 * Changes kernel management of keyboard.
741 * 770 *
742 *----------------------------------------------------------------------- 771 *-----------------------------------------------------------------------
743 */ 772 */
744int 773int
745sunChangeKbdTranslation(int fd, Bool makeTranslated) 774sunChangeKbdTranslation(int fd, Bool makeTranslated)
746{ 775{
747 int tmp; 776 int tmp;
748#ifndef i386 /* { */ 777#ifndef i386 /* { */
749 sigset_t hold_mask, old_mask; 778 sigset_t hold_mask, old_mask;
750#else /* }{ */ 779#else /* }{ */
751 int old_mask; 780 int old_mask;
752#endif /* } */ 781#endif /* } */
753 int toread; 782 int toread;
754 char junk[8192]; 783 char junk[8192];
755 784
756#ifndef i386 /* { */ 785#ifndef i386 /* { */
757 (void) sigfillset(&hold_mask); 786 (void) sigfillset(&hold_mask);
758 (void) sigprocmask(SIG_BLOCK, &hold_mask, &old_mask); 787 (void) sigprocmask(SIG_BLOCK, &hold_mask, &old_mask);
759#else /* }{ */ 788#else /* }{ */
760 old_mask = sigblock (~0); 789 old_mask = sigblock (~0);
761#endif /* } */ 790#endif /* } */
762 sunKbdWait(); 791 sunKbdWait();
763 if (makeTranslated) { 792 if (makeTranslated) {
764 /* 793 /*
765 * Next set the keyboard into "direct" mode and turn on 794 * Next set the keyboard into "direct" mode and turn on
766 * event translation. If either of these fails, we can't go 795 * event translation. If either of these fails, we can't go
767 * on. 796 * on.
768 */ 797 */
769 tmp = 1; 798 tmp = 1;
770 if (ioctl (fd, KIOCSDIRECT, &tmp) == -1) { 799 if (ioctl (fd, KIOCSDIRECT, &tmp) == -1) {
771 ErrorF("Setting keyboard direct mode"); 800 ErrorF("Setting keyboard direct mode");
772 return -1; 801 return -1;
773 } 802 }
774 tmp = TR_UNTRANS_EVENT; 803 tmp = TR_UNTRANS_EVENT;
775 if (ioctl (fd, KIOCTRANS, &tmp) == -1) { 804 if (ioctl (fd, KIOCTRANS, &tmp) == -1) {
776 ErrorF("Setting keyboard translation"); 805 ErrorF("Setting keyboard translation");
777 ErrorF ("sunChangeKbdTranslation: kbdFd=%d\n", fd); 806 ErrorF ("sunChangeKbdTranslation: kbdFd=%d\n", fd);
778 return -1; 807 return -1;
779 } 808 }
780 } else { 809 } else {
781 /* 810 /*
782 * Next set the keyboard into "indirect" mode and turn off 811 * Next set the keyboard into "indirect" mode and turn off
783 * event translation. 812 * event translation.
784 */ 813 */
785 tmp = 0; 814 tmp = 0;
786 (void)ioctl (fd, KIOCSDIRECT, &tmp); 815 (void)ioctl (fd, KIOCSDIRECT, &tmp);
787 tmp = TR_ASCII; 816 tmp = TR_ASCII;
788 (void)ioctl (fd, KIOCTRANS, &tmp); 817 (void)ioctl (fd, KIOCTRANS, &tmp);
789 } 818 }
790 if (ioctl (fd, FIONREAD, &toread) != -1 && toread > 0) { 819 if (ioctl (fd, FIONREAD, &toread) != -1 && toread > 0) {
791 while (toread) { 820 while (toread) {
792 tmp = toread; 821 tmp = toread;
793 if (toread > sizeof (junk)) 822 if (toread > sizeof (junk))
794 tmp = sizeof (junk); 823 tmp = sizeof (junk);
795 (void) read (fd, junk, tmp); 824 (void) read (fd, junk, tmp);
796 toread -= tmp; 825 toread -= tmp;
797 } 826 }
798 } 827 }
799#ifndef i386 /* { */ 828#ifndef i386 /* { */
800 (void) sigprocmask(SIG_SETMASK, &old_mask, NULL); 829 (void) sigprocmask(SIG_SETMASK, &old_mask, NULL);
801#else /* }{ */ 830#else /* }{ */
802 sigsetmask (old_mask); 831 sigsetmask (old_mask);
803#endif /* } */ 832#endif /* } */
804 return 0; 833 return 0;
805} 834}
806 835
807/*ARGSUSED*/ 836/*ARGSUSED*/
808Bool 837Bool
809LegalModifier(unsigned int key, DeviceIntPtr pDev) 838LegalModifier(unsigned int key, DeviceIntPtr pDev)
810{ 839{
811 return TRUE; 840 return TRUE;
812} 841}
813 842
814/*ARGSUSED*/ 843/*ARGSUSED*/
815void 844void
816sunBlockHandler(int nscreen, void *pbdata, void *pTimeout, void *pReadmask) 845sunBlockHandler(int nscreen, void *pbdata, void *pTimeout, void *pReadmask)
817{ 846{
818} 847}
819 848
820/*ARGSUSED*/ 849/*ARGSUSED*/
821void 850void
822sunWakeupHandler(int nscreen, void *pbdata, unsigned long err, void *pReadmask) 851sunWakeupHandler(int nscreen, void *pbdata, unsigned long err, void *pReadmask)
823{ 852{
824} 853}