Mercurial > sdl-ios-xcode
comparison src/video/ps2gs/SDL_gsevents.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 |
---|---|
54 /* The translation tables from a console scancode to a SDL keysym */ | 54 /* The translation tables from a console scancode to a SDL keysym */ |
55 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) | 55 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) |
56 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; | 56 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; |
57 static SDLKey keymap[128]; | 57 static SDLKey keymap[128]; |
58 static Uint16 keymap_temp[128]; /* only used at startup */ | 58 static Uint16 keymap_temp[128]; /* only used at startup */ |
59 static SDL_keysym *TranslateKey (int scancode, SDL_keysym * keysym); | 59 static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym); |
60 | 60 |
61 /* Ugh, we have to duplicate the kernel's keysym mapping code... | 61 /* Ugh, we have to duplicate the kernel's keysym mapping code... |
62 Oh, it's not so bad. :-) | 62 Oh, it's not so bad. :-) |
63 | 63 |
64 FIXME: Add keyboard LED handling code | 64 FIXME: Add keyboard LED handling code |
65 */ | 65 */ |
66 static void | 66 static void |
67 GS_vgainitkeymaps (int fd) | 67 GS_vgainitkeymaps(int fd) |
68 { | 68 { |
69 struct kbentry entry; | 69 struct kbentry entry; |
70 int map, i; | 70 int map, i; |
71 | 71 |
72 /* Don't do anything if we are passed a closed keyboard */ | 72 /* Don't do anything if we are passed a closed keyboard */ |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 /* Load all the keysym mappings */ | 77 /* Load all the keysym mappings */ |
78 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { | 78 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { |
79 SDL_memset (vga_keymap[map], 0, NR_KEYS * sizeof (Uint16)); | 79 SDL_memset(vga_keymap[map], 0, NR_KEYS * sizeof(Uint16)); |
80 for (i = 0; i < NR_KEYS; ++i) { | 80 for (i = 0; i < NR_KEYS; ++i) { |
81 entry.kb_table = map; | 81 entry.kb_table = map; |
82 entry.kb_index = i; | 82 entry.kb_index = i; |
83 if (ioctl (fd, KDGKBENT, &entry) == 0) { | 83 if (ioctl(fd, KDGKBENT, &entry) == 0) { |
84 /* fill keytemp. This replaces SDL_fbkeys.h */ | 84 /* fill keytemp. This replaces SDL_fbkeys.h */ |
85 if ((map == 0) && (i < 128)) { | 85 if ((map == 0) && (i < 128)) { |
86 keymap_temp[i] = entry.kb_value; | 86 keymap_temp[i] = entry.kb_value; |
87 } | 87 } |
88 /* The "Enter" key is a special case */ | 88 /* The "Enter" key is a special case */ |
89 if (entry.kb_value == K_ENTER) { | 89 if (entry.kb_value == K_ENTER) { |
90 entry.kb_value = K (KT_ASCII, 13); | 90 entry.kb_value = K(KT_ASCII, 13); |
91 } | 91 } |
92 /* Handle numpad specially as well */ | 92 /* Handle numpad specially as well */ |
93 if (KTYP (entry.kb_value) == KT_PAD) { | 93 if (KTYP(entry.kb_value) == KT_PAD) { |
94 switch (entry.kb_value) { | 94 switch (entry.kb_value) { |
95 case K_P0: | 95 case K_P0: |
96 case K_P1: | 96 case K_P1: |
97 case K_P2: | 97 case K_P2: |
98 case K_P3: | 98 case K_P3: |
104 case K_P9: | 104 case K_P9: |
105 vga_keymap[map][i] = entry.kb_value; | 105 vga_keymap[map][i] = entry.kb_value; |
106 vga_keymap[map][i] += '0'; | 106 vga_keymap[map][i] += '0'; |
107 break; | 107 break; |
108 case K_PPLUS: | 108 case K_PPLUS: |
109 vga_keymap[map][i] = K (KT_ASCII, '+'); | 109 vga_keymap[map][i] = K(KT_ASCII, '+'); |
110 break; | 110 break; |
111 case K_PMINUS: | 111 case K_PMINUS: |
112 vga_keymap[map][i] = K (KT_ASCII, '-'); | 112 vga_keymap[map][i] = K(KT_ASCII, '-'); |
113 break; | 113 break; |
114 case K_PSTAR: | 114 case K_PSTAR: |
115 vga_keymap[map][i] = K (KT_ASCII, '*'); | 115 vga_keymap[map][i] = K(KT_ASCII, '*'); |
116 break; | 116 break; |
117 case K_PSLASH: | 117 case K_PSLASH: |
118 vga_keymap[map][i] = K (KT_ASCII, '/'); | 118 vga_keymap[map][i] = K(KT_ASCII, '/'); |
119 break; | 119 break; |
120 case K_PENTER: | 120 case K_PENTER: |
121 vga_keymap[map][i] = K (KT_ASCII, '\r'); | 121 vga_keymap[map][i] = K(KT_ASCII, '\r'); |
122 break; | 122 break; |
123 case K_PCOMMA: | 123 case K_PCOMMA: |
124 vga_keymap[map][i] = K (KT_ASCII, ','); | 124 vga_keymap[map][i] = K(KT_ASCII, ','); |
125 break; | 125 break; |
126 case K_PDOT: | 126 case K_PDOT: |
127 vga_keymap[map][i] = K (KT_ASCII, '.'); | 127 vga_keymap[map][i] = K(KT_ASCII, '.'); |
128 break; | 128 break; |
129 default: | 129 default: |
130 break; | 130 break; |
131 } | 131 } |
132 } | 132 } |
133 /* Do the normal key translation */ | 133 /* Do the normal key translation */ |
134 if ((KTYP (entry.kb_value) == KT_LATIN) || | 134 if ((KTYP(entry.kb_value) == KT_LATIN) || |
135 (KTYP (entry.kb_value) == KT_ASCII) || | 135 (KTYP(entry.kb_value) == KT_ASCII) || |
136 (KTYP (entry.kb_value) == KT_LETTER)) { | 136 (KTYP(entry.kb_value) == KT_LETTER)) { |
137 vga_keymap[map][i] = entry.kb_value; | 137 vga_keymap[map][i] = entry.kb_value; |
138 } | 138 } |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 int | 144 int |
145 GS_InGraphicsMode (_THIS) | 145 GS_InGraphicsMode(_THIS) |
146 { | 146 { |
147 return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); | 147 return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); |
148 } | 148 } |
149 | 149 |
150 int | 150 int |
151 GS_EnterGraphicsMode (_THIS) | 151 GS_EnterGraphicsMode(_THIS) |
152 { | 152 { |
153 struct termios keyboard_termios; | 153 struct termios keyboard_termios; |
154 | 154 |
155 /* Set medium-raw keyboard mode */ | 155 /* Set medium-raw keyboard mode */ |
156 if ((keyboard_fd >= 0) && !GS_InGraphicsMode (this)) { | 156 if ((keyboard_fd >= 0) && !GS_InGraphicsMode(this)) { |
157 | 157 |
158 /* Switch to the correct virtual terminal */ | 158 /* Switch to the correct virtual terminal */ |
159 if (current_vt > 0) { | 159 if (current_vt > 0) { |
160 struct vt_stat vtstate; | 160 struct vt_stat vtstate; |
161 | 161 |
162 if (ioctl (keyboard_fd, VT_GETSTATE, &vtstate) == 0) { | 162 if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) { |
163 saved_vt = vtstate.v_active; | 163 saved_vt = vtstate.v_active; |
164 } | 164 } |
165 if (ioctl (keyboard_fd, VT_ACTIVATE, current_vt) == 0) { | 165 if (ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0) { |
166 ioctl (keyboard_fd, VT_WAITACTIVE, current_vt); | 166 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 /* Set the terminal input mode */ | 170 /* Set the terminal input mode */ |
171 if (tcgetattr (keyboard_fd, &saved_kbd_termios) < 0) { | 171 if (tcgetattr(keyboard_fd, &saved_kbd_termios) < 0) { |
172 SDL_SetError ("Unable to get terminal attributes"); | 172 SDL_SetError("Unable to get terminal attributes"); |
173 if (keyboard_fd > 0) { | 173 if (keyboard_fd > 0) { |
174 close (keyboard_fd); | 174 close(keyboard_fd); |
175 } | 175 } |
176 keyboard_fd = -1; | 176 keyboard_fd = -1; |
177 return (-1); | 177 return (-1); |
178 } | 178 } |
179 if (ioctl (keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) { | 179 if (ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) { |
180 SDL_SetError ("Unable to get current keyboard mode"); | 180 SDL_SetError("Unable to get current keyboard mode"); |
181 if (keyboard_fd > 0) { | 181 if (keyboard_fd > 0) { |
182 close (keyboard_fd); | 182 close(keyboard_fd); |
183 } | 183 } |
184 keyboard_fd = -1; | 184 keyboard_fd = -1; |
185 return (-1); | 185 return (-1); |
186 } | 186 } |
187 keyboard_termios = saved_kbd_termios; | 187 keyboard_termios = saved_kbd_termios; |
188 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); | 188 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); |
189 keyboard_termios.c_iflag &= | 189 keyboard_termios.c_iflag &= |
190 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); | 190 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); |
191 keyboard_termios.c_cc[VMIN] = 0; | 191 keyboard_termios.c_cc[VMIN] = 0; |
192 keyboard_termios.c_cc[VTIME] = 0; | 192 keyboard_termios.c_cc[VTIME] = 0; |
193 if (tcsetattr (keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { | 193 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { |
194 GS_CloseKeyboard (this); | 194 GS_CloseKeyboard(this); |
195 SDL_SetError ("Unable to set terminal attributes"); | 195 SDL_SetError("Unable to set terminal attributes"); |
196 return (-1); | 196 return (-1); |
197 } | 197 } |
198 /* This will fail if we aren't root or this isn't our tty */ | 198 /* This will fail if we aren't root or this isn't our tty */ |
199 if (ioctl (keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) { | 199 if (ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) { |
200 GS_CloseKeyboard (this); | 200 GS_CloseKeyboard(this); |
201 SDL_SetError ("Unable to set keyboard in raw mode"); | 201 SDL_SetError("Unable to set keyboard in raw mode"); |
202 return (-1); | 202 return (-1); |
203 } | 203 } |
204 if (ioctl (keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) { | 204 if (ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) { |
205 GS_CloseKeyboard (this); | 205 GS_CloseKeyboard(this); |
206 SDL_SetError ("Unable to set keyboard in graphics mode"); | 206 SDL_SetError("Unable to set keyboard in graphics mode"); |
207 return (-1); | 207 return (-1); |
208 } | 208 } |
209 } | 209 } |
210 return (keyboard_fd); | 210 return (keyboard_fd); |
211 } | 211 } |
212 | 212 |
213 void | 213 void |
214 GS_LeaveGraphicsMode (_THIS) | 214 GS_LeaveGraphicsMode(_THIS) |
215 { | 215 { |
216 if (GS_InGraphicsMode (this)) { | 216 if (GS_InGraphicsMode(this)) { |
217 ioctl (keyboard_fd, KDSETMODE, KD_TEXT); | 217 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
218 ioctl (keyboard_fd, KDSKBMODE, saved_kbd_mode); | 218 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); |
219 tcsetattr (keyboard_fd, TCSAFLUSH, &saved_kbd_termios); | 219 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); |
220 saved_kbd_mode = -1; | 220 saved_kbd_mode = -1; |
221 | 221 |
222 /* Head back over to the original virtual terminal */ | 222 /* Head back over to the original virtual terminal */ |
223 if (saved_vt > 0) { | 223 if (saved_vt > 0) { |
224 ioctl (keyboard_fd, VT_ACTIVATE, saved_vt); | 224 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); |
225 } | 225 } |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 void | 229 void |
230 GS_CloseKeyboard (_THIS) | 230 GS_CloseKeyboard(_THIS) |
231 { | 231 { |
232 if (keyboard_fd >= 0) { | 232 if (keyboard_fd >= 0) { |
233 GS_LeaveGraphicsMode (this); | 233 GS_LeaveGraphicsMode(this); |
234 if (keyboard_fd > 0) { | 234 if (keyboard_fd > 0) { |
235 close (keyboard_fd); | 235 close(keyboard_fd); |
236 } | 236 } |
237 } | 237 } |
238 keyboard_fd = -1; | 238 keyboard_fd = -1; |
239 } | 239 } |
240 | 240 |
241 int | 241 int |
242 GS_OpenKeyboard (_THIS) | 242 GS_OpenKeyboard(_THIS) |
243 { | 243 { |
244 /* Open only if not already opened */ | 244 /* Open only if not already opened */ |
245 if (keyboard_fd < 0) { | 245 if (keyboard_fd < 0) { |
246 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; | 246 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; |
247 char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; | 247 char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; |
248 int i, tty0_fd; | 248 int i, tty0_fd; |
249 | 249 |
250 /* Try to query for a free virtual terminal */ | 250 /* Try to query for a free virtual terminal */ |
251 tty0_fd = -1; | 251 tty0_fd = -1; |
252 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { | 252 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { |
253 tty0_fd = open (tty0[i], O_WRONLY, 0); | 253 tty0_fd = open(tty0[i], O_WRONLY, 0); |
254 } | 254 } |
255 if (tty0_fd < 0) { | 255 if (tty0_fd < 0) { |
256 tty0_fd = dup (0); /* Maybe stdin is a VT? */ | 256 tty0_fd = dup(0); /* Maybe stdin is a VT? */ |
257 } | 257 } |
258 ioctl (tty0_fd, VT_OPENQRY, ¤t_vt); | 258 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); |
259 close (tty0_fd); | 259 close(tty0_fd); |
260 if ((geteuid () == 0) && (current_vt > 0)) { | 260 if ((geteuid() == 0) && (current_vt > 0)) { |
261 for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) { | 261 for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) { |
262 char vtpath[12]; | 262 char vtpath[12]; |
263 | 263 |
264 SDL_snprintf (vtpath, SDL_arraysize (vtpath), vcs[i], | 264 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], |
265 current_vt); | 265 current_vt); |
266 keyboard_fd = open (vtpath, O_RDWR, 0); | 266 keyboard_fd = open(vtpath, O_RDWR, 0); |
267 #ifdef DEBUG_KEYBOARD | 267 #ifdef DEBUG_KEYBOARD |
268 fprintf (stderr, "vtpath = %s, fd = %d\n", | 268 fprintf(stderr, "vtpath = %s, fd = %d\n", |
269 vtpath, keyboard_fd); | 269 vtpath, keyboard_fd); |
270 #endif /* DEBUG_KEYBOARD */ | 270 #endif /* DEBUG_KEYBOARD */ |
271 | 271 |
272 /* This needs to be our controlling tty | 272 /* This needs to be our controlling tty |
273 so that the kernel ioctl() calls work | 273 so that the kernel ioctl() calls work |
274 */ | 274 */ |
275 if (keyboard_fd >= 0) { | 275 if (keyboard_fd >= 0) { |
276 tty0_fd = open ("/dev/tty", O_RDWR, 0); | 276 tty0_fd = open("/dev/tty", O_RDWR, 0); |
277 if (tty0_fd >= 0) { | 277 if (tty0_fd >= 0) { |
278 ioctl (tty0_fd, TIOCNOTTY, 0); | 278 ioctl(tty0_fd, TIOCNOTTY, 0); |
279 close (tty0_fd); | 279 close(tty0_fd); |
280 } | 280 } |
281 } | 281 } |
282 } | 282 } |
283 } | 283 } |
284 if (keyboard_fd < 0) { | 284 if (keyboard_fd < 0) { |
285 /* Last resort, maybe our tty is a usable VT */ | 285 /* Last resort, maybe our tty is a usable VT */ |
286 current_vt = 0; | 286 current_vt = 0; |
287 keyboard_fd = open ("/dev/tty", O_RDWR); | 287 keyboard_fd = open("/dev/tty", O_RDWR); |
288 } | 288 } |
289 #ifdef DEBUG_KEYBOARD | 289 #ifdef DEBUG_KEYBOARD |
290 fprintf (stderr, "Current VT: %d\n", current_vt); | 290 fprintf(stderr, "Current VT: %d\n", current_vt); |
291 #endif | 291 #endif |
292 saved_kbd_mode = -1; | 292 saved_kbd_mode = -1; |
293 | 293 |
294 /* Make sure that our input is a console terminal */ | 294 /* Make sure that our input is a console terminal */ |
295 { | 295 { |
296 int dummy; | 296 int dummy; |
297 if (ioctl (keyboard_fd, KDGKBMODE, &dummy) < 0) { | 297 if (ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0) { |
298 close (keyboard_fd); | 298 close(keyboard_fd); |
299 keyboard_fd = -1; | 299 keyboard_fd = -1; |
300 SDL_SetError ("Unable to open a console terminal"); | 300 SDL_SetError("Unable to open a console terminal"); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 /* Set up keymap */ | 304 /* Set up keymap */ |
305 GS_vgainitkeymaps (keyboard_fd); | 305 GS_vgainitkeymaps(keyboard_fd); |
306 } | 306 } |
307 return (keyboard_fd); | 307 return (keyboard_fd); |
308 } | 308 } |
309 | 309 |
310 static enum | 310 static enum |
317 MOUSE_BM, | 317 MOUSE_BM, |
318 NUM_MOUSE_DRVS | 318 NUM_MOUSE_DRVS |
319 } mouse_drv = MOUSE_NONE; | 319 } mouse_drv = MOUSE_NONE; |
320 | 320 |
321 void | 321 void |
322 GS_CloseMouse (_THIS) | 322 GS_CloseMouse(_THIS) |
323 { | 323 { |
324 if (mouse_fd > 0) { | 324 if (mouse_fd > 0) { |
325 close (mouse_fd); | 325 close(mouse_fd); |
326 } | 326 } |
327 mouse_fd = -1; | 327 mouse_fd = -1; |
328 } | 328 } |
329 | 329 |
330 /* Returns processes listed in /proc with the desired name */ | 330 /* Returns processes listed in /proc with the desired name */ |
331 static int | 331 static int |
332 find_pid (DIR * proc, const char *wanted_name) | 332 find_pid(DIR * proc, const char *wanted_name) |
333 { | 333 { |
334 struct dirent *entry; | 334 struct dirent *entry; |
335 int pid; | 335 int pid; |
336 | 336 |
337 /* First scan proc for the gpm process */ | 337 /* First scan proc for the gpm process */ |
338 pid = 0; | 338 pid = 0; |
339 while ((pid == 0) && ((entry = readdir (proc)) != NULL)) { | 339 while ((pid == 0) && ((entry = readdir(proc)) != NULL)) { |
340 if (isdigit (entry->d_name[0])) { | 340 if (isdigit(entry->d_name[0])) { |
341 FILE *status; | 341 FILE *status; |
342 char path[PATH_MAX]; | 342 char path[PATH_MAX]; |
343 char name[PATH_MAX]; | 343 char name[PATH_MAX]; |
344 | 344 |
345 SDL_snprintf (path, SDL_arraysize (path), "/proc/%s/status", | 345 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", |
346 entry->d_name); | 346 entry->d_name); |
347 status = fopen (path, "r"); | 347 status = fopen(path, "r"); |
348 if (status) { | 348 if (status) { |
349 name[0] = '\0'; | 349 name[0] = '\0'; |
350 fscanf (status, "Name: %s", name); | 350 fscanf(status, "Name: %s", name); |
351 if (SDL_strcmp (name, wanted_name) == 0) { | 351 if (SDL_strcmp(name, wanted_name) == 0) { |
352 pid = atoi (entry->d_name); | 352 pid = atoi(entry->d_name); |
353 } | 353 } |
354 fclose (status); | 354 fclose(status); |
355 } | 355 } |
356 } | 356 } |
357 } | 357 } |
358 return pid; | 358 return pid; |
359 } | 359 } |
360 | 360 |
361 /* Returns true if /dev/gpmdata is being written to by gpm */ | 361 /* Returns true if /dev/gpmdata is being written to by gpm */ |
362 static int | 362 static int |
363 gpm_available (void) | 363 gpm_available(void) |
364 { | 364 { |
365 int available; | 365 int available; |
366 DIR *proc; | 366 DIR *proc; |
367 int pid; | 367 int pid; |
368 int cmdline, len, arglen; | 368 int cmdline, len, arglen; |
369 char path[PATH_MAX]; | 369 char path[PATH_MAX]; |
370 char args[PATH_MAX], *arg; | 370 char args[PATH_MAX], *arg; |
371 | 371 |
372 /* Don't bother looking if the fifo isn't there */ | 372 /* Don't bother looking if the fifo isn't there */ |
373 if (access (GPM_NODE_FIFO, F_OK) < 0) { | 373 if (access(GPM_NODE_FIFO, F_OK) < 0) { |
374 return (0); | 374 return (0); |
375 } | 375 } |
376 | 376 |
377 available = 0; | 377 available = 0; |
378 proc = opendir ("/proc"); | 378 proc = opendir("/proc"); |
379 if (proc) { | 379 if (proc) { |
380 while ((pid = find_pid (proc, "gpm")) > 0) { | 380 while ((pid = find_pid(proc, "gpm")) > 0) { |
381 SDL_snprintf (path, SDL_arraysize (path), "/proc/%d/cmdline", | 381 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); |
382 pid); | 382 cmdline = open(path, O_RDONLY, 0); |
383 cmdline = open (path, O_RDONLY, 0); | |
384 if (cmdline >= 0) { | 383 if (cmdline >= 0) { |
385 len = read (cmdline, args, sizeof (args)); | 384 len = read(cmdline, args, sizeof(args)); |
386 arg = args; | 385 arg = args; |
387 while (len > 0) { | 386 while (len > 0) { |
388 if (SDL_strcmp (arg, "-R") == 0) { | 387 if (SDL_strcmp(arg, "-R") == 0) { |
389 available = 1; | 388 available = 1; |
390 } | 389 } |
391 arglen = SDL_strlen (arg) + 1; | 390 arglen = SDL_strlen(arg) + 1; |
392 len -= arglen; | 391 len -= arglen; |
393 arg += arglen; | 392 arg += arglen; |
394 } | 393 } |
395 close (cmdline); | 394 close(cmdline); |
396 } | 395 } |
397 } | 396 } |
398 closedir (proc); | 397 closedir(proc); |
399 } | 398 } |
400 return available; | 399 return available; |
401 } | 400 } |
402 | 401 |
403 | 402 |
405 * us access to the mousewheel, etc. Returns zero if | 404 * us access to the mousewheel, etc. Returns zero if |
406 * writes to device failed, but you still need to query the | 405 * writes to device failed, but you still need to query the |
407 * device to see which mode it's actually in. | 406 * device to see which mode it's actually in. |
408 */ | 407 */ |
409 static int | 408 static int |
410 set_imps2_mode (int fd) | 409 set_imps2_mode(int fd) |
411 { | 410 { |
412 /* If you wanted to control the mouse mode (and we do :) ) ... | 411 /* If you wanted to control the mouse mode (and we do :) ) ... |
413 Set IMPS/2 protocol: | 412 Set IMPS/2 protocol: |
414 {0xf3,200,0xf3,100,0xf3,80} | 413 {0xf3,200,0xf3,100,0xf3,80} |
415 Reset mouse device: | 414 Reset mouse device: |
419 Uint8 reset = 0xff; | 418 Uint8 reset = 0xff; |
420 fd_set fdset; | 419 fd_set fdset; |
421 struct timeval tv; | 420 struct timeval tv; |
422 int retval = 0; | 421 int retval = 0; |
423 | 422 |
424 if (write (fd, &set_imps2, sizeof (set_imps2)) == sizeof (set_imps2)) { | 423 if (write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2)) { |
425 if (write (fd, &reset, sizeof (reset)) == sizeof (reset)) { | 424 if (write(fd, &reset, sizeof(reset)) == sizeof(reset)) { |
426 retval = 1; | 425 retval = 1; |
427 } | 426 } |
428 } | 427 } |
429 | 428 |
430 /* Get rid of any chatter from the above */ | 429 /* Get rid of any chatter from the above */ |
431 FD_ZERO (&fdset); | 430 FD_ZERO(&fdset); |
432 FD_SET (fd, &fdset); | 431 FD_SET(fd, &fdset); |
433 tv.tv_sec = 0; | 432 tv.tv_sec = 0; |
434 tv.tv_usec = 0; | 433 tv.tv_usec = 0; |
435 while (select (fd + 1, &fdset, 0, 0, &tv) > 0) { | 434 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
436 char temp[32]; | 435 char temp[32]; |
437 read (fd, temp, sizeof (temp)); | 436 read(fd, temp, sizeof(temp)); |
438 } | 437 } |
439 | 438 |
440 return retval; | 439 return retval; |
441 } | 440 } |
442 | 441 |
443 | 442 |
444 /* Returns true if the mouse uses the IMPS/2 protocol */ | 443 /* Returns true if the mouse uses the IMPS/2 protocol */ |
445 static int | 444 static int |
446 detect_imps2 (int fd) | 445 detect_imps2(int fd) |
447 { | 446 { |
448 int imps2; | 447 int imps2; |
449 | 448 |
450 imps2 = 0; | 449 imps2 = 0; |
451 | 450 |
452 if (SDL_getenv ("SDL_MOUSEDEV_IMPS2")) { | 451 if (SDL_getenv("SDL_MOUSEDEV_IMPS2")) { |
453 imps2 = 1; | 452 imps2 = 1; |
454 } | 453 } |
455 if (!imps2) { | 454 if (!imps2) { |
456 Uint8 query_ps2 = 0xF2; | 455 Uint8 query_ps2 = 0xF2; |
457 fd_set fdset; | 456 fd_set fdset; |
458 struct timeval tv; | 457 struct timeval tv; |
459 | 458 |
460 /* Get rid of any mouse motion noise */ | 459 /* Get rid of any mouse motion noise */ |
461 FD_ZERO (&fdset); | 460 FD_ZERO(&fdset); |
462 FD_SET (fd, &fdset); | 461 FD_SET(fd, &fdset); |
463 tv.tv_sec = 0; | 462 tv.tv_sec = 0; |
464 tv.tv_usec = 0; | 463 tv.tv_usec = 0; |
465 while (select (fd + 1, &fdset, 0, 0, &tv) > 0) { | 464 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
466 char temp[32]; | 465 char temp[32]; |
467 read (fd, temp, sizeof (temp)); | 466 read(fd, temp, sizeof(temp)); |
468 } | 467 } |
469 | 468 |
470 /* Query for the type of mouse protocol */ | 469 /* Query for the type of mouse protocol */ |
471 if (write (fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { | 470 if (write(fd, &query_ps2, sizeof(query_ps2)) == sizeof(query_ps2)) { |
472 Uint8 ch = 0; | 471 Uint8 ch = 0; |
473 | 472 |
474 /* Get the mouse protocol response */ | 473 /* Get the mouse protocol response */ |
475 do { | 474 do { |
476 FD_ZERO (&fdset); | 475 FD_ZERO(&fdset); |
477 FD_SET (fd, &fdset); | 476 FD_SET(fd, &fdset); |
478 tv.tv_sec = 1; | 477 tv.tv_sec = 1; |
479 tv.tv_usec = 0; | 478 tv.tv_usec = 0; |
480 if (select (fd + 1, &fdset, 0, 0, &tv) < 1) { | 479 if (select(fd + 1, &fdset, 0, 0, &tv) < 1) { |
481 break; | 480 break; |
482 } | 481 } |
483 } | 482 } |
484 while ((read (fd, &ch, sizeof (ch)) == sizeof (ch)) && | 483 while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && |
485 ((ch == 0xFA) || (ch == 0xAA))); | 484 ((ch == 0xFA) || (ch == 0xAA))); |
486 | 485 |
487 /* Experimental values (Logitech wheelmouse) */ | 486 /* Experimental values (Logitech wheelmouse) */ |
488 #ifdef DEBUG_MOUSE | 487 #ifdef DEBUG_MOUSE |
489 fprintf (stderr, "Last mouse mode: 0x%x\n", ch); | 488 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); |
490 #endif | 489 #endif |
491 if (ch == 3) { | 490 if (ch == 3) { |
492 imps2 = 1; | 491 imps2 = 1; |
493 } | 492 } |
494 } | 493 } |
495 } | 494 } |
496 return imps2; | 495 return imps2; |
497 } | 496 } |
498 | 497 |
499 int | 498 int |
500 GS_OpenMouse (_THIS) | 499 GS_OpenMouse(_THIS) |
501 { | 500 { |
502 int i; | 501 int i; |
503 const char *mousedev; | 502 const char *mousedev; |
504 const char *mousedrv; | 503 const char *mousedrv; |
505 | 504 |
506 mousedrv = SDL_getenv ("SDL_MOUSEDRV"); | 505 mousedrv = SDL_getenv("SDL_MOUSEDRV"); |
507 mousedev = SDL_getenv ("SDL_MOUSEDEV"); | 506 mousedev = SDL_getenv("SDL_MOUSEDEV"); |
508 mouse_fd = -1; | 507 mouse_fd = -1; |
509 | 508 |
510 /* STD MICE */ | 509 /* STD MICE */ |
511 | 510 |
512 if (mousedev == NULL) { | 511 if (mousedev == NULL) { |
514 char *ps2mice[] = { | 513 char *ps2mice[] = { |
515 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL | 514 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL |
516 }; | 515 }; |
517 /* First try to use GPM in repeater mode */ | 516 /* First try to use GPM in repeater mode */ |
518 if (mouse_fd < 0) { | 517 if (mouse_fd < 0) { |
519 if (gpm_available ()) { | 518 if (gpm_available()) { |
520 mouse_fd = open (GPM_NODE_FIFO, O_RDONLY, 0); | 519 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); |
521 if (mouse_fd >= 0) { | 520 if (mouse_fd >= 0) { |
522 #ifdef DEBUG_MOUSE | 521 #ifdef DEBUG_MOUSE |
523 fprintf (stderr, "Using GPM mouse\n"); | 522 fprintf(stderr, "Using GPM mouse\n"); |
524 #endif | 523 #endif |
525 mouse_drv = MOUSE_GPM; | 524 mouse_drv = MOUSE_GPM; |
526 } | 525 } |
527 } | 526 } |
528 } | 527 } |
529 /* Now try to use a modern PS/2 mouse */ | 528 /* Now try to use a modern PS/2 mouse */ |
530 for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) { | 529 for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) { |
531 mouse_fd = open (ps2mice[i], O_RDWR, 0); | 530 mouse_fd = open(ps2mice[i], O_RDWR, 0); |
532 if (mouse_fd < 0) { | 531 if (mouse_fd < 0) { |
533 mouse_fd = open (ps2mice[i], O_RDONLY, 0); | 532 mouse_fd = open(ps2mice[i], O_RDONLY, 0); |
534 } | 533 } |
535 if (mouse_fd >= 0) { | 534 if (mouse_fd >= 0) { |
536 /* rcg06112001 Attempt to set IMPS/2 mode */ | 535 /* rcg06112001 Attempt to set IMPS/2 mode */ |
537 if (i == 0) { | 536 if (i == 0) { |
538 set_imps2_mode (mouse_fd); | 537 set_imps2_mode(mouse_fd); |
539 } | 538 } |
540 if (detect_imps2 (mouse_fd)) { | 539 if (detect_imps2(mouse_fd)) { |
541 #ifdef DEBUG_MOUSE | 540 #ifdef DEBUG_MOUSE |
542 fprintf (stderr, "Using IMPS2 mouse\n"); | 541 fprintf(stderr, "Using IMPS2 mouse\n"); |
543 #endif | 542 #endif |
544 mouse_drv = MOUSE_IMPS2; | 543 mouse_drv = MOUSE_IMPS2; |
545 } else { | 544 } else { |
546 mouse_drv = MOUSE_PS2; | 545 mouse_drv = MOUSE_PS2; |
547 #ifdef DEBUG_MOUSE | 546 #ifdef DEBUG_MOUSE |
548 fprintf (stderr, "Using PS2 mouse\n"); | 547 fprintf(stderr, "Using PS2 mouse\n"); |
549 #endif | 548 #endif |
550 } | 549 } |
551 } | 550 } |
552 } | 551 } |
553 /* Next try to use a PPC ADB port mouse */ | 552 /* Next try to use a PPC ADB port mouse */ |
554 if (mouse_fd < 0) { | 553 if (mouse_fd < 0) { |
555 mouse_fd = open ("/dev/adbmouse", O_RDONLY, 0); | 554 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); |
556 if (mouse_fd >= 0) { | 555 if (mouse_fd >= 0) { |
557 #ifdef DEBUG_MOUSE | 556 #ifdef DEBUG_MOUSE |
558 fprintf (stderr, "Using ADB mouse\n"); | 557 fprintf(stderr, "Using ADB mouse\n"); |
559 #endif | 558 #endif |
560 mouse_drv = MOUSE_BM; | 559 mouse_drv = MOUSE_BM; |
561 } | 560 } |
562 } | 561 } |
563 } | 562 } |
564 /* Default to a serial Microsoft mouse */ | 563 /* Default to a serial Microsoft mouse */ |
565 if (mouse_fd < 0) { | 564 if (mouse_fd < 0) { |
566 if (mousedev == NULL) { | 565 if (mousedev == NULL) { |
567 mousedev = "/dev/mouse"; | 566 mousedev = "/dev/mouse"; |
568 } | 567 } |
569 mouse_fd = open (mousedev, O_RDONLY, 0); | 568 mouse_fd = open(mousedev, O_RDONLY, 0); |
570 if (mouse_fd >= 0) { | 569 if (mouse_fd >= 0) { |
571 struct termios mouse_termios; | 570 struct termios mouse_termios; |
572 | 571 |
573 /* Set the sampling speed to 1200 baud */ | 572 /* Set the sampling speed to 1200 baud */ |
574 tcgetattr (mouse_fd, &mouse_termios); | 573 tcgetattr(mouse_fd, &mouse_termios); |
575 mouse_termios.c_iflag = IGNBRK | IGNPAR; | 574 mouse_termios.c_iflag = IGNBRK | IGNPAR; |
576 mouse_termios.c_oflag = 0; | 575 mouse_termios.c_oflag = 0; |
577 mouse_termios.c_lflag = 0; | 576 mouse_termios.c_lflag = 0; |
578 mouse_termios.c_line = 0; | 577 mouse_termios.c_line = 0; |
579 mouse_termios.c_cc[VTIME] = 0; | 578 mouse_termios.c_cc[VTIME] = 0; |
580 mouse_termios.c_cc[VMIN] = 1; | 579 mouse_termios.c_cc[VMIN] = 1; |
581 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; | 580 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; |
582 mouse_termios.c_cflag |= CS8; | 581 mouse_termios.c_cflag |= CS8; |
583 mouse_termios.c_cflag |= B1200; | 582 mouse_termios.c_cflag |= B1200; |
584 tcsetattr (mouse_fd, TCSAFLUSH, &mouse_termios); | 583 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); |
585 #ifdef DEBUG_MOUSE | 584 #ifdef DEBUG_MOUSE |
586 fprintf (stderr, "Using Microsoft mouse on %s\n", mousedev); | 585 fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev); |
587 #endif | 586 #endif |
588 mouse_drv = MOUSE_MS; | 587 mouse_drv = MOUSE_MS; |
589 } | 588 } |
590 } | 589 } |
591 if (mouse_fd < 0) { | 590 if (mouse_fd < 0) { |
595 } | 594 } |
596 | 595 |
597 static int posted = 0; | 596 static int posted = 0; |
598 | 597 |
599 void | 598 void |
600 GS_vgamousecallback (int button, int dx, int dy) | 599 GS_vgamousecallback(int button, int dx, int dy) |
601 { | 600 { |
602 int button_1, button_3; | 601 int button_1, button_3; |
603 int button_state; | 602 int button_state; |
604 int state_changed; | 603 int state_changed; |
605 int i; | 604 int i; |
606 Uint8 state; | 605 Uint8 state; |
607 | 606 |
608 if (dx || dy) { | 607 if (dx || dy) { |
609 posted += SDL_PrivateMouseMotion (0, 1, dx, dy); | 608 posted += SDL_PrivateMouseMotion(0, 1, dx, dy); |
610 } | 609 } |
611 | 610 |
612 /* Swap button 1 and 3 */ | 611 /* Swap button 1 and 3 */ |
613 button_1 = (button & 0x04) >> 2; | 612 button_1 = (button & 0x04) >> 2; |
614 button_3 = (button & 0x01) << 2; | 613 button_3 = (button & 0x01) << 2; |
615 button &= ~0x05; | 614 button &= ~0x05; |
616 button |= (button_1 | button_3); | 615 button |= (button_1 | button_3); |
617 | 616 |
618 /* See what changed */ | 617 /* See what changed */ |
619 button_state = SDL_GetMouseState (NULL, NULL); | 618 button_state = SDL_GetMouseState(NULL, NULL); |
620 state_changed = button_state ^ button; | 619 state_changed = button_state ^ button; |
621 for (i = 0; i < 8; ++i) { | 620 for (i = 0; i < 8; ++i) { |
622 if (state_changed & (1 << i)) { | 621 if (state_changed & (1 << i)) { |
623 if (button & (1 << i)) { | 622 if (button & (1 << i)) { |
624 state = SDL_PRESSED; | 623 state = SDL_PRESSED; |
625 } else { | 624 } else { |
626 state = SDL_RELEASED; | 625 state = SDL_RELEASED; |
627 } | 626 } |
628 posted += SDL_PrivateMouseButton (state, i + 1, 0, 0); | 627 posted += SDL_PrivateMouseButton(state, i + 1, 0, 0); |
629 } | 628 } |
630 } | 629 } |
631 } | 630 } |
632 | 631 |
633 /* For now, use GPM, PS/2, and MS protocols | 632 /* For now, use GPM, PS/2, and MS protocols |
634 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) | 633 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) |
635 */ | 634 */ |
636 static void | 635 static void |
637 handle_mouse (_THIS) | 636 handle_mouse(_THIS) |
638 { | 637 { |
639 static int start = 0; | 638 static int start = 0; |
640 static unsigned char mousebuf[BUFSIZ]; | 639 static unsigned char mousebuf[BUFSIZ]; |
641 int i, nread; | 640 int i, nread; |
642 int button = 0; | 641 int button = 0; |
645 | 644 |
646 /* Figure out the mouse packet size */ | 645 /* Figure out the mouse packet size */ |
647 switch (mouse_drv) { | 646 switch (mouse_drv) { |
648 case MOUSE_NONE: | 647 case MOUSE_NONE: |
649 /* Ack! */ | 648 /* Ack! */ |
650 read (mouse_fd, mousebuf, BUFSIZ); | 649 read(mouse_fd, mousebuf, BUFSIZ); |
651 return; | 650 return; |
652 case MOUSE_GPM: | 651 case MOUSE_GPM: |
653 packetsize = 5; | 652 packetsize = 5; |
654 break; | 653 break; |
655 case MOUSE_IMPS2: | 654 case MOUSE_IMPS2: |
665 packetsize = 0; | 664 packetsize = 0; |
666 break; | 665 break; |
667 } | 666 } |
668 | 667 |
669 /* Read as many packets as possible */ | 668 /* Read as many packets as possible */ |
670 nread = read (mouse_fd, &mousebuf[start], BUFSIZ - start); | 669 nread = read(mouse_fd, &mousebuf[start], BUFSIZ - start); |
671 if (nread < 0) { | 670 if (nread < 0) { |
672 return; | 671 return; |
673 } | 672 } |
674 nread += start; | 673 nread += start; |
675 #ifdef DEBUG_MOUSE | 674 #ifdef DEBUG_MOUSE |
676 fprintf (stderr, "Read %d bytes from mouse, start = %d\n", nread, start); | 675 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start); |
677 #endif | 676 #endif |
678 for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) { | 677 for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) { |
679 switch (mouse_drv) { | 678 switch (mouse_drv) { |
680 case MOUSE_NONE: | 679 case MOUSE_NONE: |
681 break; | 680 break; |
723 switch (mousebuf[i + 3] & 0x0F) { | 722 switch (mousebuf[i + 3] & 0x0F) { |
724 case 0x0E: /* DX = +1 */ | 723 case 0x0E: /* DX = +1 */ |
725 case 0x02: /* DX = -1 */ | 724 case 0x02: /* DX = -1 */ |
726 break; | 725 break; |
727 case 0x0F: /* DY = +1 (map button 4) */ | 726 case 0x0F: /* DY = +1 (map button 4) */ |
728 FB_vgamousecallback (button | (1 << 3), 1, 0, 0); | 727 FB_vgamousecallback(button | (1 << 3), 1, 0, 0); |
729 break; | 728 break; |
730 case 0x01: /* DY = -1 (map button 5) */ | 729 case 0x01: /* DY = -1 (map button 5) */ |
731 FB_vgamousecallback (button | (1 << 4), 1, 0, 0); | 730 FB_vgamousecallback(button | (1 << 4), 1, 0, 0); |
732 break; | 731 break; |
733 } | 732 } |
734 break; | 733 break; |
735 case MOUSE_MS: | 734 case MOUSE_MS: |
736 /* Microsoft protocol has 0x40 in high byte */ | 735 /* Microsoft protocol has 0x40 in high byte */ |
763 /* Uh oh.. */ | 762 /* Uh oh.. */ |
764 dx = 0; | 763 dx = 0; |
765 dy = 0; | 764 dy = 0; |
766 break; | 765 break; |
767 } | 766 } |
768 GS_vgamousecallback (button, dx, dy); | 767 GS_vgamousecallback(button, dx, dy); |
769 } | 768 } |
770 if (i < nread) { | 769 if (i < nread) { |
771 SDL_memcpy (mousebuf, &mousebuf[i], (nread - i)); | 770 SDL_memcpy(mousebuf, &mousebuf[i], (nread - i)); |
772 start = (nread - i); | 771 start = (nread - i); |
773 } else { | 772 } else { |
774 start = 0; | 773 start = 0; |
775 } | 774 } |
776 return; | 775 return; |
777 } | 776 } |
778 | 777 |
779 static void | 778 static void |
780 handle_keyboard (_THIS) | 779 handle_keyboard(_THIS) |
781 { | 780 { |
782 unsigned char keybuf[BUFSIZ]; | 781 unsigned char keybuf[BUFSIZ]; |
783 int i, nread; | 782 int i, nread; |
784 int pressed; | 783 int pressed; |
785 int scancode; | 784 int scancode; |
786 SDL_keysym keysym; | 785 SDL_keysym keysym; |
787 | 786 |
788 nread = read (keyboard_fd, keybuf, BUFSIZ); | 787 nread = read(keyboard_fd, keybuf, BUFSIZ); |
789 for (i = 0; i < nread; ++i) { | 788 for (i = 0; i < nread; ++i) { |
790 scancode = keybuf[i] & 0x7F; | 789 scancode = keybuf[i] & 0x7F; |
791 if (keybuf[i] & 0x80) { | 790 if (keybuf[i] & 0x80) { |
792 pressed = SDL_RELEASED; | 791 pressed = SDL_RELEASED; |
793 } else { | 792 } else { |
794 pressed = SDL_PRESSED; | 793 pressed = SDL_PRESSED; |
795 } | 794 } |
796 TranslateKey (scancode, &keysym); | 795 TranslateKey(scancode, &keysym); |
797 posted += SDL_PrivateKeyboard (pressed, &keysym); | 796 posted += SDL_PrivateKeyboard(pressed, &keysym); |
798 } | 797 } |
799 } | 798 } |
800 | 799 |
801 void | 800 void |
802 GS_PumpEvents (_THIS) | 801 GS_PumpEvents(_THIS) |
803 { | 802 { |
804 fd_set fdset; | 803 fd_set fdset; |
805 int max_fd; | 804 int max_fd; |
806 static struct timeval zero; | 805 static struct timeval zero; |
807 | 806 |
808 do { | 807 do { |
809 posted = 0; | 808 posted = 0; |
810 | 809 |
811 FD_ZERO (&fdset); | 810 FD_ZERO(&fdset); |
812 max_fd = 0; | 811 max_fd = 0; |
813 if (keyboard_fd >= 0) { | 812 if (keyboard_fd >= 0) { |
814 FD_SET (keyboard_fd, &fdset); | 813 FD_SET(keyboard_fd, &fdset); |
815 if (max_fd < keyboard_fd) { | 814 if (max_fd < keyboard_fd) { |
816 max_fd = keyboard_fd; | 815 max_fd = keyboard_fd; |
817 } | 816 } |
818 } | 817 } |
819 if (mouse_fd >= 0) { | 818 if (mouse_fd >= 0) { |
820 FD_SET (mouse_fd, &fdset); | 819 FD_SET(mouse_fd, &fdset); |
821 if (max_fd < mouse_fd) { | 820 if (max_fd < mouse_fd) { |
822 max_fd = mouse_fd; | 821 max_fd = mouse_fd; |
823 } | 822 } |
824 } | 823 } |
825 if (select (max_fd + 1, &fdset, NULL, NULL, &zero) > 0) { | 824 if (select(max_fd + 1, &fdset, NULL, NULL, &zero) > 0) { |
826 if (keyboard_fd >= 0) { | 825 if (keyboard_fd >= 0) { |
827 if (FD_ISSET (keyboard_fd, &fdset)) { | 826 if (FD_ISSET(keyboard_fd, &fdset)) { |
828 handle_keyboard (this); | 827 handle_keyboard(this); |
829 } | 828 } |
830 } | 829 } |
831 if (mouse_fd >= 0) { | 830 if (mouse_fd >= 0) { |
832 if (FD_ISSET (mouse_fd, &fdset)) { | 831 if (FD_ISSET(mouse_fd, &fdset)) { |
833 handle_mouse (this); | 832 handle_mouse(this); |
834 } | 833 } |
835 } | 834 } |
836 } | 835 } |
837 } | 836 } |
838 while (posted); | 837 while (posted); |
839 } | 838 } |
840 | 839 |
841 void | 840 void |
842 GS_InitOSKeymap (_THIS) | 841 GS_InitOSKeymap(_THIS) |
843 { | 842 { |
844 int i; | 843 int i; |
845 | 844 |
846 /* Initialize the Linux key translation table */ | 845 /* Initialize the Linux key translation table */ |
847 | 846 |
848 /* First get the ascii keys and others not well handled */ | 847 /* First get the ascii keys and others not well handled */ |
849 for (i = 0; i < SDL_arraysize (keymap); ++i) { | 848 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
850 switch (i) { | 849 switch (i) { |
851 /* These aren't handled by the x86 kernel keymapping (?) */ | 850 /* These aren't handled by the x86 kernel keymapping (?) */ |
852 case SCANCODE_PRINTSCREEN: | 851 case SCANCODE_PRINTSCREEN: |
853 keymap[i] = SDLK_PRINT; | 852 keymap[i] = SDLK_PRINT; |
854 break; | 853 break; |
879 case 127: | 878 case 127: |
880 keymap[i] = SDLK_MENU; | 879 keymap[i] = SDLK_MENU; |
881 break; | 880 break; |
882 /* this should take care of all standard ascii keys */ | 881 /* this should take care of all standard ascii keys */ |
883 default: | 882 default: |
884 keymap[i] = KVAL (vga_keymap[0][i]); | 883 keymap[i] = KVAL(vga_keymap[0][i]); |
885 break; | 884 break; |
886 } | 885 } |
887 } | 886 } |
888 for (i = 0; i < SDL_arraysize (keymap); ++i) { | 887 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
889 switch (keymap_temp[i]) { | 888 switch (keymap_temp[i]) { |
890 case K_F1: | 889 case K_F1: |
891 keymap[i] = SDLK_F1; | 890 keymap[i] = SDLK_F1; |
892 break; | 891 break; |
893 case K_F2: | 892 case K_F2: |
1058 } | 1057 } |
1059 } | 1058 } |
1060 } | 1059 } |
1061 | 1060 |
1062 static SDL_keysym * | 1061 static SDL_keysym * |
1063 TranslateKey (int scancode, SDL_keysym * keysym) | 1062 TranslateKey(int scancode, SDL_keysym * keysym) |
1064 { | 1063 { |
1065 /* Set the keysym information */ | 1064 /* Set the keysym information */ |
1066 keysym->scancode = scancode; | 1065 keysym->scancode = scancode; |
1067 keysym->sym = keymap[scancode]; | 1066 keysym->sym = keymap[scancode]; |
1068 keysym->mod = KMOD_NONE; | 1067 keysym->mod = KMOD_NONE; |
1071 keysym->unicode = 0; | 1070 keysym->unicode = 0; |
1072 if (SDL_TranslateUNICODE) { | 1071 if (SDL_TranslateUNICODE) { |
1073 int map; | 1072 int map; |
1074 SDLMod modstate; | 1073 SDLMod modstate; |
1075 | 1074 |
1076 modstate = SDL_GetModState (); | 1075 modstate = SDL_GetModState(); |
1077 map = 0; | 1076 map = 0; |
1078 if (modstate & KMOD_SHIFT) { | 1077 if (modstate & KMOD_SHIFT) { |
1079 map |= (1 << KG_SHIFT); | 1078 map |= (1 << KG_SHIFT); |
1080 } | 1079 } |
1081 if (modstate & KMOD_CTRL) { | 1080 if (modstate & KMOD_CTRL) { |
1085 map |= (1 << KG_ALT); | 1084 map |= (1 << KG_ALT); |
1086 } | 1085 } |
1087 if (modstate & KMOD_MODE) { | 1086 if (modstate & KMOD_MODE) { |
1088 map |= (1 << KG_ALTGR); | 1087 map |= (1 << KG_ALTGR); |
1089 } | 1088 } |
1090 if (KTYP (vga_keymap[map][scancode]) == KT_LETTER) { | 1089 if (KTYP(vga_keymap[map][scancode]) == KT_LETTER) { |
1091 if (modstate & KMOD_CAPS) { | 1090 if (modstate & KMOD_CAPS) { |
1092 map ^= (1 << KG_SHIFT); | 1091 map ^= (1 << KG_SHIFT); |
1093 } | 1092 } |
1094 } | 1093 } |
1095 if (KTYP (vga_keymap[map][scancode]) == KT_PAD) { | 1094 if (KTYP(vga_keymap[map][scancode]) == KT_PAD) { |
1096 if (modstate & KMOD_NUM) { | 1095 if (modstate & KMOD_NUM) { |
1097 keysym->unicode = KVAL (vga_keymap[map][scancode]); | 1096 keysym->unicode = KVAL(vga_keymap[map][scancode]); |
1098 } | 1097 } |
1099 } else { | 1098 } else { |
1100 keysym->unicode = KVAL (vga_keymap[map][scancode]); | 1099 keysym->unicode = KVAL(vga_keymap[map][scancode]); |
1101 } | 1100 } |
1102 } | 1101 } |
1103 return (keysym); | 1102 return (keysym); |
1104 } | 1103 } |
1105 | 1104 |