Mercurial > sdl-ios-xcode
comparison src/video/ps2gs/SDL_gsevents.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | d910939febfa |
children | e27bdcc80744 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
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 GS_vgainitkeymaps(int fd) | 66 static void |
67 { | 67 GS_vgainitkeymaps(int fd) |
68 struct kbentry entry; | 68 { |
69 int map, i; | 69 struct kbentry entry; |
70 | 70 int map, i; |
71 /* Don't do anything if we are passed a closed keyboard */ | 71 |
72 if ( fd < 0 ) { | 72 /* Don't do anything if we are passed a closed keyboard */ |
73 return; | 73 if (fd < 0) { |
74 } | 74 return; |
75 | 75 } |
76 /* Load all the keysym mappings */ | 76 |
77 for ( map=0; map<NUM_VGAKEYMAPS; ++map ) { | 77 /* Load all the keysym mappings */ |
78 SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16)); | 78 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { |
79 for ( i=0; i<NR_KEYS; ++i ) { | 79 SDL_memset(vga_keymap[map], 0, NR_KEYS * sizeof(Uint16)); |
80 entry.kb_table = map; | 80 for (i = 0; i < NR_KEYS; ++i) { |
81 entry.kb_index = i; | 81 entry.kb_table = map; |
82 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) { | 82 entry.kb_index = i; |
83 /* fill keytemp. This replaces SDL_fbkeys.h */ | 83 if (ioctl(fd, KDGKBENT, &entry) == 0) { |
84 if ( (map == 0) && (i<128) ) { | 84 /* fill keytemp. This replaces SDL_fbkeys.h */ |
85 keymap_temp[i] = entry.kb_value; | 85 if ((map == 0) && (i < 128)) { |
86 } | 86 keymap_temp[i] = entry.kb_value; |
87 /* The "Enter" key is a special case */ | 87 } |
88 if ( entry.kb_value == K_ENTER ) { | 88 /* The "Enter" key is a special case */ |
89 entry.kb_value = K(KT_ASCII,13); | 89 if (entry.kb_value == K_ENTER) { |
90 } | 90 entry.kb_value = K(KT_ASCII, 13); |
91 /* Handle numpad specially as well */ | 91 } |
92 if ( KTYP(entry.kb_value) == KT_PAD ) { | 92 /* Handle numpad specially as well */ |
93 switch ( entry.kb_value ) { | 93 if (KTYP(entry.kb_value) == KT_PAD) { |
94 case K_P0: | 94 switch (entry.kb_value) { |
95 case K_P1: | 95 case K_P0: |
96 case K_P2: | 96 case K_P1: |
97 case K_P3: | 97 case K_P2: |
98 case K_P4: | 98 case K_P3: |
99 case K_P5: | 99 case K_P4: |
100 case K_P6: | 100 case K_P5: |
101 case K_P7: | 101 case K_P6: |
102 case K_P8: | 102 case K_P7: |
103 case K_P9: | 103 case K_P8: |
104 vga_keymap[map][i]=entry.kb_value; | 104 case K_P9: |
105 vga_keymap[map][i]+= '0'; | 105 vga_keymap[map][i] = entry.kb_value; |
106 break; | 106 vga_keymap[map][i] += '0'; |
107 case K_PPLUS: | 107 break; |
108 vga_keymap[map][i]=K(KT_ASCII,'+'); | 108 case K_PPLUS: |
109 break; | 109 vga_keymap[map][i] = K(KT_ASCII, '+'); |
110 case K_PMINUS: | 110 break; |
111 vga_keymap[map][i]=K(KT_ASCII,'-'); | 111 case K_PMINUS: |
112 break; | 112 vga_keymap[map][i] = K(KT_ASCII, '-'); |
113 case K_PSTAR: | 113 break; |
114 vga_keymap[map][i]=K(KT_ASCII,'*'); | 114 case K_PSTAR: |
115 break; | 115 vga_keymap[map][i] = K(KT_ASCII, '*'); |
116 case K_PSLASH: | 116 break; |
117 vga_keymap[map][i]=K(KT_ASCII,'/'); | 117 case K_PSLASH: |
118 break; | 118 vga_keymap[map][i] = K(KT_ASCII, '/'); |
119 case K_PENTER: | 119 break; |
120 vga_keymap[map][i]=K(KT_ASCII,'\r'); | 120 case K_PENTER: |
121 break; | 121 vga_keymap[map][i] = K(KT_ASCII, '\r'); |
122 case K_PCOMMA: | 122 break; |
123 vga_keymap[map][i]=K(KT_ASCII,','); | 123 case K_PCOMMA: |
124 break; | 124 vga_keymap[map][i] = K(KT_ASCII, ','); |
125 case K_PDOT: | 125 break; |
126 vga_keymap[map][i]=K(KT_ASCII,'.'); | 126 case K_PDOT: |
127 break; | 127 vga_keymap[map][i] = K(KT_ASCII, '.'); |
128 default: | 128 break; |
129 break; | 129 default: |
130 } | 130 break; |
131 } | 131 } |
132 /* Do the normal key translation */ | 132 } |
133 if ( (KTYP(entry.kb_value) == KT_LATIN) || | 133 /* Do the normal key translation */ |
134 (KTYP(entry.kb_value) == KT_ASCII) || | 134 if ((KTYP(entry.kb_value) == KT_LATIN) || |
135 (KTYP(entry.kb_value) == KT_LETTER) ) { | 135 (KTYP(entry.kb_value) == KT_ASCII) || |
136 vga_keymap[map][i] = entry.kb_value; | 136 (KTYP(entry.kb_value) == KT_LETTER)) { |
137 } | 137 vga_keymap[map][i] = entry.kb_value; |
138 } | 138 } |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 } |
143 int GS_InGraphicsMode(_THIS) | 143 |
144 { | 144 int |
145 return((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); | 145 GS_InGraphicsMode(_THIS) |
146 } | 146 { |
147 | 147 return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); |
148 int GS_EnterGraphicsMode(_THIS) | 148 } |
149 { | 149 |
150 struct termios keyboard_termios; | 150 int |
151 | 151 GS_EnterGraphicsMode(_THIS) |
152 /* Set medium-raw keyboard mode */ | 152 { |
153 if ( (keyboard_fd >= 0) && !GS_InGraphicsMode(this) ) { | 153 struct termios keyboard_termios; |
154 | 154 |
155 /* Switch to the correct virtual terminal */ | 155 /* Set medium-raw keyboard mode */ |
156 if ( current_vt > 0 ) { | 156 if ((keyboard_fd >= 0) && !GS_InGraphicsMode(this)) { |
157 struct vt_stat vtstate; | 157 |
158 | 158 /* Switch to the correct virtual terminal */ |
159 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) { | 159 if (current_vt > 0) { |
160 saved_vt = vtstate.v_active; | 160 struct vt_stat vtstate; |
161 } | 161 |
162 if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) { | 162 if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) { |
163 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); | 163 saved_vt = vtstate.v_active; |
164 } | 164 } |
165 } | 165 if (ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0) { |
166 | 166 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); |
167 /* Set the terminal input mode */ | 167 } |
168 if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) { | 168 } |
169 SDL_SetError("Unable to get terminal attributes"); | 169 |
170 if ( keyboard_fd > 0 ) { | 170 /* Set the terminal input mode */ |
171 close(keyboard_fd); | 171 if (tcgetattr(keyboard_fd, &saved_kbd_termios) < 0) { |
172 } | 172 SDL_SetError("Unable to get terminal attributes"); |
173 keyboard_fd = -1; | 173 if (keyboard_fd > 0) { |
174 return(-1); | 174 close(keyboard_fd); |
175 } | 175 } |
176 if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) { | 176 keyboard_fd = -1; |
177 SDL_SetError("Unable to get current keyboard mode"); | 177 return (-1); |
178 if ( keyboard_fd > 0 ) { | 178 } |
179 close(keyboard_fd); | 179 if (ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) { |
180 } | 180 SDL_SetError("Unable to get current keyboard mode"); |
181 keyboard_fd = -1; | 181 if (keyboard_fd > 0) { |
182 return(-1); | 182 close(keyboard_fd); |
183 } | 183 } |
184 keyboard_termios = saved_kbd_termios; | 184 keyboard_fd = -1; |
185 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); | 185 return (-1); |
186 keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); | 186 } |
187 keyboard_termios.c_cc[VMIN] = 0; | 187 keyboard_termios = saved_kbd_termios; |
188 keyboard_termios.c_cc[VTIME] = 0; | 188 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); |
189 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { | 189 keyboard_termios.c_iflag &= |
190 GS_CloseKeyboard(this); | 190 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); |
191 SDL_SetError("Unable to set terminal attributes"); | 191 keyboard_termios.c_cc[VMIN] = 0; |
192 return(-1); | 192 keyboard_termios.c_cc[VTIME] = 0; |
193 } | 193 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { |
194 /* This will fail if we aren't root or this isn't our tty */ | 194 GS_CloseKeyboard(this); |
195 if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) { | 195 SDL_SetError("Unable to set terminal attributes"); |
196 GS_CloseKeyboard(this); | 196 return (-1); |
197 SDL_SetError("Unable to set keyboard in raw mode"); | 197 } |
198 return(-1); | 198 /* This will fail if we aren't root or this isn't our tty */ |
199 } | 199 if (ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) { |
200 if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) { | 200 GS_CloseKeyboard(this); |
201 GS_CloseKeyboard(this); | 201 SDL_SetError("Unable to set keyboard in raw mode"); |
202 SDL_SetError("Unable to set keyboard in graphics mode"); | 202 return (-1); |
203 return(-1); | 203 } |
204 } | 204 if (ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) { |
205 } | 205 GS_CloseKeyboard(this); |
206 return(keyboard_fd); | 206 SDL_SetError("Unable to set keyboard in graphics mode"); |
207 } | 207 return (-1); |
208 | 208 } |
209 void GS_LeaveGraphicsMode(_THIS) | 209 } |
210 { | 210 return (keyboard_fd); |
211 if ( GS_InGraphicsMode(this) ) { | 211 } |
212 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); | 212 |
213 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); | 213 void |
214 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); | 214 GS_LeaveGraphicsMode(_THIS) |
215 saved_kbd_mode = -1; | 215 { |
216 | 216 if (GS_InGraphicsMode(this)) { |
217 /* Head back over to the original virtual terminal */ | 217 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
218 if ( saved_vt > 0 ) { | 218 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); |
219 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); | 219 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); |
220 } | 220 saved_kbd_mode = -1; |
221 } | 221 |
222 } | 222 /* Head back over to the original virtual terminal */ |
223 | 223 if (saved_vt > 0) { |
224 void GS_CloseKeyboard(_THIS) | 224 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); |
225 { | 225 } |
226 if ( keyboard_fd >= 0 ) { | 226 } |
227 GS_LeaveGraphicsMode(this); | 227 } |
228 if ( keyboard_fd > 0 ) { | 228 |
229 close(keyboard_fd); | 229 void |
230 } | 230 GS_CloseKeyboard(_THIS) |
231 } | 231 { |
232 keyboard_fd = -1; | 232 if (keyboard_fd >= 0) { |
233 } | 233 GS_LeaveGraphicsMode(this); |
234 | 234 if (keyboard_fd > 0) { |
235 int GS_OpenKeyboard(_THIS) | 235 close(keyboard_fd); |
236 { | 236 } |
237 /* Open only if not already opened */ | 237 } |
238 if ( keyboard_fd < 0 ) { | 238 keyboard_fd = -1; |
239 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; | 239 } |
240 char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; | 240 |
241 int i, tty0_fd; | 241 int |
242 | 242 GS_OpenKeyboard(_THIS) |
243 /* Try to query for a free virtual terminal */ | 243 { |
244 tty0_fd = -1; | 244 /* Open only if not already opened */ |
245 for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) { | 245 if (keyboard_fd < 0) { |
246 tty0_fd = open(tty0[i], O_WRONLY, 0); | 246 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; |
247 } | 247 char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; |
248 if ( tty0_fd < 0 ) { | 248 int i, tty0_fd; |
249 tty0_fd = dup(0); /* Maybe stdin is a VT? */ | 249 |
250 } | 250 /* Try to query for a free virtual terminal */ |
251 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); | 251 tty0_fd = -1; |
252 close(tty0_fd); | 252 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { |
253 if ( (geteuid() == 0) && (current_vt > 0) ) { | 253 tty0_fd = open(tty0[i], O_WRONLY, 0); |
254 for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) { | 254 } |
255 char vtpath[12]; | 255 if (tty0_fd < 0) { |
256 | 256 tty0_fd = dup(0); /* Maybe stdin is a VT? */ |
257 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt); | 257 } |
258 keyboard_fd = open(vtpath, O_RDWR, 0); | 258 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); |
259 close(tty0_fd); | |
260 if ((geteuid() == 0) && (current_vt > 0)) { | |
261 for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) { | |
262 char vtpath[12]; | |
263 | |
264 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], | |
265 current_vt); | |
266 keyboard_fd = open(vtpath, O_RDWR, 0); | |
259 #ifdef DEBUG_KEYBOARD | 267 #ifdef DEBUG_KEYBOARD |
260 fprintf(stderr, "vtpath = %s, fd = %d\n", | 268 fprintf(stderr, "vtpath = %s, fd = %d\n", |
261 vtpath, keyboard_fd); | 269 vtpath, keyboard_fd); |
262 #endif /* DEBUG_KEYBOARD */ | 270 #endif /* DEBUG_KEYBOARD */ |
263 | 271 |
264 /* This needs to be our controlling tty | 272 /* This needs to be our controlling tty |
265 so that the kernel ioctl() calls work | 273 so that the kernel ioctl() calls work |
266 */ | 274 */ |
267 if ( keyboard_fd >= 0 ) { | 275 if (keyboard_fd >= 0) { |
268 tty0_fd = open("/dev/tty", O_RDWR, 0); | 276 tty0_fd = open("/dev/tty", O_RDWR, 0); |
269 if ( tty0_fd >= 0 ) { | 277 if (tty0_fd >= 0) { |
270 ioctl(tty0_fd, TIOCNOTTY, 0); | 278 ioctl(tty0_fd, TIOCNOTTY, 0); |
271 close(tty0_fd); | 279 close(tty0_fd); |
272 } | 280 } |
273 } | 281 } |
274 } | 282 } |
275 } | 283 } |
276 if ( keyboard_fd < 0 ) { | 284 if (keyboard_fd < 0) { |
277 /* Last resort, maybe our tty is a usable VT */ | 285 /* Last resort, maybe our tty is a usable VT */ |
278 current_vt = 0; | 286 current_vt = 0; |
279 keyboard_fd = open("/dev/tty", O_RDWR); | 287 keyboard_fd = open("/dev/tty", O_RDWR); |
280 } | 288 } |
281 #ifdef DEBUG_KEYBOARD | 289 #ifdef DEBUG_KEYBOARD |
282 fprintf(stderr, "Current VT: %d\n", current_vt); | 290 fprintf(stderr, "Current VT: %d\n", current_vt); |
283 #endif | 291 #endif |
284 saved_kbd_mode = -1; | 292 saved_kbd_mode = -1; |
285 | 293 |
286 /* Make sure that our input is a console terminal */ | 294 /* Make sure that our input is a console terminal */ |
287 { int dummy; | 295 { |
288 if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) { | 296 int dummy; |
289 close(keyboard_fd); | 297 if (ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0) { |
290 keyboard_fd = -1; | 298 close(keyboard_fd); |
291 SDL_SetError("Unable to open a console terminal"); | 299 keyboard_fd = -1; |
292 } | 300 SDL_SetError("Unable to open a console terminal"); |
293 } | 301 } |
294 | 302 } |
295 /* Set up keymap */ | 303 |
296 GS_vgainitkeymaps(keyboard_fd); | 304 /* Set up keymap */ |
297 } | 305 GS_vgainitkeymaps(keyboard_fd); |
298 return(keyboard_fd); | 306 } |
299 } | 307 return (keyboard_fd); |
300 | 308 } |
301 static enum { | 309 |
302 MOUSE_NONE = -1, | 310 static enum |
303 MOUSE_GPM, /* Note: GPM uses the MSC protocol */ | 311 { |
304 MOUSE_PS2, | 312 MOUSE_NONE = -1, |
305 MOUSE_IMPS2, | 313 MOUSE_GPM, /* Note: GPM uses the MSC protocol */ |
306 MOUSE_MS, | 314 MOUSE_PS2, |
307 MOUSE_BM, | 315 MOUSE_IMPS2, |
308 NUM_MOUSE_DRVS | 316 MOUSE_MS, |
317 MOUSE_BM, | |
318 NUM_MOUSE_DRVS | |
309 } mouse_drv = MOUSE_NONE; | 319 } mouse_drv = MOUSE_NONE; |
310 | 320 |
311 void GS_CloseMouse(_THIS) | 321 void |
312 { | 322 GS_CloseMouse(_THIS) |
313 if ( mouse_fd > 0 ) { | 323 { |
314 close(mouse_fd); | 324 if (mouse_fd > 0) { |
315 } | 325 close(mouse_fd); |
316 mouse_fd = -1; | 326 } |
327 mouse_fd = -1; | |
317 } | 328 } |
318 | 329 |
319 /* Returns processes listed in /proc with the desired name */ | 330 /* Returns processes listed in /proc with the desired name */ |
320 static int find_pid(DIR *proc, const char *wanted_name) | 331 static int |
321 { | 332 find_pid(DIR * proc, const char *wanted_name) |
322 struct dirent *entry; | 333 { |
323 int pid; | 334 struct dirent *entry; |
324 | 335 int pid; |
325 /* First scan proc for the gpm process */ | 336 |
326 pid = 0; | 337 /* First scan proc for the gpm process */ |
327 while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) { | 338 pid = 0; |
328 if ( isdigit(entry->d_name[0]) ) { | 339 while ((pid == 0) && ((entry = readdir(proc)) != NULL)) { |
329 FILE *status; | 340 if (isdigit(entry->d_name[0])) { |
330 char path[PATH_MAX]; | 341 FILE *status; |
331 char name[PATH_MAX]; | 342 char path[PATH_MAX]; |
332 | 343 char name[PATH_MAX]; |
333 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name); | 344 |
334 status=fopen(path, "r"); | 345 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", |
335 if ( status ) { | 346 entry->d_name); |
336 name[0] = '\0'; | 347 status = fopen(path, "r"); |
337 fscanf(status, "Name: %s", name); | 348 if (status) { |
338 if ( SDL_strcmp(name, wanted_name) == 0 ) { | 349 name[0] = '\0'; |
339 pid = atoi(entry->d_name); | 350 fscanf(status, "Name: %s", name); |
340 } | 351 if (SDL_strcmp(name, wanted_name) == 0) { |
341 fclose(status); | 352 pid = atoi(entry->d_name); |
342 } | 353 } |
343 } | 354 fclose(status); |
344 } | 355 } |
345 return pid; | 356 } |
357 } | |
358 return pid; | |
346 } | 359 } |
347 | 360 |
348 /* Returns true if /dev/gpmdata is being written to by gpm */ | 361 /* Returns true if /dev/gpmdata is being written to by gpm */ |
349 static int gpm_available(void) | 362 static int |
350 { | 363 gpm_available(void) |
351 int available; | 364 { |
352 DIR *proc; | 365 int available; |
353 int pid; | 366 DIR *proc; |
354 int cmdline, len, arglen; | 367 int pid; |
355 char path[PATH_MAX]; | 368 int cmdline, len, arglen; |
356 char args[PATH_MAX], *arg; | 369 char path[PATH_MAX]; |
357 | 370 char args[PATH_MAX], *arg; |
358 /* Don't bother looking if the fifo isn't there */ | 371 |
359 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { | 372 /* Don't bother looking if the fifo isn't there */ |
360 return(0); | 373 if (access(GPM_NODE_FIFO, F_OK) < 0) { |
361 } | 374 return (0); |
362 | 375 } |
363 available = 0; | 376 |
364 proc = opendir("/proc"); | 377 available = 0; |
365 if ( proc ) { | 378 proc = opendir("/proc"); |
366 while ( (pid=find_pid(proc, "gpm")) > 0 ) { | 379 if (proc) { |
367 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); | 380 while ((pid = find_pid(proc, "gpm")) > 0) { |
368 cmdline = open(path, O_RDONLY, 0); | 381 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); |
369 if ( cmdline >= 0 ) { | 382 cmdline = open(path, O_RDONLY, 0); |
370 len = read(cmdline, args, sizeof(args)); | 383 if (cmdline >= 0) { |
371 arg = args; | 384 len = read(cmdline, args, sizeof(args)); |
372 while ( len > 0 ) { | 385 arg = args; |
373 if ( SDL_strcmp(arg, "-R") == 0 ) { | 386 while (len > 0) { |
374 available = 1; | 387 if (SDL_strcmp(arg, "-R") == 0) { |
375 } | 388 available = 1; |
376 arglen = SDL_strlen(arg)+1; | 389 } |
377 len -= arglen; | 390 arglen = SDL_strlen(arg) + 1; |
378 arg += arglen; | 391 len -= arglen; |
379 } | 392 arg += arglen; |
380 close(cmdline); | 393 } |
381 } | 394 close(cmdline); |
382 } | 395 } |
383 closedir(proc); | 396 } |
384 } | 397 closedir(proc); |
385 return available; | 398 } |
399 return available; | |
386 } | 400 } |
387 | 401 |
388 | 402 |
389 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives | 403 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives |
390 * us access to the mousewheel, etc. Returns zero if | 404 * us access to the mousewheel, etc. Returns zero if |
391 * writes to device failed, but you still need to query the | 405 * writes to device failed, but you still need to query the |
392 * device to see which mode it's actually in. | 406 * device to see which mode it's actually in. |
393 */ | 407 */ |
394 static int set_imps2_mode(int fd) | 408 static int |
395 { | 409 set_imps2_mode(int fd) |
396 /* If you wanted to control the mouse mode (and we do :) ) ... | 410 { |
397 Set IMPS/2 protocol: | 411 /* If you wanted to control the mouse mode (and we do :) ) ... |
398 {0xf3,200,0xf3,100,0xf3,80} | 412 Set IMPS/2 protocol: |
399 Reset mouse device: | 413 {0xf3,200,0xf3,100,0xf3,80} |
400 {0xFF} | 414 Reset mouse device: |
401 */ | 415 {0xFF} |
402 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80}; | 416 */ |
403 Uint8 reset = 0xff; | 417 Uint8 set_imps2[] = { 0xf3, 200, 0xf3, 100, 0xf3, 80 }; |
404 fd_set fdset; | 418 Uint8 reset = 0xff; |
405 struct timeval tv; | 419 fd_set fdset; |
406 int retval = 0; | 420 struct timeval tv; |
407 | 421 int retval = 0; |
408 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) { | 422 |
409 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { | 423 if (write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2)) { |
410 retval = 1; | 424 if (write(fd, &reset, sizeof(reset)) == sizeof(reset)) { |
411 } | 425 retval = 1; |
412 } | 426 } |
413 | 427 } |
414 /* Get rid of any chatter from the above */ | 428 |
415 FD_ZERO(&fdset); | 429 /* Get rid of any chatter from the above */ |
416 FD_SET(fd, &fdset); | 430 FD_ZERO(&fdset); |
417 tv.tv_sec = 0; | 431 FD_SET(fd, &fdset); |
418 tv.tv_usec = 0; | 432 tv.tv_sec = 0; |
419 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | 433 tv.tv_usec = 0; |
420 char temp[32]; | 434 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
421 read(fd, temp, sizeof(temp)); | 435 char temp[32]; |
422 } | 436 read(fd, temp, sizeof(temp)); |
423 | 437 } |
424 return retval; | 438 |
439 return retval; | |
425 } | 440 } |
426 | 441 |
427 | 442 |
428 /* Returns true if the mouse uses the IMPS/2 protocol */ | 443 /* Returns true if the mouse uses the IMPS/2 protocol */ |
429 static int detect_imps2(int fd) | 444 static int |
430 { | 445 detect_imps2(int fd) |
431 int imps2; | 446 { |
432 | 447 int imps2; |
433 imps2 = 0; | 448 |
434 | 449 imps2 = 0; |
435 if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) { | 450 |
436 imps2 = 1; | 451 if (SDL_getenv("SDL_MOUSEDEV_IMPS2")) { |
437 } | 452 imps2 = 1; |
438 if ( ! imps2 ) { | 453 } |
439 Uint8 query_ps2 = 0xF2; | 454 if (!imps2) { |
440 fd_set fdset; | 455 Uint8 query_ps2 = 0xF2; |
441 struct timeval tv; | 456 fd_set fdset; |
442 | 457 struct timeval tv; |
443 /* Get rid of any mouse motion noise */ | 458 |
444 FD_ZERO(&fdset); | 459 /* Get rid of any mouse motion noise */ |
445 FD_SET(fd, &fdset); | 460 FD_ZERO(&fdset); |
446 tv.tv_sec = 0; | 461 FD_SET(fd, &fdset); |
447 tv.tv_usec = 0; | 462 tv.tv_sec = 0; |
448 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | 463 tv.tv_usec = 0; |
449 char temp[32]; | 464 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
450 read(fd, temp, sizeof(temp)); | 465 char temp[32]; |
451 } | 466 read(fd, temp, sizeof(temp)); |
452 | 467 } |
453 /* Query for the type of mouse protocol */ | 468 |
454 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { | 469 /* Query for the type of mouse protocol */ |
455 Uint8 ch = 0; | 470 if (write(fd, &query_ps2, sizeof(query_ps2)) == sizeof(query_ps2)) { |
456 | 471 Uint8 ch = 0; |
457 /* Get the mouse protocol response */ | 472 |
458 do { | 473 /* Get the mouse protocol response */ |
459 FD_ZERO(&fdset); | 474 do { |
460 FD_SET(fd, &fdset); | 475 FD_ZERO(&fdset); |
461 tv.tv_sec = 1; | 476 FD_SET(fd, &fdset); |
462 tv.tv_usec = 0; | 477 tv.tv_sec = 1; |
463 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) { | 478 tv.tv_usec = 0; |
464 break; | 479 if (select(fd + 1, &fdset, 0, 0, &tv) < 1) { |
465 } | 480 break; |
466 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) && | 481 } |
467 ((ch == 0xFA) || (ch == 0xAA)) ); | 482 } |
468 | 483 while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && |
469 /* Experimental values (Logitech wheelmouse) */ | 484 ((ch == 0xFA) || (ch == 0xAA))); |
485 | |
486 /* Experimental values (Logitech wheelmouse) */ | |
470 #ifdef DEBUG_MOUSE | 487 #ifdef DEBUG_MOUSE |
471 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); | 488 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); |
472 #endif | 489 #endif |
473 if ( ch == 3 ) { | 490 if (ch == 3) { |
474 imps2 = 1; | 491 imps2 = 1; |
475 } | 492 } |
476 } | 493 } |
477 } | 494 } |
478 return imps2; | 495 return imps2; |
479 } | 496 } |
480 | 497 |
481 int GS_OpenMouse(_THIS) | 498 int |
482 { | 499 GS_OpenMouse(_THIS) |
483 int i; | 500 { |
484 const char *mousedev; | 501 int i; |
485 const char *mousedrv; | 502 const char *mousedev; |
486 | 503 const char *mousedrv; |
487 mousedrv = SDL_getenv("SDL_MOUSEDRV"); | 504 |
488 mousedev = SDL_getenv("SDL_MOUSEDEV"); | 505 mousedrv = SDL_getenv("SDL_MOUSEDRV"); |
489 mouse_fd = -1; | 506 mousedev = SDL_getenv("SDL_MOUSEDEV"); |
490 | 507 mouse_fd = -1; |
491 /* STD MICE */ | 508 |
492 | 509 /* STD MICE */ |
493 if ( mousedev == NULL ) { | 510 |
494 /* FIXME someday... allow multiple mice in this driver */ | 511 if (mousedev == NULL) { |
495 char *ps2mice[] = { | 512 /* FIXME someday... allow multiple mice in this driver */ |
496 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL | 513 char *ps2mice[] = { |
497 }; | 514 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL |
498 /* First try to use GPM in repeater mode */ | 515 }; |
499 if ( mouse_fd < 0 ) { | 516 /* First try to use GPM in repeater mode */ |
500 if ( gpm_available() ) { | 517 if (mouse_fd < 0) { |
501 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); | 518 if (gpm_available()) { |
502 if ( mouse_fd >= 0 ) { | 519 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); |
520 if (mouse_fd >= 0) { | |
503 #ifdef DEBUG_MOUSE | 521 #ifdef DEBUG_MOUSE |
504 fprintf(stderr, "Using GPM mouse\n"); | 522 fprintf(stderr, "Using GPM mouse\n"); |
505 #endif | 523 #endif |
506 mouse_drv = MOUSE_GPM; | 524 mouse_drv = MOUSE_GPM; |
507 } | 525 } |
508 } | 526 } |
509 } | 527 } |
510 /* Now try to use a modern PS/2 mouse */ | 528 /* Now try to use a modern PS/2 mouse */ |
511 for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) { | 529 for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) { |
512 mouse_fd = open(ps2mice[i], O_RDWR, 0); | 530 mouse_fd = open(ps2mice[i], O_RDWR, 0); |
513 if (mouse_fd < 0) { | 531 if (mouse_fd < 0) { |
514 mouse_fd = open(ps2mice[i], O_RDONLY, 0); | 532 mouse_fd = open(ps2mice[i], O_RDONLY, 0); |
515 } | 533 } |
516 if (mouse_fd >= 0) { | 534 if (mouse_fd >= 0) { |
517 /* rcg06112001 Attempt to set IMPS/2 mode */ | 535 /* rcg06112001 Attempt to set IMPS/2 mode */ |
518 if ( i == 0 ) { | 536 if (i == 0) { |
519 set_imps2_mode(mouse_fd); | 537 set_imps2_mode(mouse_fd); |
520 } | 538 } |
521 if (detect_imps2(mouse_fd)) { | 539 if (detect_imps2(mouse_fd)) { |
522 #ifdef DEBUG_MOUSE | 540 #ifdef DEBUG_MOUSE |
523 fprintf(stderr, "Using IMPS2 mouse\n"); | 541 fprintf(stderr, "Using IMPS2 mouse\n"); |
524 #endif | 542 #endif |
525 mouse_drv = MOUSE_IMPS2; | 543 mouse_drv = MOUSE_IMPS2; |
526 } else { | 544 } else { |
527 mouse_drv = MOUSE_PS2; | 545 mouse_drv = MOUSE_PS2; |
528 #ifdef DEBUG_MOUSE | 546 #ifdef DEBUG_MOUSE |
529 fprintf(stderr, "Using PS2 mouse\n"); | 547 fprintf(stderr, "Using PS2 mouse\n"); |
530 #endif | 548 #endif |
531 } | 549 } |
532 } | 550 } |
533 } | 551 } |
534 /* Next try to use a PPC ADB port mouse */ | 552 /* Next try to use a PPC ADB port mouse */ |
535 if ( mouse_fd < 0 ) { | 553 if (mouse_fd < 0) { |
536 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); | 554 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); |
537 if ( mouse_fd >= 0 ) { | 555 if (mouse_fd >= 0) { |
538 #ifdef DEBUG_MOUSE | 556 #ifdef DEBUG_MOUSE |
539 fprintf(stderr, "Using ADB mouse\n"); | 557 fprintf(stderr, "Using ADB mouse\n"); |
540 #endif | 558 #endif |
541 mouse_drv = MOUSE_BM; | 559 mouse_drv = MOUSE_BM; |
542 } | 560 } |
543 } | 561 } |
544 } | 562 } |
545 /* Default to a serial Microsoft mouse */ | 563 /* Default to a serial Microsoft mouse */ |
546 if ( mouse_fd < 0 ) { | 564 if (mouse_fd < 0) { |
547 if ( mousedev == NULL ) { | 565 if (mousedev == NULL) { |
548 mousedev = "/dev/mouse"; | 566 mousedev = "/dev/mouse"; |
549 } | 567 } |
550 mouse_fd = open(mousedev, O_RDONLY, 0); | 568 mouse_fd = open(mousedev, O_RDONLY, 0); |
551 if ( mouse_fd >= 0 ) { | 569 if (mouse_fd >= 0) { |
552 struct termios mouse_termios; | 570 struct termios mouse_termios; |
553 | 571 |
554 /* Set the sampling speed to 1200 baud */ | 572 /* Set the sampling speed to 1200 baud */ |
555 tcgetattr(mouse_fd, &mouse_termios); | 573 tcgetattr(mouse_fd, &mouse_termios); |
556 mouse_termios.c_iflag = IGNBRK | IGNPAR; | 574 mouse_termios.c_iflag = IGNBRK | IGNPAR; |
557 mouse_termios.c_oflag = 0; | 575 mouse_termios.c_oflag = 0; |
558 mouse_termios.c_lflag = 0; | 576 mouse_termios.c_lflag = 0; |
559 mouse_termios.c_line = 0; | 577 mouse_termios.c_line = 0; |
560 mouse_termios.c_cc[VTIME] = 0; | 578 mouse_termios.c_cc[VTIME] = 0; |
561 mouse_termios.c_cc[VMIN] = 1; | 579 mouse_termios.c_cc[VMIN] = 1; |
562 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; | 580 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; |
563 mouse_termios.c_cflag |= CS8; | 581 mouse_termios.c_cflag |= CS8; |
564 mouse_termios.c_cflag |= B1200; | 582 mouse_termios.c_cflag |= B1200; |
565 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); | 583 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); |
566 #ifdef DEBUG_MOUSE | 584 #ifdef DEBUG_MOUSE |
567 fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev); | 585 fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev); |
568 #endif | 586 #endif |
569 mouse_drv = MOUSE_MS; | 587 mouse_drv = MOUSE_MS; |
570 } | 588 } |
571 } | 589 } |
572 if ( mouse_fd < 0 ) { | 590 if (mouse_fd < 0) { |
573 mouse_drv = MOUSE_NONE; | 591 mouse_drv = MOUSE_NONE; |
574 } | 592 } |
575 return(mouse_fd); | 593 return (mouse_fd); |
576 } | 594 } |
577 | 595 |
578 static int posted = 0; | 596 static int posted = 0; |
579 | 597 |
580 void GS_vgamousecallback(int button, int dx, int dy) | 598 void |
581 { | 599 GS_vgamousecallback(int button, int dx, int dy) |
582 int button_1, button_3; | 600 { |
583 int button_state; | 601 int button_1, button_3; |
584 int state_changed; | 602 int button_state; |
585 int i; | 603 int state_changed; |
586 Uint8 state; | 604 int i; |
587 | 605 Uint8 state; |
588 if ( dx || dy ) { | 606 |
589 posted += SDL_PrivateMouseMotion(0, 1, dx, dy); | 607 if (dx || dy) { |
590 } | 608 posted += SDL_PrivateMouseMotion(0, 1, dx, dy); |
591 | 609 } |
592 /* Swap button 1 and 3 */ | 610 |
593 button_1 = (button & 0x04) >> 2; | 611 /* Swap button 1 and 3 */ |
594 button_3 = (button & 0x01) << 2; | 612 button_1 = (button & 0x04) >> 2; |
595 button &= ~0x05; | 613 button_3 = (button & 0x01) << 2; |
596 button |= (button_1|button_3); | 614 button &= ~0x05; |
597 | 615 button |= (button_1 | button_3); |
598 /* See what changed */ | 616 |
599 button_state = SDL_GetMouseState(NULL, NULL); | 617 /* See what changed */ |
600 state_changed = button_state ^ button; | 618 button_state = SDL_GetMouseState(NULL, NULL); |
601 for ( i=0; i<8; ++i ) { | 619 state_changed = button_state ^ button; |
602 if ( state_changed & (1<<i) ) { | 620 for (i = 0; i < 8; ++i) { |
603 if ( button & (1<<i) ) { | 621 if (state_changed & (1 << i)) { |
604 state = SDL_PRESSED; | 622 if (button & (1 << i)) { |
605 } else { | 623 state = SDL_PRESSED; |
606 state = SDL_RELEASED; | 624 } else { |
607 } | 625 state = SDL_RELEASED; |
608 posted += SDL_PrivateMouseButton(state, i+1, 0, 0); | 626 } |
609 } | 627 posted += SDL_PrivateMouseButton(state, i + 1, 0, 0); |
610 } | 628 } |
629 } | |
611 } | 630 } |
612 | 631 |
613 /* For now, use GPM, PS/2, and MS protocols | 632 /* For now, use GPM, PS/2, and MS protocols |
614 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.) |
615 */ | 634 */ |
616 static void handle_mouse(_THIS) | 635 static void |
617 { | 636 handle_mouse(_THIS) |
618 static int start = 0; | 637 { |
619 static unsigned char mousebuf[BUFSIZ]; | 638 static int start = 0; |
620 int i, nread; | 639 static unsigned char mousebuf[BUFSIZ]; |
621 int button = 0; | 640 int i, nread; |
622 int dx = 0, dy = 0; | 641 int button = 0; |
623 int packetsize = 0; | 642 int dx = 0, dy = 0; |
624 | 643 int packetsize = 0; |
625 /* Figure out the mouse packet size */ | 644 |
626 switch (mouse_drv) { | 645 /* Figure out the mouse packet size */ |
627 case MOUSE_NONE: | 646 switch (mouse_drv) { |
628 /* Ack! */ | 647 case MOUSE_NONE: |
629 read(mouse_fd, mousebuf, BUFSIZ); | 648 /* Ack! */ |
630 return; | 649 read(mouse_fd, mousebuf, BUFSIZ); |
631 case MOUSE_GPM: | 650 return; |
632 packetsize = 5; | 651 case MOUSE_GPM: |
633 break; | 652 packetsize = 5; |
634 case MOUSE_IMPS2: | 653 break; |
635 packetsize = 4; | 654 case MOUSE_IMPS2: |
636 break; | 655 packetsize = 4; |
637 case MOUSE_PS2: | 656 break; |
638 case MOUSE_MS: | 657 case MOUSE_PS2: |
639 case MOUSE_BM: | 658 case MOUSE_MS: |
640 packetsize = 3; | 659 case MOUSE_BM: |
641 break; | 660 packetsize = 3; |
642 case NUM_MOUSE_DRVS: | 661 break; |
643 /* Uh oh.. */ | 662 case NUM_MOUSE_DRVS: |
644 packetsize = 0; | 663 /* Uh oh.. */ |
645 break; | 664 packetsize = 0; |
646 } | 665 break; |
647 | 666 } |
648 /* Read as many packets as possible */ | 667 |
649 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start); | 668 /* Read as many packets as possible */ |
650 if ( nread < 0 ) { | 669 nread = read(mouse_fd, &mousebuf[start], BUFSIZ - start); |
651 return; | 670 if (nread < 0) { |
652 } | 671 return; |
653 nread += start; | 672 } |
673 nread += start; | |
654 #ifdef DEBUG_MOUSE | 674 #ifdef DEBUG_MOUSE |
655 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); |
656 #endif | 676 #endif |
657 for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) { | 677 for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) { |
658 switch (mouse_drv) { | 678 switch (mouse_drv) { |
659 case MOUSE_NONE: | 679 case MOUSE_NONE: |
660 break; | 680 break; |
661 case MOUSE_GPM: | 681 case MOUSE_GPM: |
662 /* GPM protocol has 0x80 in high byte */ | 682 /* GPM protocol has 0x80 in high byte */ |
663 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | 683 if ((mousebuf[i] & 0xF8) != 0x80) { |
664 /* Go to next byte */ | 684 /* Go to next byte */ |
665 i -= (packetsize-1); | 685 i -= (packetsize - 1); |
666 continue; | 686 continue; |
667 } | 687 } |
668 /* Get current mouse state */ | 688 /* Get current mouse state */ |
669 button = (~mousebuf[i]) & 0x07; | 689 button = (~mousebuf[i]) & 0x07; |
670 dx = (signed char)(mousebuf[i+1]) + | 690 dx = (signed char) (mousebuf[i + 1]) + |
671 (signed char)(mousebuf[i+3]); | 691 (signed char) (mousebuf[i + 3]); |
672 dy = -((signed char)(mousebuf[i+2]) + | 692 dy = -((signed char) (mousebuf[i + 2]) + |
673 (signed char)(mousebuf[i+4])); | 693 (signed char) (mousebuf[i + 4])); |
674 break; | 694 break; |
675 case MOUSE_PS2: | 695 case MOUSE_PS2: |
676 /* PS/2 protocol has nothing in high byte */ | 696 /* PS/2 protocol has nothing in high byte */ |
677 if ( (mousebuf[i] & 0xC0) != 0 ) { | 697 if ((mousebuf[i] & 0xC0) != 0) { |
678 /* Go to next byte */ | 698 /* Go to next byte */ |
679 i -= (packetsize-1); | 699 i -= (packetsize - 1); |
680 continue; | 700 continue; |
681 } | 701 } |
682 /* Get current mouse state */ | 702 /* Get current mouse state */ |
683 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | 703 button = (mousebuf[i] & 0x04) >> 1 | /*Middle */ |
684 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | 704 (mousebuf[i] & 0x02) >> 1 | /*Right */ |
685 (mousebuf[i] & 0x01) << 2; /*Left*/ | 705 (mousebuf[i] & 0x01) << 2; /*Left */ |
686 dx = (mousebuf[i] & 0x10) ? | 706 dx = (mousebuf[i] & 0x10) ? |
687 mousebuf[i+1] - 256 : mousebuf[i+1]; | 707 mousebuf[i + 1] - 256 : mousebuf[i + 1]; |
688 dy = (mousebuf[i] & 0x20) ? | 708 dy = (mousebuf[i] & 0x20) ? |
689 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | 709 -(mousebuf[i + 2] - 256) : -mousebuf[i + 2]; |
690 break; | 710 break; |
691 case MOUSE_IMPS2: | 711 case MOUSE_IMPS2: |
692 /* Get current mouse state */ | 712 /* Get current mouse state */ |
693 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | 713 button = (mousebuf[i] & 0x04) >> 1 | /*Middle */ |
694 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | 714 (mousebuf[i] & 0x02) >> 1 | /*Right */ |
695 (mousebuf[i] & 0x01) << 2 | /*Left*/ | 715 (mousebuf[i] & 0x01) << 2 | /*Left */ |
696 (mousebuf[i] & 0x40) >> 3 | /* 4 */ | 716 (mousebuf[i] & 0x40) >> 3 | /* 4 */ |
697 (mousebuf[i] & 0x80) >> 3; /* 5 */ | 717 (mousebuf[i] & 0x80) >> 3; /* 5 */ |
698 dx = (mousebuf[i] & 0x10) ? | 718 dx = (mousebuf[i] & 0x10) ? |
699 mousebuf[i+1] - 256 : mousebuf[i+1]; | 719 mousebuf[i + 1] - 256 : mousebuf[i + 1]; |
700 dy = (mousebuf[i] & 0x20) ? | 720 dy = (mousebuf[i] & 0x20) ? |
701 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | 721 -(mousebuf[i + 2] - 256) : -mousebuf[i + 2]; |
702 switch (mousebuf[i+3]&0x0F) { | 722 switch (mousebuf[i + 3] & 0x0F) { |
703 case 0x0E: /* DX = +1 */ | 723 case 0x0E: /* DX = +1 */ |
704 case 0x02: /* DX = -1 */ | 724 case 0x02: /* DX = -1 */ |
705 break; | 725 break; |
706 case 0x0F: /* DY = +1 (map button 4) */ | 726 case 0x0F: /* DY = +1 (map button 4) */ |
707 FB_vgamousecallback(button | (1<<3), | 727 FB_vgamousecallback(button | (1 << 3), 1, 0, 0); |
708 1, 0, 0); | 728 break; |
709 break; | 729 case 0x01: /* DY = -1 (map button 5) */ |
710 case 0x01: /* DY = -1 (map button 5) */ | 730 FB_vgamousecallback(button | (1 << 4), 1, 0, 0); |
711 FB_vgamousecallback(button | (1<<4), | 731 break; |
712 1, 0, 0); | 732 } |
713 break; | 733 break; |
714 } | 734 case MOUSE_MS: |
715 break; | 735 /* Microsoft protocol has 0x40 in high byte */ |
716 case MOUSE_MS: | 736 if ((mousebuf[i] & 0x40) != 0x40) { |
717 /* Microsoft protocol has 0x40 in high byte */ | 737 /* Go to next byte */ |
718 if ( (mousebuf[i] & 0x40) != 0x40 ) { | 738 i -= (packetsize - 1); |
719 /* Go to next byte */ | 739 continue; |
720 i -= (packetsize-1); | 740 } |
721 continue; | 741 /* Get current mouse state */ |
722 } | 742 button = ((mousebuf[i] & 0x20) >> 3) | |
723 /* Get current mouse state */ | 743 ((mousebuf[i] & 0x10) >> 4); |
724 button = ((mousebuf[i] & 0x20) >> 3) | | 744 dx = (signed char) (((mousebuf[i] & 0x03) << 6) | |
725 ((mousebuf[i] & 0x10) >> 4); | 745 (mousebuf[i + 1] & 0x3F)); |
726 dx = (signed char)(((mousebuf[i] & 0x03) << 6) | | 746 dy = (signed char) (((mousebuf[i] & 0x0C) << 4) | |
727 (mousebuf[i + 1] & 0x3F)); | 747 (mousebuf[i + 2] & 0x3F)); |
728 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) | | 748 break; |
729 (mousebuf[i + 2] & 0x3F)); | 749 case MOUSE_BM: |
730 break; | 750 /* BusMouse protocol has 0xF8 in high byte */ |
731 case MOUSE_BM: | 751 if ((mousebuf[i] & 0xF8) != 0x80) { |
732 /* BusMouse protocol has 0xF8 in high byte */ | 752 /* Go to next byte */ |
733 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | 753 i -= (packetsize - 1); |
734 /* Go to next byte */ | 754 continue; |
735 i -= (packetsize-1); | 755 } |
736 continue; | 756 /* Get current mouse state */ |
737 } | 757 button = (~mousebuf[i]) & 0x07; |
738 /* Get current mouse state */ | 758 dx = (signed char) mousebuf[i + 1]; |
739 button = (~mousebuf[i]) & 0x07; | 759 dy = -(signed char) mousebuf[i + 2]; |
740 dx = (signed char)mousebuf[i+1]; | 760 break; |
741 dy = -(signed char)mousebuf[i+2]; | 761 case NUM_MOUSE_DRVS: |
742 break; | 762 /* Uh oh.. */ |
743 case NUM_MOUSE_DRVS: | 763 dx = 0; |
744 /* Uh oh.. */ | 764 dy = 0; |
745 dx = 0; | 765 break; |
746 dy = 0; | 766 } |
747 break; | 767 GS_vgamousecallback(button, dx, dy); |
748 } | 768 } |
749 GS_vgamousecallback(button, dx, dy); | 769 if (i < nread) { |
750 } | 770 SDL_memcpy(mousebuf, &mousebuf[i], (nread - i)); |
751 if ( i < nread ) { | 771 start = (nread - i); |
752 SDL_memcpy(mousebuf, &mousebuf[i], (nread-i)); | 772 } else { |
753 start = (nread-i); | 773 start = 0; |
754 } else { | 774 } |
755 start = 0; | 775 return; |
756 } | 776 } |
757 return; | 777 |
758 } | 778 static void |
759 | 779 handle_keyboard(_THIS) |
760 static void handle_keyboard(_THIS) | 780 { |
761 { | 781 unsigned char keybuf[BUFSIZ]; |
762 unsigned char keybuf[BUFSIZ]; | 782 int i, nread; |
763 int i, nread; | 783 int pressed; |
764 int pressed; | 784 int scancode; |
765 int scancode; | 785 SDL_keysym keysym; |
766 SDL_keysym keysym; | 786 |
767 | 787 nread = read(keyboard_fd, keybuf, BUFSIZ); |
768 nread = read(keyboard_fd, keybuf, BUFSIZ); | 788 for (i = 0; i < nread; ++i) { |
769 for ( i=0; i<nread; ++i ) { | 789 scancode = keybuf[i] & 0x7F; |
770 scancode = keybuf[i] & 0x7F; | 790 if (keybuf[i] & 0x80) { |
771 if ( keybuf[i] & 0x80 ) { | 791 pressed = SDL_RELEASED; |
772 pressed = SDL_RELEASED; | 792 } else { |
773 } else { | 793 pressed = SDL_PRESSED; |
774 pressed = SDL_PRESSED; | 794 } |
775 } | 795 TranslateKey(scancode, &keysym); |
776 TranslateKey(scancode, &keysym); | 796 posted += SDL_PrivateKeyboard(pressed, &keysym); |
777 posted += SDL_PrivateKeyboard(pressed, &keysym); | 797 } |
778 } | 798 } |
779 } | 799 |
780 | 800 void |
781 void GS_PumpEvents(_THIS) | 801 GS_PumpEvents(_THIS) |
782 { | 802 { |
783 fd_set fdset; | 803 fd_set fdset; |
784 int max_fd; | 804 int max_fd; |
785 static struct timeval zero; | 805 static struct timeval zero; |
786 | 806 |
787 do { | 807 do { |
788 posted = 0; | 808 posted = 0; |
789 | 809 |
790 FD_ZERO(&fdset); | 810 FD_ZERO(&fdset); |
791 max_fd = 0; | 811 max_fd = 0; |
792 if ( keyboard_fd >= 0 ) { | 812 if (keyboard_fd >= 0) { |
793 FD_SET(keyboard_fd, &fdset); | 813 FD_SET(keyboard_fd, &fdset); |
794 if ( max_fd < keyboard_fd ) { | 814 if (max_fd < keyboard_fd) { |
795 max_fd = keyboard_fd; | 815 max_fd = keyboard_fd; |
796 } | 816 } |
797 } | 817 } |
798 if ( mouse_fd >= 0 ) { | 818 if (mouse_fd >= 0) { |
799 FD_SET(mouse_fd, &fdset); | 819 FD_SET(mouse_fd, &fdset); |
800 if ( max_fd < mouse_fd ) { | 820 if (max_fd < mouse_fd) { |
801 max_fd = mouse_fd; | 821 max_fd = mouse_fd; |
802 } | 822 } |
803 } | 823 } |
804 if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) { | 824 if (select(max_fd + 1, &fdset, NULL, NULL, &zero) > 0) { |
805 if ( keyboard_fd >= 0 ) { | 825 if (keyboard_fd >= 0) { |
806 if ( FD_ISSET(keyboard_fd, &fdset) ) { | 826 if (FD_ISSET(keyboard_fd, &fdset)) { |
807 handle_keyboard(this); | 827 handle_keyboard(this); |
808 } | 828 } |
809 } | 829 } |
810 if ( mouse_fd >= 0 ) { | 830 if (mouse_fd >= 0) { |
811 if ( FD_ISSET(mouse_fd, &fdset) ) { | 831 if (FD_ISSET(mouse_fd, &fdset)) { |
812 handle_mouse(this); | 832 handle_mouse(this); |
813 } | 833 } |
814 } | 834 } |
815 } | 835 } |
816 } while ( posted ); | 836 } |
817 } | 837 while (posted); |
818 | 838 } |
819 void GS_InitOSKeymap(_THIS) | 839 |
820 { | 840 void |
821 int i; | 841 GS_InitOSKeymap(_THIS) |
822 | 842 { |
823 /* Initialize the Linux key translation table */ | 843 int i; |
824 | 844 |
825 /* First get the ascii keys and others not well handled */ | 845 /* Initialize the Linux key translation table */ |
826 for (i=0; i<SDL_arraysize(keymap); ++i) { | 846 |
827 switch(i) { | 847 /* First get the ascii keys and others not well handled */ |
828 /* These aren't handled by the x86 kernel keymapping (?) */ | 848 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
829 case SCANCODE_PRINTSCREEN: | 849 switch (i) { |
830 keymap[i] = SDLK_PRINT; | 850 /* These aren't handled by the x86 kernel keymapping (?) */ |
831 break; | 851 case SCANCODE_PRINTSCREEN: |
832 case SCANCODE_BREAK: | 852 keymap[i] = SDLK_PRINT; |
833 keymap[i] = SDLK_BREAK; | 853 break; |
834 break; | 854 case SCANCODE_BREAK: |
835 case SCANCODE_BREAK_ALTERNATIVE: | 855 keymap[i] = SDLK_BREAK; |
836 keymap[i] = SDLK_PAUSE; | 856 break; |
837 break; | 857 case SCANCODE_BREAK_ALTERNATIVE: |
838 case SCANCODE_LEFTSHIFT: | 858 keymap[i] = SDLK_PAUSE; |
839 keymap[i] = SDLK_LSHIFT; | 859 break; |
840 break; | 860 case SCANCODE_LEFTSHIFT: |
841 case SCANCODE_RIGHTSHIFT: | 861 keymap[i] = SDLK_LSHIFT; |
842 keymap[i] = SDLK_RSHIFT; | 862 break; |
843 break; | 863 case SCANCODE_RIGHTSHIFT: |
844 case SCANCODE_LEFTCONTROL: | 864 keymap[i] = SDLK_RSHIFT; |
845 keymap[i] = SDLK_LCTRL; | 865 break; |
846 break; | 866 case SCANCODE_LEFTCONTROL: |
847 case SCANCODE_RIGHTCONTROL: | 867 keymap[i] = SDLK_LCTRL; |
848 keymap[i] = SDLK_RCTRL; | 868 break; |
849 break; | 869 case SCANCODE_RIGHTCONTROL: |
850 case SCANCODE_RIGHTWIN: | 870 keymap[i] = SDLK_RCTRL; |
851 keymap[i] = SDLK_RSUPER; | 871 break; |
852 break; | 872 case SCANCODE_RIGHTWIN: |
853 case SCANCODE_LEFTWIN: | 873 keymap[i] = SDLK_RSUPER; |
854 keymap[i] = SDLK_LSUPER; | 874 break; |
855 break; | 875 case SCANCODE_LEFTWIN: |
856 case 127: | 876 keymap[i] = SDLK_LSUPER; |
857 keymap[i] = SDLK_MENU; | 877 break; |
858 break; | 878 case 127: |
859 /* this should take care of all standard ascii keys */ | 879 keymap[i] = SDLK_MENU; |
860 default: | 880 break; |
861 keymap[i] = KVAL(vga_keymap[0][i]); | 881 /* this should take care of all standard ascii keys */ |
862 break; | 882 default: |
863 } | 883 keymap[i] = KVAL(vga_keymap[0][i]); |
864 } | 884 break; |
865 for (i=0; i<SDL_arraysize(keymap); ++i) { | 885 } |
866 switch(keymap_temp[i]) { | 886 } |
867 case K_F1: keymap[i] = SDLK_F1; break; | 887 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
868 case K_F2: keymap[i] = SDLK_F2; break; | 888 switch (keymap_temp[i]) { |
869 case K_F3: keymap[i] = SDLK_F3; break; | 889 case K_F1: |
870 case K_F4: keymap[i] = SDLK_F4; break; | 890 keymap[i] = SDLK_F1; |
871 case K_F5: keymap[i] = SDLK_F5; break; | 891 break; |
872 case K_F6: keymap[i] = SDLK_F6; break; | 892 case K_F2: |
873 case K_F7: keymap[i] = SDLK_F7; break; | 893 keymap[i] = SDLK_F2; |
874 case K_F8: keymap[i] = SDLK_F8; break; | 894 break; |
875 case K_F9: keymap[i] = SDLK_F9; break; | 895 case K_F3: |
876 case K_F10: keymap[i] = SDLK_F10; break; | 896 keymap[i] = SDLK_F3; |
877 case K_F11: keymap[i] = SDLK_F11; break; | 897 break; |
878 case K_F12: keymap[i] = SDLK_F12; break; | 898 case K_F4: |
879 | 899 keymap[i] = SDLK_F4; |
880 case K_DOWN: keymap[i] = SDLK_DOWN; break; | 900 break; |
881 case K_LEFT: keymap[i] = SDLK_LEFT; break; | 901 case K_F5: |
882 case K_RIGHT: keymap[i] = SDLK_RIGHT; break; | 902 keymap[i] = SDLK_F5; |
883 case K_UP: keymap[i] = SDLK_UP; break; | 903 break; |
884 | 904 case K_F6: |
885 case K_P0: keymap[i] = SDLK_KP0; break; | 905 keymap[i] = SDLK_F6; |
886 case K_P1: keymap[i] = SDLK_KP1; break; | 906 break; |
887 case K_P2: keymap[i] = SDLK_KP2; break; | 907 case K_F7: |
888 case K_P3: keymap[i] = SDLK_KP3; break; | 908 keymap[i] = SDLK_F7; |
889 case K_P4: keymap[i] = SDLK_KP4; break; | 909 break; |
890 case K_P5: keymap[i] = SDLK_KP5; break; | 910 case K_F8: |
891 case K_P6: keymap[i] = SDLK_KP6; break; | 911 keymap[i] = SDLK_F8; |
892 case K_P7: keymap[i] = SDLK_KP7; break; | 912 break; |
893 case K_P8: keymap[i] = SDLK_KP8; break; | 913 case K_F9: |
894 case K_P9: keymap[i] = SDLK_KP9; break; | 914 keymap[i] = SDLK_F9; |
895 case K_PPLUS: keymap[i] = SDLK_KP_PLUS; break; | 915 break; |
896 case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break; | 916 case K_F10: |
897 case K_PSTAR: keymap[i] = SDLK_KP_MULTIPLY; break; | 917 keymap[i] = SDLK_F10; |
898 case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break; | 918 break; |
899 case K_PENTER: keymap[i] = SDLK_KP_ENTER; break; | 919 case K_F11: |
900 case K_PDOT: keymap[i] = SDLK_KP_PERIOD; break; | 920 keymap[i] = SDLK_F11; |
901 | 921 break; |
902 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT ) | 922 case K_F12: |
903 keymap[i] = SDLK_LSHIFT; | 923 keymap[i] = SDLK_F12; |
904 break; | 924 break; |
905 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break; | 925 |
906 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break; | 926 case K_DOWN: |
907 case K_CTRL: if ( keymap[i] != SDLK_RCTRL ) | 927 keymap[i] = SDLK_DOWN; |
908 keymap[i] = SDLK_LCTRL; | 928 break; |
909 break; | 929 case K_LEFT: |
910 case K_CTRLL: keymap[i] = SDLK_LCTRL; break; | 930 keymap[i] = SDLK_LEFT; |
911 case K_CTRLR: keymap[i] = SDLK_RCTRL; break; | 931 break; |
912 case K_ALT: keymap[i] = SDLK_LALT; break; | 932 case K_RIGHT: |
913 case K_ALTGR: keymap[i] = SDLK_RALT; break; | 933 keymap[i] = SDLK_RIGHT; |
914 | 934 break; |
915 case K_INSERT: keymap[i] = SDLK_INSERT; break; | 935 case K_UP: |
916 case K_REMOVE: keymap[i] = SDLK_DELETE; break; | 936 keymap[i] = SDLK_UP; |
917 case K_PGUP: keymap[i] = SDLK_PAGEUP; break; | 937 break; |
918 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break; | 938 |
919 case K_FIND: keymap[i] = SDLK_HOME; break; | 939 case K_P0: |
920 case K_SELECT: keymap[i] = SDLK_END; break; | 940 keymap[i] = SDLK_KP0; |
921 | 941 break; |
922 case K_NUM: keymap[i] = SDLK_NUMLOCK; break; | 942 case K_P1: |
923 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break; | 943 keymap[i] = SDLK_KP1; |
924 | 944 break; |
925 case K_F13: keymap[i] = SDLK_PRINT; break; | 945 case K_P2: |
926 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break; | 946 keymap[i] = SDLK_KP2; |
927 case K_PAUSE: keymap[i] = SDLK_PAUSE; break; | 947 break; |
928 | 948 case K_P3: |
929 case 127: keymap[i] = SDLK_BACKSPACE; break; | 949 keymap[i] = SDLK_KP3; |
930 | 950 break; |
931 default: break; | 951 case K_P4: |
932 } | 952 keymap[i] = SDLK_KP4; |
933 } | 953 break; |
934 } | 954 case K_P5: |
935 | 955 keymap[i] = SDLK_KP5; |
936 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | 956 break; |
937 { | 957 case K_P6: |
938 /* Set the keysym information */ | 958 keymap[i] = SDLK_KP6; |
939 keysym->scancode = scancode; | 959 break; |
940 keysym->sym = keymap[scancode]; | 960 case K_P7: |
941 keysym->mod = KMOD_NONE; | 961 keymap[i] = SDLK_KP7; |
942 | 962 break; |
943 /* If UNICODE is on, get the UNICODE value for the key */ | 963 case K_P8: |
944 keysym->unicode = 0; | 964 keymap[i] = SDLK_KP8; |
945 if ( SDL_TranslateUNICODE ) { | 965 break; |
946 int map; | 966 case K_P9: |
947 SDLMod modstate; | 967 keymap[i] = SDLK_KP9; |
948 | 968 break; |
949 modstate = SDL_GetModState(); | 969 case K_PPLUS: |
950 map = 0; | 970 keymap[i] = SDLK_KP_PLUS; |
951 if ( modstate & KMOD_SHIFT ) { | 971 break; |
952 map |= (1<<KG_SHIFT); | 972 case K_PMINUS: |
953 } | 973 keymap[i] = SDLK_KP_MINUS; |
954 if ( modstate & KMOD_CTRL ) { | 974 break; |
955 map |= (1<<KG_CTRL); | 975 case K_PSTAR: |
956 } | 976 keymap[i] = SDLK_KP_MULTIPLY; |
957 if ( modstate & KMOD_ALT ) { | 977 break; |
958 map |= (1<<KG_ALT); | 978 case K_PSLASH: |
959 } | 979 keymap[i] = SDLK_KP_DIVIDE; |
960 if ( modstate & KMOD_MODE ) { | 980 break; |
961 map |= (1<<KG_ALTGR); | 981 case K_PENTER: |
962 } | 982 keymap[i] = SDLK_KP_ENTER; |
963 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) { | 983 break; |
964 if ( modstate & KMOD_CAPS ) { | 984 case K_PDOT: |
965 map ^= (1<<KG_SHIFT); | 985 keymap[i] = SDLK_KP_PERIOD; |
966 } | 986 break; |
967 } | 987 |
968 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) { | 988 case K_SHIFT: |
969 if ( modstate & KMOD_NUM ) { | 989 if (keymap[i] != SDLK_RSHIFT) |
970 keysym->unicode=KVAL(vga_keymap[map][scancode]); | 990 keymap[i] = SDLK_LSHIFT; |
971 } | 991 break; |
972 } else { | 992 case K_SHIFTL: |
973 keysym->unicode = KVAL(vga_keymap[map][scancode]); | 993 keymap[i] = SDLK_LSHIFT; |
974 } | 994 break; |
975 } | 995 case K_SHIFTR: |
976 return(keysym); | 996 keymap[i] = SDLK_RSHIFT; |
977 } | 997 break; |
998 case K_CTRL: | |
999 if (keymap[i] != SDLK_RCTRL) | |
1000 keymap[i] = SDLK_LCTRL; | |
1001 break; | |
1002 case K_CTRLL: | |
1003 keymap[i] = SDLK_LCTRL; | |
1004 break; | |
1005 case K_CTRLR: | |
1006 keymap[i] = SDLK_RCTRL; | |
1007 break; | |
1008 case K_ALT: | |
1009 keymap[i] = SDLK_LALT; | |
1010 break; | |
1011 case K_ALTGR: | |
1012 keymap[i] = SDLK_RALT; | |
1013 break; | |
1014 | |
1015 case K_INSERT: | |
1016 keymap[i] = SDLK_INSERT; | |
1017 break; | |
1018 case K_REMOVE: | |
1019 keymap[i] = SDLK_DELETE; | |
1020 break; | |
1021 case K_PGUP: | |
1022 keymap[i] = SDLK_PAGEUP; | |
1023 break; | |
1024 case K_PGDN: | |
1025 keymap[i] = SDLK_PAGEDOWN; | |
1026 break; | |
1027 case K_FIND: | |
1028 keymap[i] = SDLK_HOME; | |
1029 break; | |
1030 case K_SELECT: | |
1031 keymap[i] = SDLK_END; | |
1032 break; | |
1033 | |
1034 case K_NUM: | |
1035 keymap[i] = SDLK_NUMLOCK; | |
1036 break; | |
1037 case K_CAPS: | |
1038 keymap[i] = SDLK_CAPSLOCK; | |
1039 break; | |
1040 | |
1041 case K_F13: | |
1042 keymap[i] = SDLK_PRINT; | |
1043 break; | |
1044 case K_HOLD: | |
1045 keymap[i] = SDLK_SCROLLOCK; | |
1046 break; | |
1047 case K_PAUSE: | |
1048 keymap[i] = SDLK_PAUSE; | |
1049 break; | |
1050 | |
1051 case 127: | |
1052 keymap[i] = SDLK_BACKSPACE; | |
1053 break; | |
1054 | |
1055 default: | |
1056 break; | |
1057 } | |
1058 } | |
1059 } | |
1060 | |
1061 static SDL_keysym * | |
1062 TranslateKey(int scancode, SDL_keysym * keysym) | |
1063 { | |
1064 /* Set the keysym information */ | |
1065 keysym->scancode = scancode; | |
1066 keysym->sym = keymap[scancode]; | |
1067 keysym->mod = KMOD_NONE; | |
1068 | |
1069 /* If UNICODE is on, get the UNICODE value for the key */ | |
1070 keysym->unicode = 0; | |
1071 if (SDL_TranslateUNICODE) { | |
1072 int map; | |
1073 SDLMod modstate; | |
1074 | |
1075 modstate = SDL_GetModState(); | |
1076 map = 0; | |
1077 if (modstate & KMOD_SHIFT) { | |
1078 map |= (1 << KG_SHIFT); | |
1079 } | |
1080 if (modstate & KMOD_CTRL) { | |
1081 map |= (1 << KG_CTRL); | |
1082 } | |
1083 if (modstate & KMOD_ALT) { | |
1084 map |= (1 << KG_ALT); | |
1085 } | |
1086 if (modstate & KMOD_MODE) { | |
1087 map |= (1 << KG_ALTGR); | |
1088 } | |
1089 if (KTYP(vga_keymap[map][scancode]) == KT_LETTER) { | |
1090 if (modstate & KMOD_CAPS) { | |
1091 map ^= (1 << KG_SHIFT); | |
1092 } | |
1093 } | |
1094 if (KTYP(vga_keymap[map][scancode]) == KT_PAD) { | |
1095 if (modstate & KMOD_NUM) { | |
1096 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
1097 } | |
1098 } else { | |
1099 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
1100 } | |
1101 } | |
1102 return (keysym); | |
1103 } | |
1104 | |
1105 /* vi: set ts=4 sw=4 expandtab: */ |