| @@ -1,413 +1,411 @@ | | | @@ -1,413 +1,411 @@ |
1 | /* $NetBSD: x68kKbd.c,v 1.8 2020/08/01 20:21:00 tsutsui Exp $ */ | | 1 | /* $NetBSD: x68kKbd.c,v 1.9 2020/11/01 11:44:55 tsutsui Exp $ */ |
2 | /*------------------------------------------------------------------------- | | 2 | /*------------------------------------------------------------------------- |
3 | * Copyright (c) 1996 Yasushi Yamasaki | | 3 | * Copyright (c) 1996 Yasushi Yamasaki |
4 | * All rights reserved. | | 4 | * All rights reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | *-----------------------------------------------------------------------*/ | | 25 | *-----------------------------------------------------------------------*/ |
26 | | | 26 | |
27 | /*- | | 27 | /*- |
28 | * Copyright (c) 1987 by the Regents of the University of California | | 28 | * Copyright (c) 1987 by the Regents of the University of California |
29 | * | | 29 | * |
30 | * Permission to use, copy, modify, and distribute this | | 30 | * Permission to use, copy, modify, and distribute this |
31 | * software and its documentation for any purpose and without | | 31 | * software and its documentation for any purpose and without |
32 | * fee is hereby granted, provided that the above copyright | | 32 | * fee is hereby granted, provided that the above copyright |
33 | * notice appear in all copies. The University of California | | 33 | * notice appear in all copies. The University of California |
34 | * makes no representations about the suitability of this | | 34 | * makes no representations about the suitability of this |
35 | * software for any purpose. It is provided "as is" without | | 35 | * software for any purpose. It is provided "as is" without |
36 | * express or implied warranty. | | 36 | * express or implied warranty. |
37 | */ | | 37 | */ |
38 | | | 38 | |
39 | /************************************************************ | | 39 | /************************************************************ |
40 | Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. | | 40 | Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. |
41 | | | 41 | |
42 | All Rights Reserved | | 42 | All Rights Reserved |
43 | | | 43 | |
44 | Permission to use, copy, modify, and distribute this | | 44 | Permission to use, copy, modify, and distribute this |
45 | software and its documentation for any purpose and without | | 45 | software and its documentation for any purpose and without |
46 | fee is hereby granted, provided that the above copyright no- | | 46 | fee is hereby granted, provided that the above copyright no- |
47 | tice appear in all copies and that both that copyright no- | | 47 | tice appear in all copies and that both that copyright no- |
48 | tice and this permission notice appear in supporting docu- | | 48 | tice and this permission notice appear in supporting docu- |
49 | mentation, and that the names of Sun or X Consortium | | 49 | mentation, and that the names of Sun or X Consortium |
50 | not be used in advertising or publicity pertaining to | | 50 | not be used in advertising or publicity pertaining to |
51 | distribution of the software without specific prior | | 51 | distribution of the software without specific prior |
52 | written permission. Sun and X Consortium make no | | 52 | written permission. Sun and X Consortium make no |
53 | representations about the suitability of this software for | | 53 | representations about the suitability of this software for |
54 | any purpose. It is provided "as is" without any express or | | 54 | any purpose. It is provided "as is" without any express or |
55 | implied warranty. | | 55 | implied warranty. |
56 | | | 56 | |
57 | SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | | 57 | SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
58 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- | | 58 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- |
59 | NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- | | 59 | NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- |
60 | ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | | 60 | ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
61 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | | 61 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
62 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | | 62 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
63 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH | | 63 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH |
64 | THE USE OR PERFORMANCE OF THIS SOFTWARE. | | 64 | THE USE OR PERFORMANCE OF THIS SOFTWARE. |
65 | | | 65 | |
66 | ********************************************************/ | | 66 | ********************************************************/ |
67 | | | 67 | |
68 | #include "x68k.h" | | 68 | #include "x68k.h" |
69 | #include "mi.h" | | 69 | #include "mi.h" |
70 | | | 70 | |
71 | #include <X11/X.h> | | 71 | #include <X11/X.h> |
72 | #include <X11/Xproto.h> | | 72 | #include <X11/Xproto.h> |
73 | #include <X11/keysym.h> | | 73 | #include <X11/keysym.h> |
74 | #include "screenint.h" | | 74 | #include "screenint.h" |
75 | #include "inputstr.h" | | 75 | #include "inputstr.h" |
76 | #include "eventstr.h" | | 76 | #include "eventstr.h" |
77 | #include "misc.h" | | 77 | #include "misc.h" |
78 | #include "scrnintstr.h" | | 78 | #include "scrnintstr.h" |
79 | #include "servermd.h" | | 79 | #include "servermd.h" |
80 | | | 80 | |
81 | #include <X11/extensions/XKB.h> | | 81 | #include <X11/extensions/XKB.h> |
82 | #include "xkbsrv.h" | | 82 | #include "xkbsrv.h" |
83 | | | 83 | |
84 | #define MIN_KEYCODE 7 /* necessary to avoid the mouse buttons */ | | 84 | #define MIN_KEYCODE 7 /* necessary to avoid the mouse buttons */ |
85 | #define MAX_KEYCODE 255 /* limited by the protocol */ | | 85 | #define MAX_KEYCODE 255 /* limited by the protocol */ |
86 | | | 86 | |
87 | X68kKbdPriv x68kKbdPriv; | | 87 | X68kKbdPriv x68kKbdPriv; |
88 | DeviceIntPtr x68kKeyboardDevice = NULL; | | 88 | DeviceIntPtr x68kKeyboardDevice = NULL; |
89 | | | 89 | |
90 | static void x68kKbdHandlerNotify(int, int, void *); | | 90 | static void x68kKbdHandlerNotify(int, int, void *); |
91 | static void x68kInitModMap(KeySymsRec *, CARD8 *); | | 91 | static void x68kInitModMap(KeySymsRec *, CARD8 *); |
92 | static void x68kInitKbdNames(XkbRMLVOSet *, X68kKbdPrivPtr); | | 92 | static void x68kInitKbdNames(XkbRMLVOSet *, X68kKbdPrivPtr); |
93 | static void x68kKbdRingBell(DeviceIntPtr, int, int); | | 93 | static void x68kKbdRingBell(DeviceIntPtr, int, int); |
94 | static void x68kKbdBell(int, DeviceIntPtr, void *, int); | | 94 | static void x68kKbdBell(int, DeviceIntPtr, void *, int); |
95 | static void x68kKbdCtrl(DeviceIntPtr, KeybdCtrl *); | | 95 | static void x68kKbdCtrl(DeviceIntPtr, KeybdCtrl *); |
96 | static void x68kSetLeds(X68kKbdPrivPtr, u_char); | | 96 | static void x68kSetLeds(X68kKbdPrivPtr, u_char); |
97 | | | 97 | |
98 | static void | | 98 | static void |
99 | x68kKbdHandlerNotify(int fd __unused, int ready __unused, void *data __unused) | | 99 | x68kKbdHandlerNotify(int fd __unused, int ready __unused, void *data __unused) |
100 | { | | 100 | { |
101 | } | | 101 | } |
102 | | | 102 | |
103 | /*------------------------------------------------------------------------ | | 103 | /*------------------------------------------------------------------------ |
104 | * x68kKbdProc -- | | 104 | * x68kKbdProc -- |
105 | * Handle the initialization, etc. of a keyboard. | | 105 | * Handle the initialization, etc. of a keyboard. |
106 | * | | 106 | * |
107 | * Results: | | 107 | * Results: |
108 | * None. | | 108 | * None. |
109 | * | | 109 | * |
110 | *----------------------------------------------------------------------*/ | | 110 | *----------------------------------------------------------------------*/ |
111 | int | | 111 | int |
112 | x68kKbdProc(DeviceIntPtr pDev, /* Keyboard to manipulate */ | | 112 | x68kKbdProc(DeviceIntPtr pDev, /* Keyboard to manipulate */ |
113 | int what) /* What to do to it */ | | 113 | int what) /* What to do to it */ |
114 | { | | 114 | { |
115 | DevicePtr pKeyboard = &pDev->public; | | 115 | DevicePtr pKeyboard = &pDev->public; |
116 | CARD8 x68kModMap[MAP_LENGTH]; | | 116 | CARD8 x68kModMap[MAP_LENGTH]; |
117 | int mode; | | 117 | int mode; |
118 | XkbRMLVOSet rmlvo; | | 118 | XkbRMLVOSet rmlvo; |
119 | | | 119 | |
120 | switch (what) { | | 120 | switch (what) { |
121 | case DEVICE_INIT: | | 121 | case DEVICE_INIT: |
122 | pKeyboard->devicePrivate = (void *)&x68kKbdPriv; | | 122 | pKeyboard->devicePrivate = (void *)&x68kKbdPriv; |
123 | if( (x68kKbdPriv.fd = open("/dev/kbd", O_RDONLY)) == -1 ) { | | 123 | if( (x68kKbdPriv.fd = open("/dev/kbd", O_RDONLY)) == -1 ) { |
124 | ErrorF("Can't open keyboard device"); | | 124 | ErrorF("Can't open keyboard device"); |
125 | return !Success; | | 125 | return !Success; |
126 | } | | 126 | } |
127 | pKeyboard->on = FALSE; | | 127 | pKeyboard->on = FALSE; |
128 | x68kInitModMap(x68kKeySyms, x68kModMap); | | 128 | x68kInitModMap(x68kKeySyms, x68kModMap); |
129 | | | 129 | |
130 | x68kInitKbdNames(&rmlvo, pKeyboard->devicePrivate); | | 130 | x68kInitKbdNames(&rmlvo, pKeyboard->devicePrivate); |
131 | #if 0 /* XXX How should we setup XKB maps for non PS/2 keyboard!? */ | | 131 | #if 0 /* XXX How should we setup XKB maps for non PS/2 keyboard!? */ |
132 | InitKeyboardDeviceStruct(pDev, &rmlvo, | | 132 | InitKeyboardDeviceStruct(pDev, &rmlvo, |
133 | x68kKbdBell, x68kKbdCtrl); | | 133 | x68kKbdBell, x68kKbdCtrl); |
134 | #else | | 134 | #else |
135 | InitKeyboardDeviceStruct(pDev, NULL, | | 135 | InitKeyboardDeviceStruct(pDev, NULL, |
136 | x68kKbdBell, x68kKbdCtrl); | | 136 | x68kKbdBell, x68kKbdCtrl); |
137 | XkbApplyMappingChange(pDev, x68kKeySyms, | | 137 | XkbApplyMappingChange(pDev, x68kKeySyms, |
138 | x68kKeySyms->minKeyCode, | | 138 | x68kKeySyms->minKeyCode, |
139 | x68kKeySyms->maxKeyCode - x68kKeySyms->minKeyCode + 1, | | 139 | x68kKeySyms->maxKeyCode - x68kKeySyms->minKeyCode + 1, |
140 | x68kModMap, serverClient); | | 140 | x68kModMap, serverClient); |
141 | #endif | | 141 | #endif |
142 | break; | | 142 | break; |
143 | | | 143 | |
144 | case DEVICE_ON: | | 144 | case DEVICE_ON: |
145 | mode = 1; | | 145 | mode = 1; |
146 | if ( fcntl(x68kKbdPriv.fd, F_SETOWN, getpid()) == -1 || | | 146 | if ( fcntl(x68kKbdPriv.fd, F_SETOWN, getpid()) == -1 || |
147 | fcntl(x68kKbdPriv.fd, F_SETFL, O_NONBLOCK|O_ASYNC) == -1 || | | 147 | fcntl(x68kKbdPriv.fd, F_SETFL, O_NONBLOCK|O_ASYNC) == -1 || |
148 | ioctl(x68kKbdPriv.fd, KIOCSDIRECT, &mode) == -1 ) { | | 148 | ioctl(x68kKbdPriv.fd, KIOCSDIRECT, &mode) == -1 ) { |
149 | ErrorF("Async keyboard I/O failed"); | | 149 | ErrorF("Async keyboard I/O failed"); |
150 | return !Success; | | 150 | return !Success; |
151 | } | | 151 | } |
152 | x68kSetLeds(&x68kKbdPriv, (u_char)x68kKbdPriv.leds); | | 152 | x68kSetLeds(&x68kKbdPriv, (u_char)x68kKbdPriv.leds); |
153 | SetNotifyFd(x68kKbdPriv.fd, x68kKbdHandlerNotify, | | 153 | SetNotifyFd(x68kKbdPriv.fd, x68kKbdHandlerNotify, |
154 | X_NOTIFY_READ, NULL); | | 154 | X_NOTIFY_READ, NULL); |
155 | pKeyboard->on = TRUE; | | 155 | pKeyboard->on = TRUE; |
156 | break; | | 156 | break; |
157 | | | 157 | |
158 | case DEVICE_CLOSE: | | 158 | case DEVICE_CLOSE: |
159 | case DEVICE_OFF: | | 159 | case DEVICE_OFF: |
160 | RemoveNotifyFd(x68kKbdPriv.fd); | | 160 | RemoveNotifyFd(x68kKbdPriv.fd); |
161 | pKeyboard->on = FALSE; | | 161 | pKeyboard->on = FALSE; |
162 | break; | | 162 | break; |
163 | default: | | 163 | default: |
164 | FatalError("Unknown keyboard operation\n"); | | 164 | FatalError("Unknown keyboard operation\n"); |
165 | } | | 165 | } |
166 | return Success; | | 166 | return Success; |
167 | } | | 167 | } |
168 | | | 168 | |
169 | /*------------------------------------------------------------------------- | | 169 | /*------------------------------------------------------------------------- |
170 | * function "x68kInitModMap" | | 170 | * function "x68kInitModMap" |
171 | * | | 171 | * |
172 | * purpose: initialize modmap with keysym table | | 172 | * purpose: initialize modmap with keysym table |
173 | * argument: (KeySymsRec *)x68kKeySyms : keysym table | | 173 | * argument: (KeySymsRec *)x68kKeySyms : keysym table |
174 | * (CARD8 *)x68kModMap : result | | 174 | * (CARD8 *)x68kModMap : result |
175 | * returns: nothing | | 175 | * returns: nothing |
176 | *-----------------------------------------------------------------------*/ | | 176 | *-----------------------------------------------------------------------*/ |
177 | static void | | 177 | static void |
178 | x68kInitModMap(KeySymsRec *KeySyms, CARD8 *x68kModMap) | | 178 | x68kInitModMap(KeySymsRec *KeySyms, CARD8 *x68kModMap) |
179 | { | | 179 | { |
180 | int i; | | 180 | int i; |
181 | | | 181 | |
182 | for (i = 0; i < MAP_LENGTH; i++) | | 182 | for (i = 0; i < MAP_LENGTH; i++) |
183 | x68kModMap[i] = NoSymbol; | | 183 | x68kModMap[i] = NoSymbol; |
184 | if (KeySyms->minKeyCode < MIN_KEYCODE) { | | 184 | if (KeySyms->minKeyCode < MIN_KEYCODE) { |
185 | KeySyms->minKeyCode += MIN_KEYCODE; | | 185 | KeySyms->minKeyCode += MIN_KEYCODE; |
186 | KeySyms->maxKeyCode += MIN_KEYCODE; | | 186 | KeySyms->maxKeyCode += MIN_KEYCODE; |
187 | } | | 187 | } |
188 | #if 0 | | | |
189 | if (KeySyms->maxKeyCode > MAX_KEYCODE) | | 188 | if (KeySyms->maxKeyCode > MAX_KEYCODE) |
190 | KeySyms->maxKeyCode += MAX_KEYCODE; | | 189 | KeySyms->maxKeyCode = MAX_KEYCODE; |
191 | #endif | | | |
192 | for (i = KeySyms->minKeyCode; | | 190 | for (i = KeySyms->minKeyCode; |
193 | i < KeySyms->maxKeyCode; i++) { | | 191 | i < KeySyms->maxKeyCode; i++) { |
194 | switch (KeySyms->map[(i-KeySyms->minKeyCode)*4]) { | | 192 | switch (KeySyms->map[(i-KeySyms->minKeyCode)*4]) { |
195 | case XK_Shift_L: | | 193 | case XK_Shift_L: |
196 | case XK_Shift_R: | | 194 | case XK_Shift_R: |
197 | x68kModMap[i] = ShiftMask; | | 195 | x68kModMap[i] = ShiftMask; |
198 | break; | | 196 | break; |
199 | case XK_Control_L: | | 197 | case XK_Control_L: |
200 | case XK_Control_R: | | 198 | case XK_Control_R: |
201 | x68kModMap[i] = ControlMask; | | 199 | x68kModMap[i] = ControlMask; |
202 | break; | | 200 | break; |
203 | case XK_Alt_L: | | 201 | case XK_Alt_L: |
204 | case XK_Alt_R: | | 202 | case XK_Alt_R: |
205 | x68kModMap[i] = Mod1Mask; | | 203 | x68kModMap[i] = Mod1Mask; |
206 | break; | | 204 | break; |
207 | case XK_Meta_L: | | 205 | case XK_Meta_L: |
208 | case XK_Meta_R: | | 206 | case XK_Meta_R: |
209 | x68kModMap[i] = Mod2Mask; | | 207 | x68kModMap[i] = Mod2Mask; |
210 | break; | | 208 | break; |
211 | case XK_Caps_Lock: | | 209 | case XK_Caps_Lock: |
212 | x68kModMap[i] = LockMask; | | 210 | x68kModMap[i] = LockMask; |
213 | break; | | 211 | break; |
214 | } | | 212 | } |
215 | } | | 213 | } |
216 | } | | 214 | } |
217 | | | 215 | |
218 | /*------------------------------------------------------------------------- | | 216 | /*------------------------------------------------------------------------- |
219 | * function "x68kInitKbdNames" | | 217 | * function "x68kInitKbdNames" |
220 | * | | 218 | * |
221 | * purpose: store xkb database names | | 219 | * purpose: store xkb database names |
222 | * argument: (XkbRMLVOSet *)rmlvo | | 220 | * argument: (XkbRMLVOSet *)rmlvo |
223 | * (X68kKbdPrivPtr)pKbd | | 221 | * (X68kKbdPrivPtr)pKbd |
224 | * returns: nothing | | 222 | * returns: nothing |
225 | *-----------------------------------------------------------------------*/ | | 223 | *-----------------------------------------------------------------------*/ |
226 | static void | | 224 | static void |
227 | x68kInitKbdNames(XkbRMLVOSet *rmlvo, X68kKbdPrivPtr pKbd) | | 225 | x68kInitKbdNames(XkbRMLVOSet *rmlvo, X68kKbdPrivPtr pKbd) |
228 | { | | 226 | { |
229 | #if 0 /* XXX How should we setup XKB maps for non PS/2 keyboard!? */ | | 227 | #if 0 /* XXX How should we setup XKB maps for non PS/2 keyboard!? */ |
230 | rmlvo->rules = "base"; | | 228 | rmlvo->rules = "base"; |
231 | rmlvo->model = "x68k"; | | 229 | rmlvo->model = "x68k"; |
232 | switch (pKbd->type) { | | 230 | switch (pKbd->type) { |
233 | case X68K_KB_STANDARD: | | 231 | case X68K_KB_STANDARD: |
234 | rmlvo->layout = "jp(standard)"; | | 232 | rmlvo->layout = "jp(standard)"; |
235 | break; | | 233 | break; |
236 | case X68K_KB_ASCII: | | 234 | case X68K_KB_ASCII: |
237 | rmlvo->layout = "jp(ascii)"; | | 235 | rmlvo->layout = "jp(ascii)"; |
238 | break; | | 236 | break; |
239 | } | | 237 | } |
240 | rmlvo->variant = "basic"; | | 238 | rmlvo->variant = "basic"; |
241 | rmlvo->options = ""; | | 239 | rmlvo->options = ""; |
242 | #else | | 240 | #else |
243 | rmlvo->rules = "base"; | | 241 | rmlvo->rules = "base"; |
244 | rmlvo->model = NULL; | | 242 | rmlvo->model = NULL; |
245 | rmlvo->layout = NULL; | | 243 | rmlvo->layout = NULL; |
246 | rmlvo->variant = NULL; | | 244 | rmlvo->variant = NULL; |
247 | rmlvo->options = NULL; | | 245 | rmlvo->options = NULL; |
248 | #endif | | 246 | #endif |
249 | } | | 247 | } |
250 | | | 248 | |
251 | /*- | | 249 | /*- |
252 | *----------------------------------------------------------------------- | | 250 | *----------------------------------------------------------------------- |
253 | * x68kKbdGetEvents -- | | 251 | * x68kKbdGetEvents -- |
254 | * Return the events waiting in the wings for the given keyboard. | | 252 | * Return the events waiting in the wings for the given keyboard. |
255 | * | | 253 | * |
256 | * Results: | | 254 | * Results: |
257 | * A pointer to an array of Firm_events or (Firm_event *)0 if no events | | 255 | * A pointer to an array of Firm_events or (Firm_event *)0 if no events |
258 | * The number of events contained in the array. | | 256 | * The number of events contained in the array. |
259 | * A boolean as to whether more events might be available. | | 257 | * A boolean as to whether more events might be available. |
260 | * | | 258 | * |
261 | * Side Effects: | | 259 | * Side Effects: |
262 | * None. | | 260 | * None. |
263 | *----------------------------------------------------------------------- | | 261 | *----------------------------------------------------------------------- |
264 | */ | | 262 | */ |
265 | Firm_event * | | 263 | Firm_event * |
266 | x68kKbdGetEvents(int fd, int *pNumEvents, Bool *pAgain) | | 264 | x68kKbdGetEvents(int fd, int *pNumEvents, Bool *pAgain) |
267 | { | | 265 | { |
268 | int nBytes; /* number of bytes of events available. */ | | 266 | int nBytes; /* number of bytes of events available. */ |
269 | static Firm_event evBuf[X68K_MAXEVENTS]; /* Buffer for Firm_events */ | | 267 | static Firm_event evBuf[X68K_MAXEVENTS]; /* Buffer for Firm_events */ |
270 | | | 268 | |
271 | if ((nBytes = read (fd, evBuf, sizeof(evBuf))) == -1) { | | 269 | if ((nBytes = read (fd, evBuf, sizeof(evBuf))) == -1) { |
272 | if (errno == EWOULDBLOCK) { | | 270 | if (errno == EWOULDBLOCK) { |
273 | *pNumEvents = 0; | | 271 | *pNumEvents = 0; |
274 | *pAgain = FALSE; | | 272 | *pAgain = FALSE; |
275 | } else { | | 273 | } else { |
276 | ErrorF("Reading keyboard"); | | 274 | ErrorF("Reading keyboard"); |
277 | FatalError ("Could not read the keyboard"); | | 275 | FatalError ("Could not read the keyboard"); |
278 | } | | 276 | } |
279 | } else { | | 277 | } else { |
280 | *pNumEvents = nBytes / sizeof (Firm_event); | | 278 | *pNumEvents = nBytes / sizeof (Firm_event); |
281 | *pAgain = (nBytes == sizeof (evBuf)); | | 279 | *pAgain = (nBytes == sizeof (evBuf)); |
282 | } | | 280 | } |
283 | return evBuf; | | 281 | return evBuf; |
284 | } | | 282 | } |
285 | | | 283 | |
286 | /*- | | 284 | /*- |
287 | *----------------------------------------------------------------------- | | 285 | *----------------------------------------------------------------------- |
288 | * x68kKbdEnqueueEvent -- | | 286 | * x68kKbdEnqueueEvent -- |
289 | * | | 287 | * |
290 | *----------------------------------------------------------------------- | | 288 | *----------------------------------------------------------------------- |
291 | */ | | 289 | */ |
292 | void | | 290 | void |
293 | x68kKbdEnqueueEvent(DeviceIntPtr pDev, Firm_event *fe) | | 291 | x68kKbdEnqueueEvent(DeviceIntPtr pDev, Firm_event *fe) |
294 | { | | 292 | { |
295 | BYTE keycode; | | 293 | BYTE keycode; |
296 | int type; | | 294 | int type; |
297 | | | 295 | |
298 | type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress); | | 296 | type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress); |
299 | keycode = (fe->id & 0x7f) + MIN_KEYCODE; | | 297 | keycode = (fe->id & 0x7f) + MIN_KEYCODE; |
300 | QueueKeyboardEvents(pDev, type, keycode); | | 298 | QueueKeyboardEvents(pDev, type, keycode); |
301 | } | | 299 | } |
302 | | | 300 | |
303 | /*- | | 301 | /*- |
304 | *----------------------------------------------------------------------- | | 302 | *----------------------------------------------------------------------- |
305 | * x68kKbdBell -- | | 303 | * x68kKbdBell -- |
306 | * Ring the terminal/keyboard bell | | 304 | * Ring the terminal/keyboard bell |
307 | * | | 305 | * |
308 | * Results: | | 306 | * Results: |
309 | * Ring the keyboard bell for an amount of time proportional to | | 307 | * Ring the keyboard bell for an amount of time proportional to |
310 | * "loudness." | | 308 | * "loudness." |
311 | * | | 309 | * |
312 | * Side Effects: | | 310 | * Side Effects: |
313 | * None, really... | | 311 | * None, really... |
314 | * | | 312 | * |
315 | *----------------------------------------------------------------------- | | 313 | *----------------------------------------------------------------------- |
316 | */ | | 314 | */ |
317 | | | 315 | |
318 | static void | | 316 | static void |
319 | x68kKbdRingBell(DeviceIntPtr pDev, int volume, int duration) | | 317 | x68kKbdRingBell(DeviceIntPtr pDev, int volume, int duration) |
320 | { | | 318 | { |
321 | int kbdCmd; /* Command to give keyboard */ | | 319 | int kbdCmd; /* Command to give keyboard */ |
322 | X68kKbdPrivPtr pPriv = (X68kKbdPrivPtr)pDev->public.devicePrivate; | | 320 | X68kKbdPrivPtr pPriv = (X68kKbdPrivPtr)pDev->public.devicePrivate; |
323 | | | 321 | |
324 | if (volume == 0) | | 322 | if (volume == 0) |
325 | return; | | 323 | return; |
326 | | | 324 | |
327 | kbdCmd = KBD_CMD_BELL; | | 325 | kbdCmd = KBD_CMD_BELL; |
328 | if (ioctl (pPriv->fd, KIOCCMD, &kbdCmd) == -1) { | | 326 | if (ioctl (pPriv->fd, KIOCCMD, &kbdCmd) == -1) { |
329 | ErrorF("Failed to activate bell"); | | 327 | ErrorF("Failed to activate bell"); |
330 | return; | | 328 | return; |
331 | } | | 329 | } |
332 | usleep (duration * 1000); | | 330 | usleep (duration * 1000); |
333 | kbdCmd = KBD_CMD_NOBELL; | | 331 | kbdCmd = KBD_CMD_NOBELL; |
334 | if (ioctl (pPriv->fd, KIOCCMD, &kbdCmd) == -1) | | 332 | if (ioctl (pPriv->fd, KIOCCMD, &kbdCmd) == -1) |
335 | ErrorF("Failed to deactivate bell"); | | 333 | ErrorF("Failed to deactivate bell"); |
336 | } | | 334 | } |
337 | | | 335 | |
338 | static void | | 336 | static void |
339 | x68kKbdBell(int volume, DeviceIntPtr pDev, void *ctrl, int unused) | | 337 | x68kKbdBell(int volume, DeviceIntPtr pDev, void *ctrl, int unused) |
340 | { | | 338 | { |
341 | KeybdCtrl* kctrl = (KeybdCtrl*) ctrl; | | 339 | KeybdCtrl* kctrl = (KeybdCtrl*) ctrl; |
342 | | | 340 | |
343 | if (kctrl->bell == 0) | | 341 | if (kctrl->bell == 0) |
344 | return; | | 342 | return; |
345 | | | 343 | |
346 | x68kKbdRingBell(pDev, volume, kctrl->bell_duration); | | 344 | x68kKbdRingBell(pDev, volume, kctrl->bell_duration); |
347 | } | | 345 | } |
348 | | | 346 | |
349 | void | | 347 | void |
350 | DDXRingBell(int volume, int pitch, int duration) | | 348 | DDXRingBell(int volume, int pitch, int duration) |
351 | { | | 349 | { |
352 | DeviceIntPtr pKeyboard; | | 350 | DeviceIntPtr pKeyboard; |
353 | | | 351 | |
354 | pKeyboard = x68kKeyboardDevice; | | 352 | pKeyboard = x68kKeyboardDevice; |
355 | if (pKeyboard != NULL) | | 353 | if (pKeyboard != NULL) |
356 | x68kKbdRingBell(pKeyboard, volume, duration); | | 354 | x68kKbdRingBell(pKeyboard, volume, duration); |
357 | } | | 355 | } |
358 | | | 356 | |
359 | /*- | | 357 | /*- |
360 | *----------------------------------------------------------------------- | | 358 | *----------------------------------------------------------------------- |
361 | * x68kKbdCtrl -- | | 359 | * x68kKbdCtrl -- |
362 | * Alter some of the keyboard control parameters | | 360 | * Alter some of the keyboard control parameters |
363 | * | | 361 | * |
364 | * Results: | | 362 | * Results: |
365 | * None. | | 363 | * None. |
366 | * | | 364 | * |
367 | * Side Effects: | | 365 | * Side Effects: |
368 | * Some... | | 366 | * Some... |
369 | * | | 367 | * |
370 | *----------------------------------------------------------------------- | | 368 | *----------------------------------------------------------------------- |
371 | */ | | 369 | */ |
372 | #define XKB_LED_ZENKAKU 0x40 | | 370 | #define XKB_LED_ZENKAKU 0x40 |
373 | #define XKB_LED_HIRAGANA 0x20 | | 371 | #define XKB_LED_HIRAGANA 0x20 |
374 | #define XKB_LED_INSERT 0x10 | | 372 | #define XKB_LED_INSERT 0x10 |
375 | #define XKB_LED_CAPS_LOCK 0x08 | | 373 | #define XKB_LED_CAPS_LOCK 0x08 |
376 | #define XKB_LED_CODE_INPUT 0x04 | | 374 | #define XKB_LED_CODE_INPUT 0x04 |
377 | #define XKB_LED_ROMAJI 0x02 | | 375 | #define XKB_LED_ROMAJI 0x02 |
378 | #define XKB_LED_KANA_LOCK 0x01 | | 376 | #define XKB_LED_KANA_LOCK 0x01 |
379 | | | 377 | |
380 | static void | | 378 | static void |
381 | x68kKbdCtrl(DeviceIntPtr pDev, KeybdCtrl *ctrl) | | 379 | x68kKbdCtrl(DeviceIntPtr pDev, KeybdCtrl *ctrl) |
382 | { | | 380 | { |
383 | X68kKbdPrivPtr pPriv = (X68kKbdPrivPtr)pDev->public.devicePrivate; | | 381 | X68kKbdPrivPtr pPriv = (X68kKbdPrivPtr)pDev->public.devicePrivate; |
384 | | | 382 | |
385 | if (pPriv->leds != ctrl->leds) { | | 383 | if (pPriv->leds != ctrl->leds) { |
386 | x68kSetLeds(pPriv, (u_char)ctrl->leds); | | 384 | x68kSetLeds(pPriv, (u_char)ctrl->leds); |
387 | pPriv->leds = ctrl->leds; | | 385 | pPriv->leds = ctrl->leds; |
388 | } | | 386 | } |
389 | } | | 387 | } |
390 | | | 388 | |
391 | /*------------------------------------------------------------------------- | | 389 | /*------------------------------------------------------------------------- |
392 | * function "x68kSetLeds" | | 390 | * function "x68kSetLeds" |
393 | * | | 391 | * |
394 | * purpose: set keyboard leds to specified state | | 392 | * purpose: set keyboard leds to specified state |
395 | * argument: (X68kKbdPrivPtr)pPriv | | 393 | * argument: (X68kKbdPrivPtr)pPriv |
396 | * (u_char)data; | | 394 | * (u_char)data; |
397 | * returns: nothing | | 395 | * returns: nothing |
398 | *-----------------------------------------------------------------------*/ | | 396 | *-----------------------------------------------------------------------*/ |
399 | static void | | 397 | static void |
400 | x68kSetLeds(X68kKbdPrivPtr pPriv, u_char data) | | 398 | x68kSetLeds(X68kKbdPrivPtr pPriv, u_char data) |
401 | { | | 399 | { |
402 | /* bit sequence of led indicator in xkb and hardware are same */ | | 400 | /* bit sequence of led indicator in xkb and hardware are same */ |
403 | if (ioctl(pPriv->fd, KIOCSLED, &data) == -1) | | 401 | if (ioctl(pPriv->fd, KIOCSLED, &data) == -1) |
404 | ErrorF("Failed to set keyboard lights"); | | 402 | ErrorF("Failed to set keyboard lights"); |
405 | } | | 403 | } |
406 | | | 404 | |
407 | Bool | | 405 | Bool |
408 | LegalModifier(unsigned int key, DeviceIntPtr pDev) | | 406 | LegalModifier(unsigned int key, DeviceIntPtr pDev) |
409 | { | | 407 | { |
410 | return TRUE; | | 408 | return TRUE; |
411 | } | | 409 | } |
412 | | | 410 | |
413 | /* EOF x68kKbd.c */ | | 411 | /* EOF x68kKbd.c */ |