Mercurial > sdl-ios-xcode
comparison src/video/fbcon/SDL_fbevents.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
61 /* The translation tables from a console scancode to a SDL keysym */ | 61 /* The translation tables from a console scancode to a SDL keysym */ |
62 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) | 62 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) |
63 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; | 63 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; |
64 static SDLKey keymap[128]; | 64 static SDLKey keymap[128]; |
65 static Uint16 keymap_temp[128]; /* only used at startup */ | 65 static Uint16 keymap_temp[128]; /* only used at startup */ |
66 static SDL_keysym *TranslateKey (int scancode, SDL_keysym * keysym); | 66 static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym); |
67 | 67 |
68 /* Ugh, we have to duplicate the kernel's keysym mapping code... | 68 /* Ugh, we have to duplicate the kernel's keysym mapping code... |
69 Oh, it's not so bad. :-) | 69 Oh, it's not so bad. :-) |
70 | 70 |
71 FIXME: Add keyboard LED handling code | 71 FIXME: Add keyboard LED handling code |
72 */ | 72 */ |
73 static void | 73 static void |
74 FB_vgainitkeymaps (int fd) | 74 FB_vgainitkeymaps(int fd) |
75 { | 75 { |
76 struct kbentry entry; | 76 struct kbentry entry; |
77 int map, i; | 77 int map, i; |
78 | 78 |
79 /* Don't do anything if we are passed a closed keyboard */ | 79 /* Don't do anything if we are passed a closed keyboard */ |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 /* Load all the keysym mappings */ | 84 /* Load all the keysym mappings */ |
85 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { | 85 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { |
86 SDL_memset (vga_keymap[map], 0, NR_KEYS * sizeof (Uint16)); | 86 SDL_memset(vga_keymap[map], 0, NR_KEYS * sizeof(Uint16)); |
87 for (i = 0; i < NR_KEYS; ++i) { | 87 for (i = 0; i < NR_KEYS; ++i) { |
88 entry.kb_table = map; | 88 entry.kb_table = map; |
89 entry.kb_index = i; | 89 entry.kb_index = i; |
90 if (ioctl (fd, KDGKBENT, &entry) == 0) { | 90 if (ioctl(fd, KDGKBENT, &entry) == 0) { |
91 /* fill keytemp. This replaces SDL_fbkeys.h */ | 91 /* fill keytemp. This replaces SDL_fbkeys.h */ |
92 if ((map == 0) && (i < 128)) { | 92 if ((map == 0) && (i < 128)) { |
93 keymap_temp[i] = entry.kb_value; | 93 keymap_temp[i] = entry.kb_value; |
94 } | 94 } |
95 /* The "Enter" key is a special case */ | 95 /* The "Enter" key is a special case */ |
96 if (entry.kb_value == K_ENTER) { | 96 if (entry.kb_value == K_ENTER) { |
97 entry.kb_value = K (KT_ASCII, 13); | 97 entry.kb_value = K(KT_ASCII, 13); |
98 } | 98 } |
99 /* Handle numpad specially as well */ | 99 /* Handle numpad specially as well */ |
100 if (KTYP (entry.kb_value) == KT_PAD) { | 100 if (KTYP(entry.kb_value) == KT_PAD) { |
101 switch (entry.kb_value) { | 101 switch (entry.kb_value) { |
102 case K_P0: | 102 case K_P0: |
103 case K_P1: | 103 case K_P1: |
104 case K_P2: | 104 case K_P2: |
105 case K_P3: | 105 case K_P3: |
111 case K_P9: | 111 case K_P9: |
112 vga_keymap[map][i] = entry.kb_value; | 112 vga_keymap[map][i] = entry.kb_value; |
113 vga_keymap[map][i] += '0'; | 113 vga_keymap[map][i] += '0'; |
114 break; | 114 break; |
115 case K_PPLUS: | 115 case K_PPLUS: |
116 vga_keymap[map][i] = K (KT_ASCII, '+'); | 116 vga_keymap[map][i] = K(KT_ASCII, '+'); |
117 break; | 117 break; |
118 case K_PMINUS: | 118 case K_PMINUS: |
119 vga_keymap[map][i] = K (KT_ASCII, '-'); | 119 vga_keymap[map][i] = K(KT_ASCII, '-'); |
120 break; | 120 break; |
121 case K_PSTAR: | 121 case K_PSTAR: |
122 vga_keymap[map][i] = K (KT_ASCII, '*'); | 122 vga_keymap[map][i] = K(KT_ASCII, '*'); |
123 break; | 123 break; |
124 case K_PSLASH: | 124 case K_PSLASH: |
125 vga_keymap[map][i] = K (KT_ASCII, '/'); | 125 vga_keymap[map][i] = K(KT_ASCII, '/'); |
126 break; | 126 break; |
127 case K_PENTER: | 127 case K_PENTER: |
128 vga_keymap[map][i] = K (KT_ASCII, '\r'); | 128 vga_keymap[map][i] = K(KT_ASCII, '\r'); |
129 break; | 129 break; |
130 case K_PCOMMA: | 130 case K_PCOMMA: |
131 vga_keymap[map][i] = K (KT_ASCII, ','); | 131 vga_keymap[map][i] = K(KT_ASCII, ','); |
132 break; | 132 break; |
133 case K_PDOT: | 133 case K_PDOT: |
134 vga_keymap[map][i] = K (KT_ASCII, '.'); | 134 vga_keymap[map][i] = K(KT_ASCII, '.'); |
135 break; | 135 break; |
136 default: | 136 default: |
137 break; | 137 break; |
138 } | 138 } |
139 } | 139 } |
140 /* Do the normal key translation */ | 140 /* Do the normal key translation */ |
141 if ((KTYP (entry.kb_value) == KT_LATIN) || | 141 if ((KTYP(entry.kb_value) == KT_LATIN) || |
142 (KTYP (entry.kb_value) == KT_ASCII) || | 142 (KTYP(entry.kb_value) == KT_ASCII) || |
143 (KTYP (entry.kb_value) == KT_LETTER)) { | 143 (KTYP(entry.kb_value) == KT_LETTER)) { |
144 vga_keymap[map][i] = entry.kb_value; | 144 vga_keymap[map][i] = entry.kb_value; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 int | 151 int |
152 FB_InGraphicsMode (_THIS) | 152 FB_InGraphicsMode(_THIS) |
153 { | 153 { |
154 return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); | 154 return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); |
155 } | 155 } |
156 | 156 |
157 int | 157 int |
158 FB_EnterGraphicsMode (_THIS) | 158 FB_EnterGraphicsMode(_THIS) |
159 { | 159 { |
160 struct termios keyboard_termios; | 160 struct termios keyboard_termios; |
161 | 161 |
162 /* Set medium-raw keyboard mode */ | 162 /* Set medium-raw keyboard mode */ |
163 if ((keyboard_fd >= 0) && !FB_InGraphicsMode (this)) { | 163 if ((keyboard_fd >= 0) && !FB_InGraphicsMode(this)) { |
164 | 164 |
165 /* Switch to the correct virtual terminal */ | 165 /* Switch to the correct virtual terminal */ |
166 if (current_vt > 0) { | 166 if (current_vt > 0) { |
167 struct vt_stat vtstate; | 167 struct vt_stat vtstate; |
168 | 168 |
169 if (ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) { | 169 if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) { |
170 saved_vt = vtstate.v_active; | 170 saved_vt = vtstate.v_active; |
171 } | 171 } |
172 if (ioctl (keyboard_fd, VT_ACTIVATE, current_vt) == 0) { | 172 if (ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0) { |
173 ioctl (keyboard_fd, VT_WAITACTIVE, current_vt); | 173 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 /* Set the terminal input mode */ | 177 /* Set the terminal input mode */ |
178 if (tcgetattr (keyboard_fd, &saved_kbd_termios) < 0) { | 178 if (tcgetattr(keyboard_fd, &saved_kbd_termios) < 0) { |
179 SDL_SetError ("Unable to get terminal attributes"); | 179 SDL_SetError("Unable to get terminal attributes"); |
180 if (keyboard_fd > 0) { | 180 if (keyboard_fd > 0) { |
181 close (keyboard_fd); | 181 close(keyboard_fd); |
182 } | 182 } |
183 keyboard_fd = -1; | 183 keyboard_fd = -1; |
184 return (-1); | 184 return (-1); |
185 } | 185 } |
186 if (ioctl (keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) { | 186 if (ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) { |
187 SDL_SetError ("Unable to get current keyboard mode"); | 187 SDL_SetError("Unable to get current keyboard mode"); |
188 if (keyboard_fd > 0) { | 188 if (keyboard_fd > 0) { |
189 close (keyboard_fd); | 189 close(keyboard_fd); |
190 } | 190 } |
191 keyboard_fd = -1; | 191 keyboard_fd = -1; |
192 return (-1); | 192 return (-1); |
193 } | 193 } |
194 keyboard_termios = saved_kbd_termios; | 194 keyboard_termios = saved_kbd_termios; |
195 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); | 195 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); |
196 keyboard_termios.c_iflag &= | 196 keyboard_termios.c_iflag &= |
197 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); | 197 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); |
198 keyboard_termios.c_cc[VMIN] = 0; | 198 keyboard_termios.c_cc[VMIN] = 0; |
199 keyboard_termios.c_cc[VTIME] = 0; | 199 keyboard_termios.c_cc[VTIME] = 0; |
200 if (tcsetattr (keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { | 200 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { |
201 FB_CloseKeyboard (this); | 201 FB_CloseKeyboard(this); |
202 SDL_SetError ("Unable to set terminal attributes"); | 202 SDL_SetError("Unable to set terminal attributes"); |
203 return (-1); | 203 return (-1); |
204 } | 204 } |
205 /* This will fail if we aren't root or this isn't our tty */ | 205 /* This will fail if we aren't root or this isn't our tty */ |
206 if (ioctl (keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) { | 206 if (ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) { |
207 FB_CloseKeyboard (this); | 207 FB_CloseKeyboard(this); |
208 SDL_SetError ("Unable to set keyboard in raw mode"); | 208 SDL_SetError("Unable to set keyboard in raw mode"); |
209 return (-1); | 209 return (-1); |
210 } | 210 } |
211 if (ioctl (keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) { | 211 if (ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) { |
212 FB_CloseKeyboard (this); | 212 FB_CloseKeyboard(this); |
213 SDL_SetError ("Unable to set keyboard in graphics mode"); | 213 SDL_SetError("Unable to set keyboard in graphics mode"); |
214 return (-1); | 214 return (-1); |
215 } | 215 } |
216 /* Prevent switching the virtual terminal */ | 216 /* Prevent switching the virtual terminal */ |
217 ioctl (keyboard_fd, VT_LOCKSWITCH, 1); | 217 ioctl(keyboard_fd, VT_LOCKSWITCH, 1); |
218 } | 218 } |
219 return (keyboard_fd); | 219 return (keyboard_fd); |
220 } | 220 } |
221 | 221 |
222 void | 222 void |
223 FB_LeaveGraphicsMode (_THIS) | 223 FB_LeaveGraphicsMode(_THIS) |
224 { | 224 { |
225 if (FB_InGraphicsMode (this)) { | 225 if (FB_InGraphicsMode(this)) { |
226 ioctl (keyboard_fd, KDSETMODE, KD_TEXT); | 226 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
227 ioctl (keyboard_fd, KDSKBMODE, saved_kbd_mode); | 227 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); |
228 tcsetattr (keyboard_fd, TCSAFLUSH, &saved_kbd_termios); | 228 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); |
229 saved_kbd_mode = -1; | 229 saved_kbd_mode = -1; |
230 | 230 |
231 /* Head back over to the original virtual terminal */ | 231 /* Head back over to the original virtual terminal */ |
232 ioctl (keyboard_fd, VT_UNLOCKSWITCH, 1); | 232 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); |
233 if (saved_vt > 0) { | 233 if (saved_vt > 0) { |
234 ioctl (keyboard_fd, VT_ACTIVATE, saved_vt); | 234 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); |
235 } | 235 } |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 void | 239 void |
240 FB_CloseKeyboard (_THIS) | 240 FB_CloseKeyboard(_THIS) |
241 { | 241 { |
242 if (keyboard_fd >= 0) { | 242 if (keyboard_fd >= 0) { |
243 FB_LeaveGraphicsMode (this); | 243 FB_LeaveGraphicsMode(this); |
244 if (keyboard_fd > 0) { | 244 if (keyboard_fd > 0) { |
245 close (keyboard_fd); | 245 close(keyboard_fd); |
246 } | 246 } |
247 } | 247 } |
248 keyboard_fd = -1; | 248 keyboard_fd = -1; |
249 } | 249 } |
250 | 250 |
251 int | 251 int |
252 FB_OpenKeyboard (_THIS) | 252 FB_OpenKeyboard(_THIS) |
253 { | 253 { |
254 /* Open only if not already opened */ | 254 /* Open only if not already opened */ |
255 if (keyboard_fd < 0) { | 255 if (keyboard_fd < 0) { |
256 static const char *const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; | 256 static const char *const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; |
257 static const char *const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; | 257 static const char *const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; |
258 int i, tty0_fd; | 258 int i, tty0_fd; |
259 | 259 |
260 /* Try to query for a free virtual terminal */ | 260 /* Try to query for a free virtual terminal */ |
261 tty0_fd = -1; | 261 tty0_fd = -1; |
262 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { | 262 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { |
263 tty0_fd = open (tty0[i], O_WRONLY, 0); | 263 tty0_fd = open(tty0[i], O_WRONLY, 0); |
264 } | 264 } |
265 if (tty0_fd < 0) { | 265 if (tty0_fd < 0) { |
266 tty0_fd = dup (0); /* Maybe stdin is a VT? */ | 266 tty0_fd = dup(0); /* Maybe stdin is a VT? */ |
267 } | 267 } |
268 ioctl (tty0_fd, VT_OPENQRY, ¤t_vt); | 268 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); |
269 close (tty0_fd); | 269 close(tty0_fd); |
270 if ((geteuid () == 0) && (current_vt > 0)) { | 270 if ((geteuid() == 0) && (current_vt > 0)) { |
271 for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) { | 271 for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) { |
272 char vtpath[12]; | 272 char vtpath[12]; |
273 | 273 |
274 SDL_snprintf (vtpath, SDL_arraysize (vtpath), vcs[i], | 274 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], |
275 current_vt); | 275 current_vt); |
276 keyboard_fd = open (vtpath, O_RDWR, 0); | 276 keyboard_fd = open(vtpath, O_RDWR, 0); |
277 #ifdef DEBUG_KEYBOARD | 277 #ifdef DEBUG_KEYBOARD |
278 fprintf (stderr, "vtpath = %s, fd = %d\n", | 278 fprintf(stderr, "vtpath = %s, fd = %d\n", |
279 vtpath, keyboard_fd); | 279 vtpath, keyboard_fd); |
280 #endif /* DEBUG_KEYBOARD */ | 280 #endif /* DEBUG_KEYBOARD */ |
281 | 281 |
282 /* This needs to be our controlling tty | 282 /* This needs to be our controlling tty |
283 so that the kernel ioctl() calls work | 283 so that the kernel ioctl() calls work |
284 */ | 284 */ |
285 if (keyboard_fd >= 0) { | 285 if (keyboard_fd >= 0) { |
286 tty0_fd = open ("/dev/tty", O_RDWR, 0); | 286 tty0_fd = open("/dev/tty", O_RDWR, 0); |
287 if (tty0_fd >= 0) { | 287 if (tty0_fd >= 0) { |
288 ioctl (tty0_fd, TIOCNOTTY, 0); | 288 ioctl(tty0_fd, TIOCNOTTY, 0); |
289 close (tty0_fd); | 289 close(tty0_fd); |
290 } | 290 } |
291 } | 291 } |
292 } | 292 } |
293 } | 293 } |
294 if (keyboard_fd < 0) { | 294 if (keyboard_fd < 0) { |
295 /* Last resort, maybe our tty is a usable VT */ | 295 /* Last resort, maybe our tty is a usable VT */ |
296 struct vt_stat vtstate; | 296 struct vt_stat vtstate; |
297 | 297 |
298 keyboard_fd = open ("/dev/tty", O_RDWR); | 298 keyboard_fd = open("/dev/tty", O_RDWR); |
299 | 299 |
300 if (ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) { | 300 if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) { |
301 current_vt = vtstate.v_active; | 301 current_vt = vtstate.v_active; |
302 } else { | 302 } else { |
303 current_vt = 0; | 303 current_vt = 0; |
304 } | 304 } |
305 } | 305 } |
306 #ifdef DEBUG_KEYBOARD | 306 #ifdef DEBUG_KEYBOARD |
307 fprintf (stderr, "Current VT: %d\n", current_vt); | 307 fprintf(stderr, "Current VT: %d\n", current_vt); |
308 #endif | 308 #endif |
309 saved_kbd_mode = -1; | 309 saved_kbd_mode = -1; |
310 | 310 |
311 /* Make sure that our input is a console terminal */ | 311 /* Make sure that our input is a console terminal */ |
312 { | 312 { |
313 int dummy; | 313 int dummy; |
314 if (ioctl (keyboard_fd, KDGKBMODE, &dummy) < 0) { | 314 if (ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0) { |
315 close (keyboard_fd); | 315 close(keyboard_fd); |
316 keyboard_fd = -1; | 316 keyboard_fd = -1; |
317 SDL_SetError ("Unable to open a console terminal"); | 317 SDL_SetError("Unable to open a console terminal"); |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 /* Set up keymap */ | 321 /* Set up keymap */ |
322 FB_vgainitkeymaps (keyboard_fd); | 322 FB_vgainitkeymaps(keyboard_fd); |
323 } | 323 } |
324 return (keyboard_fd); | 324 return (keyboard_fd); |
325 } | 325 } |
326 | 326 |
327 static enum | 327 static enum |
336 MOUSE_TSLIB, | 336 MOUSE_TSLIB, |
337 NUM_MOUSE_DRVS | 337 NUM_MOUSE_DRVS |
338 } mouse_drv = MOUSE_NONE; | 338 } mouse_drv = MOUSE_NONE; |
339 | 339 |
340 void | 340 void |
341 FB_CloseMouse (_THIS) | 341 FB_CloseMouse(_THIS) |
342 { | 342 { |
343 #if SDL_INPUT_TSLIB | 343 #if SDL_INPUT_TSLIB |
344 if (ts_dev != NULL) { | 344 if (ts_dev != NULL) { |
345 ts_close (ts_dev); | 345 ts_close(ts_dev); |
346 ts_dev = NULL; | 346 ts_dev = NULL; |
347 mouse_fd = -1; | 347 mouse_fd = -1; |
348 } | 348 } |
349 #endif /* SDL_INPUT_TSLIB */ | 349 #endif /* SDL_INPUT_TSLIB */ |
350 if (mouse_fd > 0) { | 350 if (mouse_fd > 0) { |
351 close (mouse_fd); | 351 close(mouse_fd); |
352 } | 352 } |
353 mouse_fd = -1; | 353 mouse_fd = -1; |
354 } | 354 } |
355 | 355 |
356 /* Returns processes listed in /proc with the desired name */ | 356 /* Returns processes listed in /proc with the desired name */ |
357 static int | 357 static int |
358 find_pid (DIR * proc, const char *wanted_name) | 358 find_pid(DIR * proc, const char *wanted_name) |
359 { | 359 { |
360 struct dirent *entry; | 360 struct dirent *entry; |
361 int pid; | 361 int pid; |
362 | 362 |
363 /* First scan proc for the gpm process */ | 363 /* First scan proc for the gpm process */ |
364 pid = 0; | 364 pid = 0; |
365 while ((pid == 0) && ((entry = readdir (proc)) != NULL)) { | 365 while ((pid == 0) && ((entry = readdir(proc)) != NULL)) { |
366 if (isdigit (entry->d_name[0])) { | 366 if (isdigit(entry->d_name[0])) { |
367 FILE *status; | 367 FILE *status; |
368 char path[PATH_MAX]; | 368 char path[PATH_MAX]; |
369 char name[PATH_MAX]; | 369 char name[PATH_MAX]; |
370 | 370 |
371 SDL_snprintf (path, SDL_arraysize (path), "/proc/%s/status", | 371 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", |
372 entry->d_name); | 372 entry->d_name); |
373 status = fopen (path, "r"); | 373 status = fopen(path, "r"); |
374 if (status) { | 374 if (status) { |
375 name[0] = '\0'; | 375 name[0] = '\0'; |
376 fscanf (status, "Name: %s", name); | 376 fscanf(status, "Name: %s", name); |
377 if (SDL_strcmp (name, wanted_name) == 0) { | 377 if (SDL_strcmp(name, wanted_name) == 0) { |
378 pid = SDL_atoi (entry->d_name); | 378 pid = SDL_atoi(entry->d_name); |
379 } | 379 } |
380 fclose (status); | 380 fclose(status); |
381 } | 381 } |
382 } | 382 } |
383 } | 383 } |
384 return pid; | 384 return pid; |
385 } | 385 } |
386 | 386 |
387 /* Returns true if /dev/gpmdata is being written to by gpm */ | 387 /* Returns true if /dev/gpmdata is being written to by gpm */ |
388 static int | 388 static int |
389 gpm_available (char *proto, size_t protolen) | 389 gpm_available(char *proto, size_t protolen) |
390 { | 390 { |
391 int available; | 391 int available; |
392 DIR *proc; | 392 DIR *proc; |
393 int pid; | 393 int pid; |
394 int cmdline, len, arglen; | 394 int cmdline, len, arglen; |
395 char path[PATH_MAX]; | 395 char path[PATH_MAX]; |
396 char args[PATH_MAX], *arg; | 396 char args[PATH_MAX], *arg; |
397 | 397 |
398 /* Don't bother looking if the fifo isn't there */ | 398 /* Don't bother looking if the fifo isn't there */ |
399 #ifdef DEBUG_MOUSE | 399 #ifdef DEBUG_MOUSE |
400 fprintf (stderr, "testing gpm\n"); | 400 fprintf(stderr, "testing gpm\n"); |
401 #endif | 401 #endif |
402 if (access (GPM_NODE_FIFO, F_OK) < 0) { | 402 if (access(GPM_NODE_FIFO, F_OK) < 0) { |
403 return (0); | 403 return (0); |
404 } | 404 } |
405 | 405 |
406 available = 0; | 406 available = 0; |
407 proc = opendir ("/proc"); | 407 proc = opendir("/proc"); |
408 if (proc) { | 408 if (proc) { |
409 char raw_proto[10] = { '\0' }; | 409 char raw_proto[10] = { '\0' }; |
410 char repeat_proto[10] = { '\0' }; | 410 char repeat_proto[10] = { '\0' }; |
411 while (!available && (pid = find_pid (proc, "gpm")) > 0) { | 411 while (!available && (pid = find_pid(proc, "gpm")) > 0) { |
412 SDL_snprintf (path, SDL_arraysize (path), "/proc/%d/cmdline", | 412 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); |
413 pid); | 413 cmdline = open(path, O_RDONLY, 0); |
414 cmdline = open (path, O_RDONLY, 0); | |
415 if (cmdline >= 0) { | 414 if (cmdline >= 0) { |
416 len = read (cmdline, args, sizeof (args)); | 415 len = read(cmdline, args, sizeof(args)); |
417 arg = args; | 416 arg = args; |
418 while (len > 0) { | 417 while (len > 0) { |
419 arglen = SDL_strlen (arg) + 1; | 418 arglen = SDL_strlen(arg) + 1; |
420 #ifdef DEBUG_MOUSE | 419 #ifdef DEBUG_MOUSE |
421 fprintf (stderr, "gpm arg %s len %d\n", arg, arglen); | 420 fprintf(stderr, "gpm arg %s len %d\n", arg, arglen); |
422 #endif | 421 #endif |
423 if (SDL_strcmp (arg, "-t") == 0) { | 422 if (SDL_strcmp(arg, "-t") == 0) { |
424 /* protocol string, keep it for later */ | 423 /* protocol string, keep it for later */ |
425 char *t, *s; | 424 char *t, *s; |
426 t = arg + arglen; | 425 t = arg + arglen; |
427 s = SDL_strchr (t, ' '); | 426 s = SDL_strchr(t, ' '); |
428 if (s) | 427 if (s) |
429 *s = 0; | 428 *s = 0; |
430 SDL_strlcpy (raw_proto, t, SDL_arraysize (raw_proto)); | 429 SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto)); |
431 if (s) | 430 if (s) |
432 *s = ' '; | 431 *s = ' '; |
433 } | 432 } |
434 if (SDL_strncmp (arg, "-R", 2) == 0) { | 433 if (SDL_strncmp(arg, "-R", 2) == 0) { |
435 char *t, *s; | 434 char *t, *s; |
436 available = 1; | 435 available = 1; |
437 t = arg + 2; | 436 t = arg + 2; |
438 s = SDL_strchr (t, ' '); | 437 s = SDL_strchr(t, ' '); |
439 if (s) | 438 if (s) |
440 *s = 0; | 439 *s = 0; |
441 SDL_strlcpy (repeat_proto, t, | 440 SDL_strlcpy(repeat_proto, t, |
442 SDL_arraysize (repeat_proto)); | 441 SDL_arraysize(repeat_proto)); |
443 if (s) | 442 if (s) |
444 *s = ' '; | 443 *s = ' '; |
445 } | 444 } |
446 len -= arglen; | 445 len -= arglen; |
447 arg += arglen; | 446 arg += arglen; |
448 } | 447 } |
449 close (cmdline); | 448 close(cmdline); |
450 } | 449 } |
451 } | 450 } |
452 closedir (proc); | 451 closedir(proc); |
453 | 452 |
454 if (available) { | 453 if (available) { |
455 if (SDL_strcmp (repeat_proto, "raw") == 0) { | 454 if (SDL_strcmp(repeat_proto, "raw") == 0) { |
456 SDL_strlcpy (proto, raw_proto, protolen); | 455 SDL_strlcpy(proto, raw_proto, protolen); |
457 } else if (*repeat_proto) { | 456 } else if (*repeat_proto) { |
458 SDL_strlcpy (proto, repeat_proto, protolen); | 457 SDL_strlcpy(proto, repeat_proto, protolen); |
459 } else { | 458 } else { |
460 SDL_strlcpy (proto, "msc", protolen); | 459 SDL_strlcpy(proto, "msc", protolen); |
461 } | 460 } |
462 } | 461 } |
463 } | 462 } |
464 return available; | 463 return available; |
465 } | 464 } |
469 * us access to the mousewheel, etc. Returns zero if | 468 * us access to the mousewheel, etc. Returns zero if |
470 * writes to device failed, but you still need to query the | 469 * writes to device failed, but you still need to query the |
471 * device to see which mode it's actually in. | 470 * device to see which mode it's actually in. |
472 */ | 471 */ |
473 static int | 472 static int |
474 set_imps2_mode (int fd) | 473 set_imps2_mode(int fd) |
475 { | 474 { |
476 /* If you wanted to control the mouse mode (and we do :) ) ... | 475 /* If you wanted to control the mouse mode (and we do :) ) ... |
477 Set IMPS/2 protocol: | 476 Set IMPS/2 protocol: |
478 {0xf3,200,0xf3,100,0xf3,80} | 477 {0xf3,200,0xf3,100,0xf3,80} |
479 Reset mouse device: | 478 Reset mouse device: |
483 /*Uint8 reset = 0xff; */ | 482 /*Uint8 reset = 0xff; */ |
484 fd_set fdset; | 483 fd_set fdset; |
485 struct timeval tv; | 484 struct timeval tv; |
486 int retval = 0; | 485 int retval = 0; |
487 | 486 |
488 if (write (fd, &set_imps2, sizeof (set_imps2)) == sizeof (set_imps2)) { | 487 if (write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2)) { |
489 /* Don't reset it, that'll clear IMPS/2 mode on some mice | 488 /* Don't reset it, that'll clear IMPS/2 mode on some mice |
490 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { | 489 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { |
491 retval = 1; | 490 retval = 1; |
492 } | 491 } |
493 */ | 492 */ |
494 } | 493 } |
495 | 494 |
496 /* Get rid of any chatter from the above */ | 495 /* Get rid of any chatter from the above */ |
497 FD_ZERO (&fdset); | 496 FD_ZERO(&fdset); |
498 FD_SET (fd, &fdset); | 497 FD_SET(fd, &fdset); |
499 tv.tv_sec = 0; | 498 tv.tv_sec = 0; |
500 tv.tv_usec = 0; | 499 tv.tv_usec = 0; |
501 while (select (fd + 1, &fdset, 0, 0, &tv) > 0) { | 500 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
502 char temp[32]; | 501 char temp[32]; |
503 read (fd, temp, sizeof (temp)); | 502 read(fd, temp, sizeof(temp)); |
504 } | 503 } |
505 | 504 |
506 return retval; | 505 return retval; |
507 } | 506 } |
508 | 507 |
509 | 508 |
510 /* Returns true if the mouse uses the IMPS/2 protocol */ | 509 /* Returns true if the mouse uses the IMPS/2 protocol */ |
511 static int | 510 static int |
512 detect_imps2 (int fd) | 511 detect_imps2(int fd) |
513 { | 512 { |
514 int imps2; | 513 int imps2; |
515 | 514 |
516 imps2 = 0; | 515 imps2 = 0; |
517 | 516 |
518 if (SDL_getenv ("SDL_MOUSEDEV_IMPS2")) { | 517 if (SDL_getenv("SDL_MOUSEDEV_IMPS2")) { |
519 imps2 = 1; | 518 imps2 = 1; |
520 } | 519 } |
521 if (!imps2) { | 520 if (!imps2) { |
522 Uint8 query_ps2 = 0xF2; | 521 Uint8 query_ps2 = 0xF2; |
523 fd_set fdset; | 522 fd_set fdset; |
524 struct timeval tv; | 523 struct timeval tv; |
525 | 524 |
526 /* Get rid of any mouse motion noise */ | 525 /* Get rid of any mouse motion noise */ |
527 FD_ZERO (&fdset); | 526 FD_ZERO(&fdset); |
528 FD_SET (fd, &fdset); | 527 FD_SET(fd, &fdset); |
529 tv.tv_sec = 0; | 528 tv.tv_sec = 0; |
530 tv.tv_usec = 0; | 529 tv.tv_usec = 0; |
531 while (select (fd + 1, &fdset, 0, 0, &tv) > 0) { | 530 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
532 char temp[32]; | 531 char temp[32]; |
533 read (fd, temp, sizeof (temp)); | 532 read(fd, temp, sizeof(temp)); |
534 } | 533 } |
535 | 534 |
536 /* Query for the type of mouse protocol */ | 535 /* Query for the type of mouse protocol */ |
537 if (write (fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { | 536 if (write(fd, &query_ps2, sizeof(query_ps2)) == sizeof(query_ps2)) { |
538 Uint8 ch = 0; | 537 Uint8 ch = 0; |
539 | 538 |
540 /* Get the mouse protocol response */ | 539 /* Get the mouse protocol response */ |
541 do { | 540 do { |
542 FD_ZERO (&fdset); | 541 FD_ZERO(&fdset); |
543 FD_SET (fd, &fdset); | 542 FD_SET(fd, &fdset); |
544 tv.tv_sec = 1; | 543 tv.tv_sec = 1; |
545 tv.tv_usec = 0; | 544 tv.tv_usec = 0; |
546 if (select (fd + 1, &fdset, 0, 0, &tv) < 1) { | 545 if (select(fd + 1, &fdset, 0, 0, &tv) < 1) { |
547 break; | 546 break; |
548 } | 547 } |
549 } | 548 } |
550 while ((read (fd, &ch, sizeof (ch)) == sizeof (ch)) && | 549 while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && |
551 ((ch == 0xFA) || (ch == 0xAA))); | 550 ((ch == 0xFA) || (ch == 0xAA))); |
552 | 551 |
553 /* Experimental values (Logitech wheelmouse) */ | 552 /* Experimental values (Logitech wheelmouse) */ |
554 #ifdef DEBUG_MOUSE | 553 #ifdef DEBUG_MOUSE |
555 fprintf (stderr, "Last mouse mode: 0x%x\n", ch); | 554 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); |
556 #endif | 555 #endif |
557 if ((ch == 3) || (ch == 4)) { | 556 if ((ch == 3) || (ch == 4)) { |
558 imps2 = 1; | 557 imps2 = 1; |
559 } | 558 } |
560 } | 559 } |
561 } | 560 } |
562 return imps2; | 561 return imps2; |
563 } | 562 } |
564 | 563 |
565 int | 564 int |
566 FB_OpenMouse (_THIS) | 565 FB_OpenMouse(_THIS) |
567 { | 566 { |
568 int i; | 567 int i; |
569 const char *mousedev; | 568 const char *mousedev; |
570 const char *mousedrv; | 569 const char *mousedrv; |
571 | 570 |
572 mousedrv = SDL_getenv ("SDL_MOUSEDRV"); | 571 mousedrv = SDL_getenv("SDL_MOUSEDRV"); |
573 mousedev = SDL_getenv ("SDL_MOUSEDEV"); | 572 mousedev = SDL_getenv("SDL_MOUSEDEV"); |
574 mouse_fd = -1; | 573 mouse_fd = -1; |
575 | 574 |
576 #if SDL_INPUT_TSLIB | 575 #if SDL_INPUT_TSLIB |
577 if (mousedrv && (SDL_strcmp (mousedrv, "TSLIB") == 0)) { | 576 if (mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0)) { |
578 if (mousedev == NULL) | 577 if (mousedev == NULL) |
579 mousedev = SDL_getenv ("TSLIB_TSDEVICE"); | 578 mousedev = SDL_getenv("TSLIB_TSDEVICE"); |
580 if (mousedev != NULL) { | 579 if (mousedev != NULL) { |
581 ts_dev = ts_open (mousedev, 1); | 580 ts_dev = ts_open(mousedev, 1); |
582 if ((ts_dev != NULL) && (ts_config (ts_dev) >= 0)) { | 581 if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) { |
583 #ifdef DEBUG_MOUSE | 582 #ifdef DEBUG_MOUSE |
584 fprintf (stderr, "Using tslib touchscreen\n"); | 583 fprintf(stderr, "Using tslib touchscreen\n"); |
585 #endif | 584 #endif |
586 mouse_drv = MOUSE_TSLIB; | 585 mouse_drv = MOUSE_TSLIB; |
587 mouse_fd = ts_fd (ts_dev); | 586 mouse_fd = ts_fd(ts_dev); |
588 return mouse_fd; | 587 return mouse_fd; |
589 } | 588 } |
590 } | 589 } |
591 mouse_drv = MOUSE_NONE; | 590 mouse_drv = MOUSE_NONE; |
592 return mouse_fd; | 591 return mouse_fd; |
593 } | 592 } |
594 #endif /* SDL_INPUT_TSLIB */ | 593 #endif /* SDL_INPUT_TSLIB */ |
595 | 594 |
596 /* ELO TOUCHSCREEN SUPPORT */ | 595 /* ELO TOUCHSCREEN SUPPORT */ |
597 | 596 |
598 if (mousedrv && (SDL_strcmp (mousedrv, "ELO") == 0)) { | 597 if (mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0)) { |
599 mouse_fd = open (mousedev, O_RDWR); | 598 mouse_fd = open(mousedev, O_RDWR); |
600 if (mouse_fd >= 0) { | 599 if (mouse_fd >= 0) { |
601 if (eloInitController (mouse_fd)) { | 600 if (eloInitController(mouse_fd)) { |
602 #ifdef DEBUG_MOUSE | 601 #ifdef DEBUG_MOUSE |
603 fprintf (stderr, "Using ELO touchscreen\n"); | 602 fprintf(stderr, "Using ELO touchscreen\n"); |
604 #endif | 603 #endif |
605 mouse_drv = MOUSE_ELO; | 604 mouse_drv = MOUSE_ELO; |
606 } | 605 } |
607 | 606 |
608 } else if (mouse_fd < 0) { | 607 } else if (mouse_fd < 0) { |
620 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL | 619 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL |
621 }; | 620 }; |
622 /* First try to use GPM in repeater mode */ | 621 /* First try to use GPM in repeater mode */ |
623 if (mouse_fd < 0) { | 622 if (mouse_fd < 0) { |
624 char proto[10]; | 623 char proto[10]; |
625 if (gpm_available (proto, SDL_arraysize (proto))) { | 624 if (gpm_available(proto, SDL_arraysize(proto))) { |
626 mouse_fd = open (GPM_NODE_FIFO, O_RDONLY, 0); | 625 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); |
627 if (mouse_fd >= 0) { | 626 if (mouse_fd >= 0) { |
628 if (SDL_strcmp (proto, "msc") == 0) { | 627 if (SDL_strcmp(proto, "msc") == 0) { |
629 mouse_drv = MOUSE_MSC; | 628 mouse_drv = MOUSE_MSC; |
630 } else if (SDL_strcmp (proto, "ps2") == 0) { | 629 } else if (SDL_strcmp(proto, "ps2") == 0) { |
631 mouse_drv = MOUSE_PS2; | 630 mouse_drv = MOUSE_PS2; |
632 } else if (SDL_strcmp (proto, "imps2") == 0) { | 631 } else if (SDL_strcmp(proto, "imps2") == 0) { |
633 mouse_drv = MOUSE_IMPS2; | 632 mouse_drv = MOUSE_IMPS2; |
634 } else if (SDL_strcmp (proto, "ms") == 0 || | 633 } else if (SDL_strcmp(proto, "ms") == 0 || |
635 SDL_strcmp (proto, "bare") == 0) { | 634 SDL_strcmp(proto, "bare") == 0) { |
636 mouse_drv = MOUSE_MS; | 635 mouse_drv = MOUSE_MS; |
637 } else if (SDL_strcmp (proto, "bm") == 0) { | 636 } else if (SDL_strcmp(proto, "bm") == 0) { |
638 mouse_drv = MOUSE_BM; | 637 mouse_drv = MOUSE_BM; |
639 } else { | 638 } else { |
640 /* Unknown protocol... */ | 639 /* Unknown protocol... */ |
641 #ifdef DEBUG_MOUSE | 640 #ifdef DEBUG_MOUSE |
642 fprintf (stderr, | 641 fprintf(stderr, |
643 "GPM mouse using unknown protocol = %s\n", | 642 "GPM mouse using unknown protocol = %s\n", |
644 proto); | 643 proto); |
645 #endif | 644 #endif |
646 close (mouse_fd); | 645 close(mouse_fd); |
647 mouse_fd = -1; | 646 mouse_fd = -1; |
648 } | 647 } |
649 } | 648 } |
650 #ifdef DEBUG_MOUSE | 649 #ifdef DEBUG_MOUSE |
651 if (mouse_fd >= 0) { | 650 if (mouse_fd >= 0) { |
652 fprintf (stderr, | 651 fprintf(stderr, |
653 "Using GPM mouse, protocol = %s\n", proto); | 652 "Using GPM mouse, protocol = %s\n", proto); |
654 } | 653 } |
655 #endif /* DEBUG_MOUSE */ | 654 #endif /* DEBUG_MOUSE */ |
656 } | 655 } |
657 } | 656 } |
658 /* Now try to use a modern PS/2 mouse */ | 657 /* Now try to use a modern PS/2 mouse */ |
659 for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) { | 658 for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) { |
660 mouse_fd = open (ps2mice[i], O_RDWR, 0); | 659 mouse_fd = open(ps2mice[i], O_RDWR, 0); |
661 if (mouse_fd < 0) { | 660 if (mouse_fd < 0) { |
662 mouse_fd = open (ps2mice[i], O_RDONLY, 0); | 661 mouse_fd = open(ps2mice[i], O_RDONLY, 0); |
663 } | 662 } |
664 if (mouse_fd >= 0) { | 663 if (mouse_fd >= 0) { |
665 /* rcg06112001 Attempt to set IMPS/2 mode */ | 664 /* rcg06112001 Attempt to set IMPS/2 mode */ |
666 set_imps2_mode (mouse_fd); | 665 set_imps2_mode(mouse_fd); |
667 if (detect_imps2 (mouse_fd)) { | 666 if (detect_imps2(mouse_fd)) { |
668 #ifdef DEBUG_MOUSE | 667 #ifdef DEBUG_MOUSE |
669 fprintf (stderr, "Using IMPS2 mouse\n"); | 668 fprintf(stderr, "Using IMPS2 mouse\n"); |
670 #endif | 669 #endif |
671 mouse_drv = MOUSE_IMPS2; | 670 mouse_drv = MOUSE_IMPS2; |
672 } else { | 671 } else { |
673 #ifdef DEBUG_MOUSE | 672 #ifdef DEBUG_MOUSE |
674 fprintf (stderr, "Using PS2 mouse\n"); | 673 fprintf(stderr, "Using PS2 mouse\n"); |
675 #endif | 674 #endif |
676 mouse_drv = MOUSE_PS2; | 675 mouse_drv = MOUSE_PS2; |
677 } | 676 } |
678 } | 677 } |
679 } | 678 } |
680 /* Next try to use a PPC ADB port mouse */ | 679 /* Next try to use a PPC ADB port mouse */ |
681 if (mouse_fd < 0) { | 680 if (mouse_fd < 0) { |
682 mouse_fd = open ("/dev/adbmouse", O_RDONLY, 0); | 681 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); |
683 if (mouse_fd >= 0) { | 682 if (mouse_fd >= 0) { |
684 #ifdef DEBUG_MOUSE | 683 #ifdef DEBUG_MOUSE |
685 fprintf (stderr, "Using ADB mouse\n"); | 684 fprintf(stderr, "Using ADB mouse\n"); |
686 #endif | 685 #endif |
687 mouse_drv = MOUSE_BM; | 686 mouse_drv = MOUSE_BM; |
688 } | 687 } |
689 } | 688 } |
690 } | 689 } |
691 /* Default to a serial Microsoft mouse */ | 690 /* Default to a serial Microsoft mouse */ |
692 if (mouse_fd < 0) { | 691 if (mouse_fd < 0) { |
693 if (mousedev == NULL) { | 692 if (mousedev == NULL) { |
694 mousedev = "/dev/mouse"; | 693 mousedev = "/dev/mouse"; |
695 } | 694 } |
696 mouse_fd = open (mousedev, O_RDONLY, 0); | 695 mouse_fd = open(mousedev, O_RDONLY, 0); |
697 if (mouse_fd >= 0) { | 696 if (mouse_fd >= 0) { |
698 struct termios mouse_termios; | 697 struct termios mouse_termios; |
699 | 698 |
700 /* Set the sampling speed to 1200 baud */ | 699 /* Set the sampling speed to 1200 baud */ |
701 tcgetattr (mouse_fd, &mouse_termios); | 700 tcgetattr(mouse_fd, &mouse_termios); |
702 mouse_termios.c_iflag = IGNBRK | IGNPAR; | 701 mouse_termios.c_iflag = IGNBRK | IGNPAR; |
703 mouse_termios.c_oflag = 0; | 702 mouse_termios.c_oflag = 0; |
704 mouse_termios.c_lflag = 0; | 703 mouse_termios.c_lflag = 0; |
705 mouse_termios.c_line = 0; | 704 mouse_termios.c_line = 0; |
706 mouse_termios.c_cc[VTIME] = 0; | 705 mouse_termios.c_cc[VTIME] = 0; |
707 mouse_termios.c_cc[VMIN] = 1; | 706 mouse_termios.c_cc[VMIN] = 1; |
708 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; | 707 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; |
709 mouse_termios.c_cflag |= CS8; | 708 mouse_termios.c_cflag |= CS8; |
710 mouse_termios.c_cflag |= B1200; | 709 mouse_termios.c_cflag |= B1200; |
711 tcsetattr (mouse_fd, TCSAFLUSH, &mouse_termios); | 710 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); |
712 if (mousedrv && (SDL_strcmp (mousedrv, "PS2") == 0)) { | 711 if (mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0)) { |
713 #ifdef DEBUG_MOUSE | 712 #ifdef DEBUG_MOUSE |
714 fprintf (stderr, | 713 fprintf(stderr, |
715 "Using (user specified) PS2 mouse on %s\n", | 714 "Using (user specified) PS2 mouse on %s\n", mousedev); |
716 mousedev); | |
717 #endif | 715 #endif |
718 mouse_drv = MOUSE_PS2; | 716 mouse_drv = MOUSE_PS2; |
719 } else { | 717 } else { |
720 #ifdef DEBUG_MOUSE | 718 #ifdef DEBUG_MOUSE |
721 fprintf (stderr, "Using (default) MS mouse on %s\n", | 719 fprintf(stderr, "Using (default) MS mouse on %s\n", mousedev); |
722 mousedev); | |
723 #endif | 720 #endif |
724 mouse_drv = MOUSE_MS; | 721 mouse_drv = MOUSE_MS; |
725 } | 722 } |
726 } | 723 } |
727 } | 724 } |
732 } | 729 } |
733 | 730 |
734 static int posted = 0; | 731 static int posted = 0; |
735 | 732 |
736 void | 733 void |
737 FB_vgamousecallback (int button, int relative, int dx, int dy) | 734 FB_vgamousecallback(int button, int relative, int dx, int dy) |
738 { | 735 { |
739 int button_1, button_3; | 736 int button_1, button_3; |
740 int button_state; | 737 int button_state; |
741 int state_changed; | 738 int state_changed; |
742 int i; | 739 int i; |
743 Uint8 state; | 740 Uint8 state; |
744 | 741 |
745 if (dx || dy) { | 742 if (dx || dy) { |
746 posted += SDL_PrivateMouseMotion (0, relative, dx, dy); | 743 posted += SDL_PrivateMouseMotion(0, relative, dx, dy); |
747 } | 744 } |
748 | 745 |
749 /* Swap button 1 and 3 */ | 746 /* Swap button 1 and 3 */ |
750 button_1 = (button & 0x04) >> 2; | 747 button_1 = (button & 0x04) >> 2; |
751 button_3 = (button & 0x01) << 2; | 748 button_3 = (button & 0x01) << 2; |
752 button &= ~0x05; | 749 button &= ~0x05; |
753 button |= (button_1 | button_3); | 750 button |= (button_1 | button_3); |
754 | 751 |
755 /* See what changed */ | 752 /* See what changed */ |
756 button_state = SDL_GetMouseState (NULL, NULL); | 753 button_state = SDL_GetMouseState(NULL, NULL); |
757 state_changed = button_state ^ button; | 754 state_changed = button_state ^ button; |
758 for (i = 0; i < 8; ++i) { | 755 for (i = 0; i < 8; ++i) { |
759 if (state_changed & (1 << i)) { | 756 if (state_changed & (1 << i)) { |
760 if (button & (1 << i)) { | 757 if (button & (1 << i)) { |
761 state = SDL_PRESSED; | 758 state = SDL_PRESSED; |
762 } else { | 759 } else { |
763 state = SDL_RELEASED; | 760 state = SDL_RELEASED; |
764 } | 761 } |
765 posted += SDL_PrivateMouseButton (state, i + 1, 0, 0); | 762 posted += SDL_PrivateMouseButton(state, i + 1, 0, 0); |
766 } | 763 } |
767 } | 764 } |
768 } | 765 } |
769 | 766 |
770 /* Handle input from tslib */ | 767 /* Handle input from tslib */ |
771 #if SDL_INPUT_TSLIB | 768 #if SDL_INPUT_TSLIB |
772 static void | 769 static void |
773 handle_tslib (_THIS) | 770 handle_tslib(_THIS) |
774 { | 771 { |
775 struct ts_sample sample; | 772 struct ts_sample sample; |
776 int button; | 773 int button; |
777 | 774 |
778 while (ts_read (ts_dev, &sample, 1) > 0) { | 775 while (ts_read(ts_dev, &sample, 1) > 0) { |
779 button = (sample.pressure > 0) ? 1 : 0; | 776 button = (sample.pressure > 0) ? 1 : 0; |
780 button <<= 2; /* must report it as button 3 */ | 777 button <<= 2; /* must report it as button 3 */ |
781 FB_vgamousecallback (button, 0, sample.x, sample.y); | 778 FB_vgamousecallback(button, 0, sample.x, sample.y); |
782 } | 779 } |
783 return; | 780 return; |
784 } | 781 } |
785 #endif /* SDL_INPUT_TSLIB */ | 782 #endif /* SDL_INPUT_TSLIB */ |
786 | 783 |
787 /* For now, use MSC, PS/2, and MS protocols | 784 /* For now, use MSC, PS/2, and MS protocols |
788 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) | 785 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) |
789 */ | 786 */ |
790 static void | 787 static void |
791 handle_mouse (_THIS) | 788 handle_mouse(_THIS) |
792 { | 789 { |
793 static int start = 0; | 790 static int start = 0; |
794 static unsigned char mousebuf[BUFSIZ]; | 791 static unsigned char mousebuf[BUFSIZ]; |
795 static int relative = 1; | 792 static int relative = 1; |
796 | 793 |
802 | 799 |
803 /* Figure out the mouse packet size */ | 800 /* Figure out the mouse packet size */ |
804 switch (mouse_drv) { | 801 switch (mouse_drv) { |
805 case MOUSE_NONE: | 802 case MOUSE_NONE: |
806 /* Ack! */ | 803 /* Ack! */ |
807 read (mouse_fd, mousebuf, BUFSIZ); | 804 read(mouse_fd, mousebuf, BUFSIZ); |
808 return; | 805 return; |
809 case MOUSE_MSC: | 806 case MOUSE_MSC: |
810 packetsize = 5; | 807 packetsize = 5; |
811 break; | 808 break; |
812 case MOUSE_IMPS2: | 809 case MOUSE_IMPS2: |
820 case MOUSE_ELO: | 817 case MOUSE_ELO: |
821 /* try to read the next packet */ | 818 /* try to read the next packet */ |
822 if (eloReadPosition | 819 if (eloReadPosition |
823 (this, mouse_fd, &dx, &dy, &button, &realx, &realy)) { | 820 (this, mouse_fd, &dx, &dy, &button, &realx, &realy)) { |
824 button = (button & 0x01) << 2; | 821 button = (button & 0x01) << 2; |
825 FB_vgamousecallback (button, 0, dx, dy); | 822 FB_vgamousecallback(button, 0, dx, dy); |
826 } | 823 } |
827 return; /* nothing left to do */ | 824 return; /* nothing left to do */ |
828 case MOUSE_TSLIB: | 825 case MOUSE_TSLIB: |
829 #if SDL_INPUT_TSLIB | 826 #if SDL_INPUT_TSLIB |
830 handle_tslib (this); | 827 handle_tslib(this); |
831 #endif | 828 #endif |
832 return; /* nothing left to do */ | 829 return; /* nothing left to do */ |
833 default: | 830 default: |
834 /* Uh oh.. */ | 831 /* Uh oh.. */ |
835 packetsize = 0; | 832 packetsize = 0; |
840 if (mouse_drv == MOUSE_ELO) { | 837 if (mouse_drv == MOUSE_ELO) { |
841 | 838 |
842 } | 839 } |
843 | 840 |
844 /* Read as many packets as possible */ | 841 /* Read as many packets as possible */ |
845 nread = read (mouse_fd, &mousebuf[start], BUFSIZ - start); | 842 nread = read(mouse_fd, &mousebuf[start], BUFSIZ - start); |
846 if (nread < 0) { | 843 if (nread < 0) { |
847 return; | 844 return; |
848 } | 845 } |
849 nread += start; | 846 nread += start; |
850 #ifdef DEBUG_MOUSE | 847 #ifdef DEBUG_MOUSE |
851 fprintf (stderr, "Read %d bytes from mouse, start = %d\n", nread, start); | 848 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start); |
852 #endif | 849 #endif |
853 for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) { | 850 for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) { |
854 switch (mouse_drv) { | 851 switch (mouse_drv) { |
855 case MOUSE_NONE: | 852 case MOUSE_NONE: |
856 break; | 853 break; |
898 switch (mousebuf[i + 3] & 0x0F) { | 895 switch (mousebuf[i + 3] & 0x0F) { |
899 case 0x0E: /* DX = +1 */ | 896 case 0x0E: /* DX = +1 */ |
900 case 0x02: /* DX = -1 */ | 897 case 0x02: /* DX = -1 */ |
901 break; | 898 break; |
902 case 0x0F: /* DY = +1 (map button 4) */ | 899 case 0x0F: /* DY = +1 (map button 4) */ |
903 FB_vgamousecallback (button | (1 << 3), 1, 0, 0); | 900 FB_vgamousecallback(button | (1 << 3), 1, 0, 0); |
904 break; | 901 break; |
905 case 0x01: /* DY = -1 (map button 5) */ | 902 case 0x01: /* DY = -1 (map button 5) */ |
906 FB_vgamousecallback (button | (1 << 4), 1, 0, 0); | 903 FB_vgamousecallback(button | (1 << 4), 1, 0, 0); |
907 break; | 904 break; |
908 } | 905 } |
909 break; | 906 break; |
910 case MOUSE_MS: | 907 case MOUSE_MS: |
911 /* Microsoft protocol has 0x40 in high byte */ | 908 /* Microsoft protocol has 0x40 in high byte */ |
938 /* Uh oh.. */ | 935 /* Uh oh.. */ |
939 dx = 0; | 936 dx = 0; |
940 dy = 0; | 937 dy = 0; |
941 break; | 938 break; |
942 } | 939 } |
943 FB_vgamousecallback (button, relative, dx, dy); | 940 FB_vgamousecallback(button, relative, dx, dy); |
944 } | 941 } |
945 if (i < nread) { | 942 if (i < nread) { |
946 SDL_memcpy (mousebuf, &mousebuf[i], (nread - i)); | 943 SDL_memcpy(mousebuf, &mousebuf[i], (nread - i)); |
947 start = (nread - i); | 944 start = (nread - i); |
948 } else { | 945 } else { |
949 start = 0; | 946 start = 0; |
950 } | 947 } |
951 return; | 948 return; |
952 } | 949 } |
953 | 950 |
954 /* Handle switching to another VC, returns when our VC is back */ | 951 /* Handle switching to another VC, returns when our VC is back */ |
955 static void | 952 static void |
956 switch_vt_prep (_THIS) | 953 switch_vt_prep(_THIS) |
957 { | 954 { |
958 SDL_Surface *screen = SDL_VideoSurface; | 955 SDL_Surface *screen = SDL_VideoSurface; |
959 | 956 |
960 SDL_PrivateAppActive (0, | 957 SDL_PrivateAppActive(0, |
961 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | | 958 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | |
962 SDL_APPMOUSEFOCUS)); | 959 SDL_APPMOUSEFOCUS)); |
963 | 960 |
964 /* Save the contents of the screen, and go to text mode */ | 961 /* Save the contents of the screen, and go to text mode */ |
965 wait_idle (this); | 962 wait_idle(this); |
966 screen_arealen = ((screen->h + (2 * this->offset_y)) * screen->pitch); | 963 screen_arealen = ((screen->h + (2 * this->offset_y)) * screen->pitch); |
967 screen_contents = (Uint8 *) SDL_malloc (screen_arealen); | 964 screen_contents = (Uint8 *) SDL_malloc(screen_arealen); |
968 if (screen_contents) { | 965 if (screen_contents) { |
969 SDL_memcpy (screen_contents, screen->pixels, screen_arealen); | 966 SDL_memcpy(screen_contents, screen->pixels, screen_arealen); |
970 } | 967 } |
971 FB_SavePaletteTo (this, 256, screen_palette); | 968 FB_SavePaletteTo(this, 256, screen_palette); |
972 ioctl (console_fd, FBIOGET_VSCREENINFO, &screen_vinfo); | 969 ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo); |
973 ioctl (keyboard_fd, KDSETMODE, KD_TEXT); | 970 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
974 ioctl (keyboard_fd, VT_UNLOCKSWITCH, 1); | 971 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); |
975 } | 972 } |
976 static void | 973 static void |
977 switch_vt_done (_THIS) | 974 switch_vt_done(_THIS) |
978 { | 975 { |
979 SDL_Surface *screen = SDL_VideoSurface; | 976 SDL_Surface *screen = SDL_VideoSurface; |
980 | 977 |
981 /* Restore graphics mode and the contents of the screen */ | 978 /* Restore graphics mode and the contents of the screen */ |
982 ioctl (keyboard_fd, VT_LOCKSWITCH, 1); | 979 ioctl(keyboard_fd, VT_LOCKSWITCH, 1); |
983 ioctl (keyboard_fd, KDSETMODE, KD_GRAPHICS); | 980 ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS); |
984 ioctl (console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo); | 981 ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo); |
985 FB_RestorePaletteFrom (this, 256, screen_palette); | 982 FB_RestorePaletteFrom(this, 256, screen_palette); |
986 if (screen_contents) { | 983 if (screen_contents) { |
987 SDL_memcpy (screen->pixels, screen_contents, screen_arealen); | 984 SDL_memcpy(screen->pixels, screen_contents, screen_arealen); |
988 SDL_free (screen_contents); | 985 SDL_free(screen_contents); |
989 screen_contents = NULL; | 986 screen_contents = NULL; |
990 } | 987 } |
991 | 988 |
992 /* Get updates to the shadow surface while switched away */ | 989 /* Get updates to the shadow surface while switched away */ |
993 if (SDL_ShadowSurface) { | 990 if (SDL_ShadowSurface) { |
994 SDL_UpdateRect (SDL_ShadowSurface, 0, 0, 0, 0); | 991 SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0); |
995 } | 992 } |
996 | 993 |
997 SDL_PrivateAppActive (1, | 994 SDL_PrivateAppActive(1, |
998 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | | 995 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | |
999 SDL_APPMOUSEFOCUS)); | 996 SDL_APPMOUSEFOCUS)); |
1000 } | 997 } |
1001 static void | 998 static void |
1002 switch_vt (_THIS, unsigned short which) | 999 switch_vt(_THIS, unsigned short which) |
1003 { | 1000 { |
1004 struct vt_stat vtstate; | 1001 struct vt_stat vtstate; |
1005 | 1002 |
1006 /* Figure out whether or not we're switching to a new console */ | 1003 /* Figure out whether or not we're switching to a new console */ |
1007 if ((ioctl (keyboard_fd, VT_GETSTATE, &vtstate) < 0) || | 1004 if ((ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) || |
1008 (which == vtstate.v_active)) { | 1005 (which == vtstate.v_active)) { |
1009 return; | 1006 return; |
1010 } | 1007 } |
1011 | 1008 |
1012 /* New console, switch to it */ | 1009 /* New console, switch to it */ |
1013 SDL_mutexP (hw_lock); | 1010 SDL_mutexP(hw_lock); |
1014 switch_vt_prep (this); | 1011 switch_vt_prep(this); |
1015 if (ioctl (keyboard_fd, VT_ACTIVATE, which) == 0) { | 1012 if (ioctl(keyboard_fd, VT_ACTIVATE, which) == 0) { |
1016 ioctl (keyboard_fd, VT_WAITACTIVE, which); | 1013 ioctl(keyboard_fd, VT_WAITACTIVE, which); |
1017 switched_away = 1; | 1014 switched_away = 1; |
1018 } else { | 1015 } else { |
1019 switch_vt_done (this); | 1016 switch_vt_done(this); |
1020 } | 1017 } |
1021 SDL_mutexV (hw_lock); | 1018 SDL_mutexV(hw_lock); |
1022 } | 1019 } |
1023 | 1020 |
1024 static void | 1021 static void |
1025 handle_keyboard (_THIS) | 1022 handle_keyboard(_THIS) |
1026 { | 1023 { |
1027 unsigned char keybuf[BUFSIZ]; | 1024 unsigned char keybuf[BUFSIZ]; |
1028 int i, nread; | 1025 int i, nread; |
1029 int pressed; | 1026 int pressed; |
1030 int scancode; | 1027 int scancode; |
1031 SDL_keysym keysym; | 1028 SDL_keysym keysym; |
1032 | 1029 |
1033 nread = read (keyboard_fd, keybuf, BUFSIZ); | 1030 nread = read(keyboard_fd, keybuf, BUFSIZ); |
1034 for (i = 0; i < nread; ++i) { | 1031 for (i = 0; i < nread; ++i) { |
1035 scancode = keybuf[i] & 0x7F; | 1032 scancode = keybuf[i] & 0x7F; |
1036 if (keybuf[i] & 0x80) { | 1033 if (keybuf[i] & 0x80) { |
1037 pressed = SDL_RELEASED; | 1034 pressed = SDL_RELEASED; |
1038 } else { | 1035 } else { |
1039 pressed = SDL_PRESSED; | 1036 pressed = SDL_PRESSED; |
1040 } | 1037 } |
1041 TranslateKey (scancode, &keysym); | 1038 TranslateKey(scancode, &keysym); |
1042 /* Handle Ctrl-Alt-FN for vt switch */ | 1039 /* Handle Ctrl-Alt-FN for vt switch */ |
1043 switch (keysym.sym) { | 1040 switch (keysym.sym) { |
1044 case SDLK_F1: | 1041 case SDLK_F1: |
1045 case SDLK_F2: | 1042 case SDLK_F2: |
1046 case SDLK_F3: | 1043 case SDLK_F3: |
1051 case SDLK_F8: | 1048 case SDLK_F8: |
1052 case SDLK_F9: | 1049 case SDLK_F9: |
1053 case SDLK_F10: | 1050 case SDLK_F10: |
1054 case SDLK_F11: | 1051 case SDLK_F11: |
1055 case SDLK_F12: | 1052 case SDLK_F12: |
1056 if ((SDL_GetModState () & KMOD_CTRL) && | 1053 if ((SDL_GetModState() & KMOD_CTRL) && |
1057 (SDL_GetModState () & KMOD_ALT)) { | 1054 (SDL_GetModState() & KMOD_ALT)) { |
1058 if (pressed) { | 1055 if (pressed) { |
1059 switch_vt (this, (keysym.sym - SDLK_F1) + 1); | 1056 switch_vt(this, (keysym.sym - SDLK_F1) + 1); |
1060 } | 1057 } |
1061 break; | 1058 break; |
1062 } | 1059 } |
1063 /* Fall through to normal processing */ | 1060 /* Fall through to normal processing */ |
1064 default: | 1061 default: |
1065 posted += SDL_PrivateKeyboard (pressed, &keysym); | 1062 posted += SDL_PrivateKeyboard(pressed, &keysym); |
1066 break; | 1063 break; |
1067 } | 1064 } |
1068 } | 1065 } |
1069 } | 1066 } |
1070 | 1067 |
1071 void | 1068 void |
1072 FB_PumpEvents (_THIS) | 1069 FB_PumpEvents(_THIS) |
1073 { | 1070 { |
1074 fd_set fdset; | 1071 fd_set fdset; |
1075 int max_fd; | 1072 int max_fd; |
1076 static struct timeval zero; | 1073 static struct timeval zero; |
1077 | 1074 |
1078 do { | 1075 do { |
1079 if (switched_away) { | 1076 if (switched_away) { |
1080 struct vt_stat vtstate; | 1077 struct vt_stat vtstate; |
1081 | 1078 |
1082 SDL_mutexP (hw_lock); | 1079 SDL_mutexP(hw_lock); |
1083 if ((ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) && | 1080 if ((ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) && |
1084 vtstate.v_active == current_vt) { | 1081 vtstate.v_active == current_vt) { |
1085 switched_away = 0; | 1082 switched_away = 0; |
1086 switch_vt_done (this); | 1083 switch_vt_done(this); |
1087 } | 1084 } |
1088 SDL_mutexV (hw_lock); | 1085 SDL_mutexV(hw_lock); |
1089 } | 1086 } |
1090 | 1087 |
1091 posted = 0; | 1088 posted = 0; |
1092 | 1089 |
1093 FD_ZERO (&fdset); | 1090 FD_ZERO(&fdset); |
1094 max_fd = 0; | 1091 max_fd = 0; |
1095 if (keyboard_fd >= 0) { | 1092 if (keyboard_fd >= 0) { |
1096 FD_SET (keyboard_fd, &fdset); | 1093 FD_SET(keyboard_fd, &fdset); |
1097 if (max_fd < keyboard_fd) { | 1094 if (max_fd < keyboard_fd) { |
1098 max_fd = keyboard_fd; | 1095 max_fd = keyboard_fd; |
1099 } | 1096 } |
1100 } | 1097 } |
1101 if (mouse_fd >= 0) { | 1098 if (mouse_fd >= 0) { |
1102 FD_SET (mouse_fd, &fdset); | 1099 FD_SET(mouse_fd, &fdset); |
1103 if (max_fd < mouse_fd) { | 1100 if (max_fd < mouse_fd) { |
1104 max_fd = mouse_fd; | 1101 max_fd = mouse_fd; |
1105 } | 1102 } |
1106 } | 1103 } |
1107 if (select (max_fd + 1, &fdset, NULL, NULL, &zero) > 0) { | 1104 if (select(max_fd + 1, &fdset, NULL, NULL, &zero) > 0) { |
1108 if (keyboard_fd >= 0) { | 1105 if (keyboard_fd >= 0) { |
1109 if (FD_ISSET (keyboard_fd, &fdset)) { | 1106 if (FD_ISSET(keyboard_fd, &fdset)) { |
1110 handle_keyboard (this); | 1107 handle_keyboard(this); |
1111 } | 1108 } |
1112 } | 1109 } |
1113 if (mouse_fd >= 0) { | 1110 if (mouse_fd >= 0) { |
1114 if (FD_ISSET (mouse_fd, &fdset)) { | 1111 if (FD_ISSET(mouse_fd, &fdset)) { |
1115 handle_mouse (this); | 1112 handle_mouse(this); |
1116 } | 1113 } |
1117 } | 1114 } |
1118 } | 1115 } |
1119 } | 1116 } |
1120 while (posted); | 1117 while (posted); |
1121 } | 1118 } |
1122 | 1119 |
1123 void | 1120 void |
1124 FB_InitOSKeymap (_THIS) | 1121 FB_InitOSKeymap(_THIS) |
1125 { | 1122 { |
1126 int i; | 1123 int i; |
1127 | 1124 |
1128 /* Initialize the Linux key translation table */ | 1125 /* Initialize the Linux key translation table */ |
1129 | 1126 |
1130 /* First get the ascii keys and others not well handled */ | 1127 /* First get the ascii keys and others not well handled */ |
1131 for (i = 0; i < SDL_arraysize (keymap); ++i) { | 1128 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
1132 switch (i) { | 1129 switch (i) { |
1133 /* These aren't handled by the x86 kernel keymapping (?) */ | 1130 /* These aren't handled by the x86 kernel keymapping (?) */ |
1134 case SCANCODE_PRINTSCREEN: | 1131 case SCANCODE_PRINTSCREEN: |
1135 keymap[i] = SDLK_PRINT; | 1132 keymap[i] = SDLK_PRINT; |
1136 break; | 1133 break; |
1167 case 127: | 1164 case 127: |
1168 keymap[i] = SDLK_MENU; | 1165 keymap[i] = SDLK_MENU; |
1169 break; | 1166 break; |
1170 /* this should take care of all standard ascii keys */ | 1167 /* this should take care of all standard ascii keys */ |
1171 default: | 1168 default: |
1172 keymap[i] = KVAL (vga_keymap[0][i]); | 1169 keymap[i] = KVAL(vga_keymap[0][i]); |
1173 break; | 1170 break; |
1174 } | 1171 } |
1175 } | 1172 } |
1176 for (i = 0; i < SDL_arraysize (keymap); ++i) { | 1173 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
1177 switch (keymap_temp[i]) { | 1174 switch (keymap_temp[i]) { |
1178 case K_F1: | 1175 case K_F1: |
1179 keymap[i] = SDLK_F1; | 1176 keymap[i] = SDLK_F1; |
1180 break; | 1177 break; |
1181 case K_F2: | 1178 case K_F2: |
1346 } | 1343 } |
1347 } | 1344 } |
1348 } | 1345 } |
1349 | 1346 |
1350 static SDL_keysym * | 1347 static SDL_keysym * |
1351 TranslateKey (int scancode, SDL_keysym * keysym) | 1348 TranslateKey(int scancode, SDL_keysym * keysym) |
1352 { | 1349 { |
1353 /* Set the keysym information */ | 1350 /* Set the keysym information */ |
1354 keysym->scancode = scancode; | 1351 keysym->scancode = scancode; |
1355 keysym->sym = keymap[scancode]; | 1352 keysym->sym = keymap[scancode]; |
1356 keysym->mod = KMOD_NONE; | 1353 keysym->mod = KMOD_NONE; |
1359 keysym->unicode = 0; | 1356 keysym->unicode = 0; |
1360 if (SDL_TranslateUNICODE) { | 1357 if (SDL_TranslateUNICODE) { |
1361 int map; | 1358 int map; |
1362 SDLMod modstate; | 1359 SDLMod modstate; |
1363 | 1360 |
1364 modstate = SDL_GetModState (); | 1361 modstate = SDL_GetModState(); |
1365 map = 0; | 1362 map = 0; |
1366 if (modstate & KMOD_SHIFT) { | 1363 if (modstate & KMOD_SHIFT) { |
1367 map |= (1 << KG_SHIFT); | 1364 map |= (1 << KG_SHIFT); |
1368 } | 1365 } |
1369 if (modstate & KMOD_CTRL) { | 1366 if (modstate & KMOD_CTRL) { |
1373 map |= (1 << KG_ALT); | 1370 map |= (1 << KG_ALT); |
1374 } | 1371 } |
1375 if (modstate & KMOD_RALT) { | 1372 if (modstate & KMOD_RALT) { |
1376 map |= (1 << KG_ALTGR); | 1373 map |= (1 << KG_ALTGR); |
1377 } | 1374 } |
1378 if (KTYP (vga_keymap[map][scancode]) == KT_LETTER) { | 1375 if (KTYP(vga_keymap[map][scancode]) == KT_LETTER) { |
1379 if (modstate & KMOD_CAPS) { | 1376 if (modstate & KMOD_CAPS) { |
1380 map ^= (1 << KG_SHIFT); | 1377 map ^= (1 << KG_SHIFT); |
1381 } | 1378 } |
1382 } | 1379 } |
1383 if (KTYP (vga_keymap[map][scancode]) == KT_PAD) { | 1380 if (KTYP(vga_keymap[map][scancode]) == KT_PAD) { |
1384 if (modstate & KMOD_NUM) { | 1381 if (modstate & KMOD_NUM) { |
1385 keysym->unicode = KVAL (vga_keymap[map][scancode]); | 1382 keysym->unicode = KVAL(vga_keymap[map][scancode]); |
1386 } | 1383 } |
1387 } else { | 1384 } else { |
1388 keysym->unicode = KVAL (vga_keymap[map][scancode]); | 1385 keysym->unicode = KVAL(vga_keymap[map][scancode]); |
1389 } | 1386 } |
1390 } | 1387 } |
1391 return (keysym); | 1388 return (keysym); |
1392 } | 1389 } |
1393 | 1390 |