Mercurial > sdl-ios-xcode
comparison src/video/fbcon/SDL_fbevents.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 | 15ae67aa6b4b |
children | e27bdcc80744 204be4fc2726 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
61 /* The translation tables from a console scancode to a SDL keysym */ | 61 /* The translation tables from a console scancode to a SDL keysym */ |
62 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) | 62 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) |
63 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; | 63 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; |
64 static SDLKey keymap[128]; | 64 static SDLKey keymap[128]; |
65 static Uint16 keymap_temp[128]; /* only used at startup */ | 65 static Uint16 keymap_temp[128]; /* only used at startup */ |
66 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); | 66 static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym); |
67 | 67 |
68 /* Ugh, we have to duplicate the kernel's keysym mapping code... | 68 /* Ugh, we have to duplicate the kernel's keysym mapping code... |
69 Oh, it's not so bad. :-) | 69 Oh, it's not so bad. :-) |
70 | 70 |
71 FIXME: Add keyboard LED handling code | 71 FIXME: Add keyboard LED handling code |
72 */ | 72 */ |
73 static void FB_vgainitkeymaps(int fd) | 73 static void |
74 { | 74 FB_vgainitkeymaps(int fd) |
75 struct kbentry entry; | 75 { |
76 int map, i; | 76 struct kbentry entry; |
77 | 77 int map, i; |
78 /* Don't do anything if we are passed a closed keyboard */ | 78 |
79 if ( fd < 0 ) { | 79 /* Don't do anything if we are passed a closed keyboard */ |
80 return; | 80 if (fd < 0) { |
81 } | 81 return; |
82 | 82 } |
83 /* Load all the keysym mappings */ | 83 |
84 for ( map=0; map<NUM_VGAKEYMAPS; ++map ) { | 84 /* Load all the keysym mappings */ |
85 SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16)); | 85 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { |
86 for ( i=0; i<NR_KEYS; ++i ) { | 86 SDL_memset(vga_keymap[map], 0, NR_KEYS * sizeof(Uint16)); |
87 entry.kb_table = map; | 87 for (i = 0; i < NR_KEYS; ++i) { |
88 entry.kb_index = i; | 88 entry.kb_table = map; |
89 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) { | 89 entry.kb_index = i; |
90 /* fill keytemp. This replaces SDL_fbkeys.h */ | 90 if (ioctl(fd, KDGKBENT, &entry) == 0) { |
91 if ( (map == 0) && (i<128) ) { | 91 /* fill keytemp. This replaces SDL_fbkeys.h */ |
92 keymap_temp[i] = entry.kb_value; | 92 if ((map == 0) && (i < 128)) { |
93 } | 93 keymap_temp[i] = entry.kb_value; |
94 /* The "Enter" key is a special case */ | 94 } |
95 if ( entry.kb_value == K_ENTER ) { | 95 /* The "Enter" key is a special case */ |
96 entry.kb_value = K(KT_ASCII,13); | 96 if (entry.kb_value == K_ENTER) { |
97 } | 97 entry.kb_value = K(KT_ASCII, 13); |
98 /* Handle numpad specially as well */ | 98 } |
99 if ( KTYP(entry.kb_value) == KT_PAD ) { | 99 /* Handle numpad specially as well */ |
100 switch ( entry.kb_value ) { | 100 if (KTYP(entry.kb_value) == KT_PAD) { |
101 case K_P0: | 101 switch (entry.kb_value) { |
102 case K_P1: | 102 case K_P0: |
103 case K_P2: | 103 case K_P1: |
104 case K_P3: | 104 case K_P2: |
105 case K_P4: | 105 case K_P3: |
106 case K_P5: | 106 case K_P4: |
107 case K_P6: | 107 case K_P5: |
108 case K_P7: | 108 case K_P6: |
109 case K_P8: | 109 case K_P7: |
110 case K_P9: | 110 case K_P8: |
111 vga_keymap[map][i]=entry.kb_value; | 111 case K_P9: |
112 vga_keymap[map][i]+= '0'; | 112 vga_keymap[map][i] = entry.kb_value; |
113 break; | 113 vga_keymap[map][i] += '0'; |
114 case K_PPLUS: | 114 break; |
115 vga_keymap[map][i]=K(KT_ASCII,'+'); | 115 case K_PPLUS: |
116 break; | 116 vga_keymap[map][i] = K(KT_ASCII, '+'); |
117 case K_PMINUS: | 117 break; |
118 vga_keymap[map][i]=K(KT_ASCII,'-'); | 118 case K_PMINUS: |
119 break; | 119 vga_keymap[map][i] = K(KT_ASCII, '-'); |
120 case K_PSTAR: | 120 break; |
121 vga_keymap[map][i]=K(KT_ASCII,'*'); | 121 case K_PSTAR: |
122 break; | 122 vga_keymap[map][i] = K(KT_ASCII, '*'); |
123 case K_PSLASH: | 123 break; |
124 vga_keymap[map][i]=K(KT_ASCII,'/'); | 124 case K_PSLASH: |
125 break; | 125 vga_keymap[map][i] = K(KT_ASCII, '/'); |
126 case K_PENTER: | 126 break; |
127 vga_keymap[map][i]=K(KT_ASCII,'\r'); | 127 case K_PENTER: |
128 break; | 128 vga_keymap[map][i] = K(KT_ASCII, '\r'); |
129 case K_PCOMMA: | 129 break; |
130 vga_keymap[map][i]=K(KT_ASCII,','); | 130 case K_PCOMMA: |
131 break; | 131 vga_keymap[map][i] = K(KT_ASCII, ','); |
132 case K_PDOT: | 132 break; |
133 vga_keymap[map][i]=K(KT_ASCII,'.'); | 133 case K_PDOT: |
134 break; | 134 vga_keymap[map][i] = K(KT_ASCII, '.'); |
135 default: | 135 break; |
136 break; | 136 default: |
137 } | 137 break; |
138 } | 138 } |
139 /* Do the normal key translation */ | 139 } |
140 if ( (KTYP(entry.kb_value) == KT_LATIN) || | 140 /* Do the normal key translation */ |
141 (KTYP(entry.kb_value) == KT_ASCII) || | 141 if ((KTYP(entry.kb_value) == KT_LATIN) || |
142 (KTYP(entry.kb_value) == KT_LETTER) ) { | 142 (KTYP(entry.kb_value) == KT_ASCII) || |
143 vga_keymap[map][i] = entry.kb_value; | 143 (KTYP(entry.kb_value) == KT_LETTER)) { |
144 } | 144 vga_keymap[map][i] = entry.kb_value; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 | 149 } |
150 int FB_InGraphicsMode(_THIS) | 150 |
151 { | 151 int |
152 return((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); | 152 FB_InGraphicsMode(_THIS) |
153 } | 153 { |
154 | 154 return ((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); |
155 int FB_EnterGraphicsMode(_THIS) | 155 } |
156 { | 156 |
157 struct termios keyboard_termios; | 157 int |
158 | 158 FB_EnterGraphicsMode(_THIS) |
159 /* Set medium-raw keyboard mode */ | 159 { |
160 if ( (keyboard_fd >= 0) && !FB_InGraphicsMode(this) ) { | 160 struct termios keyboard_termios; |
161 | 161 |
162 /* Switch to the correct virtual terminal */ | 162 /* Set medium-raw keyboard mode */ |
163 if ( current_vt > 0 ) { | 163 if ((keyboard_fd >= 0) && !FB_InGraphicsMode(this)) { |
164 struct vt_stat vtstate; | 164 |
165 | 165 /* Switch to the correct virtual terminal */ |
166 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) { | 166 if (current_vt > 0) { |
167 saved_vt = vtstate.v_active; | 167 struct vt_stat vtstate; |
168 } | 168 |
169 if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) { | 169 if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) { |
170 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); | 170 saved_vt = vtstate.v_active; |
171 } | 171 } |
172 } | 172 if (ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0) { |
173 | 173 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); |
174 /* Set the terminal input mode */ | 174 } |
175 if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) { | 175 } |
176 SDL_SetError("Unable to get terminal attributes"); | 176 |
177 if ( keyboard_fd > 0 ) { | 177 /* Set the terminal input mode */ |
178 close(keyboard_fd); | 178 if (tcgetattr(keyboard_fd, &saved_kbd_termios) < 0) { |
179 } | 179 SDL_SetError("Unable to get terminal attributes"); |
180 keyboard_fd = -1; | 180 if (keyboard_fd > 0) { |
181 return(-1); | 181 close(keyboard_fd); |
182 } | 182 } |
183 if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) { | 183 keyboard_fd = -1; |
184 SDL_SetError("Unable to get current keyboard mode"); | 184 return (-1); |
185 if ( keyboard_fd > 0 ) { | 185 } |
186 close(keyboard_fd); | 186 if (ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0) { |
187 } | 187 SDL_SetError("Unable to get current keyboard mode"); |
188 keyboard_fd = -1; | 188 if (keyboard_fd > 0) { |
189 return(-1); | 189 close(keyboard_fd); |
190 } | 190 } |
191 keyboard_termios = saved_kbd_termios; | 191 keyboard_fd = -1; |
192 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); | 192 return (-1); |
193 keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); | 193 } |
194 keyboard_termios.c_cc[VMIN] = 0; | 194 keyboard_termios = saved_kbd_termios; |
195 keyboard_termios.c_cc[VTIME] = 0; | 195 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); |
196 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { | 196 keyboard_termios.c_iflag &= |
197 FB_CloseKeyboard(this); | 197 ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); |
198 SDL_SetError("Unable to set terminal attributes"); | 198 keyboard_termios.c_cc[VMIN] = 0; |
199 return(-1); | 199 keyboard_termios.c_cc[VTIME] = 0; |
200 } | 200 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { |
201 /* This will fail if we aren't root or this isn't our tty */ | 201 FB_CloseKeyboard(this); |
202 if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) { | 202 SDL_SetError("Unable to set terminal attributes"); |
203 FB_CloseKeyboard(this); | 203 return (-1); |
204 SDL_SetError("Unable to set keyboard in raw mode"); | 204 } |
205 return(-1); | 205 /* This will fail if we aren't root or this isn't our tty */ |
206 } | 206 if (ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0) { |
207 if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) { | 207 FB_CloseKeyboard(this); |
208 FB_CloseKeyboard(this); | 208 SDL_SetError("Unable to set keyboard in raw mode"); |
209 SDL_SetError("Unable to set keyboard in graphics mode"); | 209 return (-1); |
210 return(-1); | 210 } |
211 } | 211 if (ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0) { |
212 /* Prevent switching the virtual terminal */ | 212 FB_CloseKeyboard(this); |
213 ioctl(keyboard_fd, VT_LOCKSWITCH, 1); | 213 SDL_SetError("Unable to set keyboard in graphics mode"); |
214 } | 214 return (-1); |
215 return(keyboard_fd); | 215 } |
216 } | 216 /* Prevent switching the virtual terminal */ |
217 | 217 ioctl(keyboard_fd, VT_LOCKSWITCH, 1); |
218 void FB_LeaveGraphicsMode(_THIS) | 218 } |
219 { | 219 return (keyboard_fd); |
220 if ( FB_InGraphicsMode(this) ) { | 220 } |
221 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); | 221 |
222 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); | 222 void |
223 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); | 223 FB_LeaveGraphicsMode(_THIS) |
224 saved_kbd_mode = -1; | 224 { |
225 | 225 if (FB_InGraphicsMode(this)) { |
226 /* Head back over to the original virtual terminal */ | 226 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
227 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); | 227 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); |
228 if ( saved_vt > 0 ) { | 228 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); |
229 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); | 229 saved_kbd_mode = -1; |
230 } | 230 |
231 } | 231 /* Head back over to the original virtual terminal */ |
232 } | 232 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); |
233 | 233 if (saved_vt > 0) { |
234 void FB_CloseKeyboard(_THIS) | 234 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); |
235 { | 235 } |
236 if ( keyboard_fd >= 0 ) { | 236 } |
237 FB_LeaveGraphicsMode(this); | 237 } |
238 if ( keyboard_fd > 0 ) { | 238 |
239 close(keyboard_fd); | 239 void |
240 } | 240 FB_CloseKeyboard(_THIS) |
241 } | 241 { |
242 keyboard_fd = -1; | 242 if (keyboard_fd >= 0) { |
243 } | 243 FB_LeaveGraphicsMode(this); |
244 | 244 if (keyboard_fd > 0) { |
245 int FB_OpenKeyboard(_THIS) | 245 close(keyboard_fd); |
246 { | 246 } |
247 /* Open only if not already opened */ | 247 } |
248 if ( keyboard_fd < 0 ) { | 248 keyboard_fd = -1; |
249 static const char * const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; | 249 } |
250 static const char * const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; | 250 |
251 int i, tty0_fd; | 251 int |
252 | 252 FB_OpenKeyboard(_THIS) |
253 /* Try to query for a free virtual terminal */ | 253 { |
254 tty0_fd = -1; | 254 /* Open only if not already opened */ |
255 for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) { | 255 if (keyboard_fd < 0) { |
256 tty0_fd = open(tty0[i], O_WRONLY, 0); | 256 static const char *const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; |
257 } | 257 static const char *const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; |
258 if ( tty0_fd < 0 ) { | 258 int i, tty0_fd; |
259 tty0_fd = dup(0); /* Maybe stdin is a VT? */ | 259 |
260 } | 260 /* Try to query for a free virtual terminal */ |
261 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); | 261 tty0_fd = -1; |
262 close(tty0_fd); | 262 for (i = 0; tty0[i] && (tty0_fd < 0); ++i) { |
263 if ( (geteuid() == 0) && (current_vt > 0) ) { | 263 tty0_fd = open(tty0[i], O_WRONLY, 0); |
264 for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) { | 264 } |
265 char vtpath[12]; | 265 if (tty0_fd < 0) { |
266 | 266 tty0_fd = dup(0); /* Maybe stdin is a VT? */ |
267 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt); | 267 } |
268 keyboard_fd = open(vtpath, O_RDWR, 0); | 268 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); |
269 close(tty0_fd); | |
270 if ((geteuid() == 0) && (current_vt > 0)) { | |
271 for (i = 0; vcs[i] && (keyboard_fd < 0); ++i) { | |
272 char vtpath[12]; | |
273 | |
274 SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], | |
275 current_vt); | |
276 keyboard_fd = open(vtpath, O_RDWR, 0); | |
269 #ifdef DEBUG_KEYBOARD | 277 #ifdef DEBUG_KEYBOARD |
270 fprintf(stderr, "vtpath = %s, fd = %d\n", | 278 fprintf(stderr, "vtpath = %s, fd = %d\n", |
271 vtpath, keyboard_fd); | 279 vtpath, keyboard_fd); |
272 #endif /* DEBUG_KEYBOARD */ | 280 #endif /* DEBUG_KEYBOARD */ |
273 | 281 |
274 /* This needs to be our controlling tty | 282 /* This needs to be our controlling tty |
275 so that the kernel ioctl() calls work | 283 so that the kernel ioctl() calls work |
276 */ | 284 */ |
277 if ( keyboard_fd >= 0 ) { | 285 if (keyboard_fd >= 0) { |
278 tty0_fd = open("/dev/tty", O_RDWR, 0); | 286 tty0_fd = open("/dev/tty", O_RDWR, 0); |
279 if ( tty0_fd >= 0 ) { | 287 if (tty0_fd >= 0) { |
280 ioctl(tty0_fd, TIOCNOTTY, 0); | 288 ioctl(tty0_fd, TIOCNOTTY, 0); |
281 close(tty0_fd); | 289 close(tty0_fd); |
282 } | 290 } |
283 } | 291 } |
284 } | 292 } |
285 } | 293 } |
286 if ( keyboard_fd < 0 ) { | 294 if (keyboard_fd < 0) { |
287 /* Last resort, maybe our tty is a usable VT */ | 295 /* Last resort, maybe our tty is a usable VT */ |
288 struct vt_stat vtstate; | 296 struct vt_stat vtstate; |
289 | 297 |
290 keyboard_fd = open("/dev/tty", O_RDWR); | 298 keyboard_fd = open("/dev/tty", O_RDWR); |
291 | 299 |
292 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) { | 300 if (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) { |
293 current_vt = vtstate.v_active; | 301 current_vt = vtstate.v_active; |
294 } else { | 302 } else { |
295 current_vt = 0; | 303 current_vt = 0; |
296 } | 304 } |
297 } | 305 } |
298 #ifdef DEBUG_KEYBOARD | 306 #ifdef DEBUG_KEYBOARD |
299 fprintf(stderr, "Current VT: %d\n", current_vt); | 307 fprintf(stderr, "Current VT: %d\n", current_vt); |
300 #endif | 308 #endif |
301 saved_kbd_mode = -1; | 309 saved_kbd_mode = -1; |
302 | 310 |
303 /* Make sure that our input is a console terminal */ | 311 /* Make sure that our input is a console terminal */ |
304 { int dummy; | 312 { |
305 if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) { | 313 int dummy; |
306 close(keyboard_fd); | 314 if (ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0) { |
307 keyboard_fd = -1; | 315 close(keyboard_fd); |
308 SDL_SetError("Unable to open a console terminal"); | 316 keyboard_fd = -1; |
309 } | 317 SDL_SetError("Unable to open a console terminal"); |
310 } | 318 } |
311 | 319 } |
312 /* Set up keymap */ | 320 |
313 FB_vgainitkeymaps(keyboard_fd); | 321 /* Set up keymap */ |
314 } | 322 FB_vgainitkeymaps(keyboard_fd); |
315 return(keyboard_fd); | 323 } |
316 } | 324 return (keyboard_fd); |
317 | 325 } |
318 static enum { | 326 |
319 MOUSE_NONE = -1, | 327 static enum |
320 MOUSE_MSC, /* Note: GPM uses the MSC protocol */ | 328 { |
321 MOUSE_PS2, | 329 MOUSE_NONE = -1, |
322 MOUSE_IMPS2, | 330 MOUSE_MSC, /* Note: GPM uses the MSC protocol */ |
323 MOUSE_MS, | 331 MOUSE_PS2, |
324 MOUSE_BM, | 332 MOUSE_IMPS2, |
325 MOUSE_ELO, | 333 MOUSE_MS, |
326 MOUSE_TSLIB, | 334 MOUSE_BM, |
327 NUM_MOUSE_DRVS | 335 MOUSE_ELO, |
336 MOUSE_TSLIB, | |
337 NUM_MOUSE_DRVS | |
328 } mouse_drv = MOUSE_NONE; | 338 } mouse_drv = MOUSE_NONE; |
329 | 339 |
330 void FB_CloseMouse(_THIS) | 340 void |
341 FB_CloseMouse(_THIS) | |
331 { | 342 { |
332 #if SDL_INPUT_TSLIB | 343 #if SDL_INPUT_TSLIB |
333 if (ts_dev != NULL) { | 344 if (ts_dev != NULL) { |
334 ts_close(ts_dev); | 345 ts_close(ts_dev); |
335 ts_dev = NULL; | 346 ts_dev = NULL; |
336 mouse_fd = -1; | 347 mouse_fd = -1; |
337 } | 348 } |
338 #endif /* SDL_INPUT_TSLIB */ | 349 #endif /* SDL_INPUT_TSLIB */ |
339 if ( mouse_fd > 0 ) { | 350 if (mouse_fd > 0) { |
340 close(mouse_fd); | 351 close(mouse_fd); |
341 } | 352 } |
342 mouse_fd = -1; | 353 mouse_fd = -1; |
343 } | 354 } |
344 | 355 |
345 /* Returns processes listed in /proc with the desired name */ | 356 /* Returns processes listed in /proc with the desired name */ |
346 static int find_pid(DIR *proc, const char *wanted_name) | 357 static int |
347 { | 358 find_pid(DIR * proc, const char *wanted_name) |
348 struct dirent *entry; | 359 { |
349 int pid; | 360 struct dirent *entry; |
350 | 361 int pid; |
351 /* First scan proc for the gpm process */ | 362 |
352 pid = 0; | 363 /* First scan proc for the gpm process */ |
353 while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) { | 364 pid = 0; |
354 if ( isdigit(entry->d_name[0]) ) { | 365 while ((pid == 0) && ((entry = readdir(proc)) != NULL)) { |
355 FILE *status; | 366 if (isdigit(entry->d_name[0])) { |
356 char path[PATH_MAX]; | 367 FILE *status; |
357 char name[PATH_MAX]; | 368 char path[PATH_MAX]; |
358 | 369 char name[PATH_MAX]; |
359 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name); | 370 |
360 status=fopen(path, "r"); | 371 SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", |
361 if ( status ) { | 372 entry->d_name); |
362 name[0] = '\0'; | 373 status = fopen(path, "r"); |
363 fscanf(status, "Name: %s", name); | 374 if (status) { |
364 if ( SDL_strcmp(name, wanted_name) == 0 ) { | 375 name[0] = '\0'; |
365 pid = SDL_atoi(entry->d_name); | 376 fscanf(status, "Name: %s", name); |
366 } | 377 if (SDL_strcmp(name, wanted_name) == 0) { |
367 fclose(status); | 378 pid = SDL_atoi(entry->d_name); |
368 } | 379 } |
369 } | 380 fclose(status); |
370 } | 381 } |
371 return pid; | 382 } |
383 } | |
384 return pid; | |
372 } | 385 } |
373 | 386 |
374 /* Returns true if /dev/gpmdata is being written to by gpm */ | 387 /* Returns true if /dev/gpmdata is being written to by gpm */ |
375 static int gpm_available(char *proto, size_t protolen) | 388 static int |
376 { | 389 gpm_available(char *proto, size_t protolen) |
377 int available; | 390 { |
378 DIR *proc; | 391 int available; |
379 int pid; | 392 DIR *proc; |
380 int cmdline, len, arglen; | 393 int pid; |
381 char path[PATH_MAX]; | 394 int cmdline, len, arglen; |
382 char args[PATH_MAX], *arg; | 395 char path[PATH_MAX]; |
383 | 396 char args[PATH_MAX], *arg; |
384 /* Don't bother looking if the fifo isn't there */ | 397 |
385 #ifdef DEBUG_MOUSE | 398 /* Don't bother looking if the fifo isn't there */ |
386 fprintf(stderr,"testing gpm\n"); | 399 #ifdef DEBUG_MOUSE |
387 #endif | 400 fprintf(stderr, "testing gpm\n"); |
388 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { | 401 #endif |
389 return(0); | 402 if (access(GPM_NODE_FIFO, F_OK) < 0) { |
390 } | 403 return (0); |
391 | 404 } |
392 available = 0; | 405 |
393 proc = opendir("/proc"); | 406 available = 0; |
394 if ( proc ) { | 407 proc = opendir("/proc"); |
395 char raw_proto[10] = { '\0' }; | 408 if (proc) { |
396 char repeat_proto[10] = { '\0' }; | 409 char raw_proto[10] = { '\0' }; |
397 while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) { | 410 char repeat_proto[10] = { '\0' }; |
398 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); | 411 while (!available && (pid = find_pid(proc, "gpm")) > 0) { |
399 cmdline = open(path, O_RDONLY, 0); | 412 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); |
400 if ( cmdline >= 0 ) { | 413 cmdline = open(path, O_RDONLY, 0); |
401 len = read(cmdline, args, sizeof(args)); | 414 if (cmdline >= 0) { |
402 arg = args; | 415 len = read(cmdline, args, sizeof(args)); |
403 while ( len > 0 ) { | 416 arg = args; |
404 arglen = SDL_strlen(arg)+1; | 417 while (len > 0) { |
405 #ifdef DEBUG_MOUSE | 418 arglen = SDL_strlen(arg) + 1; |
406 fprintf(stderr,"gpm arg %s len %d\n",arg,arglen); | 419 #ifdef DEBUG_MOUSE |
407 #endif | 420 fprintf(stderr, "gpm arg %s len %d\n", arg, arglen); |
408 if ( SDL_strcmp(arg, "-t") == 0) { | 421 #endif |
409 /* protocol string, keep it for later */ | 422 if (SDL_strcmp(arg, "-t") == 0) { |
410 char *t, *s; | 423 /* protocol string, keep it for later */ |
411 t = arg + arglen; | 424 char *t, *s; |
412 s = SDL_strchr(t, ' '); | 425 t = arg + arglen; |
413 if (s) *s = 0; | 426 s = SDL_strchr(t, ' '); |
414 SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto)); | 427 if (s) |
415 if (s) *s = ' '; | 428 *s = 0; |
416 } | 429 SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto)); |
417 if ( SDL_strncmp(arg, "-R", 2) == 0 ) { | 430 if (s) |
418 char *t, *s; | 431 *s = ' '; |
419 available = 1; | 432 } |
420 t = arg + 2; | 433 if (SDL_strncmp(arg, "-R", 2) == 0) { |
421 s = SDL_strchr(t, ' '); | 434 char *t, *s; |
422 if (s) *s = 0; | 435 available = 1; |
423 SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto)); | 436 t = arg + 2; |
424 if (s) *s = ' '; | 437 s = SDL_strchr(t, ' '); |
425 } | 438 if (s) |
426 len -= arglen; | 439 *s = 0; |
427 arg += arglen; | 440 SDL_strlcpy(repeat_proto, t, |
428 } | 441 SDL_arraysize(repeat_proto)); |
429 close(cmdline); | 442 if (s) |
430 } | 443 *s = ' '; |
431 } | 444 } |
432 closedir(proc); | 445 len -= arglen; |
433 | 446 arg += arglen; |
434 if ( available ) { | 447 } |
435 if ( SDL_strcmp(repeat_proto, "raw") == 0 ) { | 448 close(cmdline); |
436 SDL_strlcpy(proto, raw_proto, protolen); | 449 } |
437 } else if ( *repeat_proto ) { | 450 } |
438 SDL_strlcpy(proto, repeat_proto, protolen); | 451 closedir(proc); |
439 } else { | 452 |
440 SDL_strlcpy(proto, "msc", protolen); | 453 if (available) { |
441 } | 454 if (SDL_strcmp(repeat_proto, "raw") == 0) { |
442 } | 455 SDL_strlcpy(proto, raw_proto, protolen); |
443 } | 456 } else if (*repeat_proto) { |
444 return available; | 457 SDL_strlcpy(proto, repeat_proto, protolen); |
458 } else { | |
459 SDL_strlcpy(proto, "msc", protolen); | |
460 } | |
461 } | |
462 } | |
463 return available; | |
445 } | 464 } |
446 | 465 |
447 | 466 |
448 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives | 467 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives |
449 * us access to the mousewheel, etc. Returns zero if | 468 * us access to the mousewheel, etc. Returns zero if |
450 * writes to device failed, but you still need to query the | 469 * writes to device failed, but you still need to query the |
451 * device to see which mode it's actually in. | 470 * device to see which mode it's actually in. |
452 */ | 471 */ |
453 static int set_imps2_mode(int fd) | 472 static int |
454 { | 473 set_imps2_mode(int fd) |
455 /* If you wanted to control the mouse mode (and we do :) ) ... | 474 { |
456 Set IMPS/2 protocol: | 475 /* If you wanted to control the mouse mode (and we do :) ) ... |
457 {0xf3,200,0xf3,100,0xf3,80} | 476 Set IMPS/2 protocol: |
458 Reset mouse device: | 477 {0xf3,200,0xf3,100,0xf3,80} |
459 {0xFF} | 478 Reset mouse device: |
460 */ | 479 {0xFF} |
461 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80}; | 480 */ |
462 /*Uint8 reset = 0xff;*/ | 481 Uint8 set_imps2[] = { 0xf3, 200, 0xf3, 100, 0xf3, 80 }; |
463 fd_set fdset; | 482 /*Uint8 reset = 0xff; */ |
464 struct timeval tv; | 483 fd_set fdset; |
465 int retval = 0; | 484 struct timeval tv; |
466 | 485 int retval = 0; |
467 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) { | 486 |
468 /* Don't reset it, that'll clear IMPS/2 mode on some mice | 487 if (write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2)) { |
469 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { | 488 /* Don't reset it, that'll clear IMPS/2 mode on some mice |
470 retval = 1; | 489 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { |
471 } | 490 retval = 1; |
472 */ | 491 } |
473 } | 492 */ |
474 | 493 } |
475 /* Get rid of any chatter from the above */ | 494 |
476 FD_ZERO(&fdset); | 495 /* Get rid of any chatter from the above */ |
477 FD_SET(fd, &fdset); | 496 FD_ZERO(&fdset); |
478 tv.tv_sec = 0; | 497 FD_SET(fd, &fdset); |
479 tv.tv_usec = 0; | 498 tv.tv_sec = 0; |
480 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | 499 tv.tv_usec = 0; |
481 char temp[32]; | 500 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
482 read(fd, temp, sizeof(temp)); | 501 char temp[32]; |
483 } | 502 read(fd, temp, sizeof(temp)); |
484 | 503 } |
485 return retval; | 504 |
505 return retval; | |
486 } | 506 } |
487 | 507 |
488 | 508 |
489 /* Returns true if the mouse uses the IMPS/2 protocol */ | 509 /* Returns true if the mouse uses the IMPS/2 protocol */ |
490 static int detect_imps2(int fd) | 510 static int |
491 { | 511 detect_imps2(int fd) |
492 int imps2; | 512 { |
493 | 513 int imps2; |
494 imps2 = 0; | 514 |
495 | 515 imps2 = 0; |
496 if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) { | 516 |
497 imps2 = 1; | 517 if (SDL_getenv("SDL_MOUSEDEV_IMPS2")) { |
498 } | 518 imps2 = 1; |
499 if ( ! imps2 ) { | 519 } |
500 Uint8 query_ps2 = 0xF2; | 520 if (!imps2) { |
501 fd_set fdset; | 521 Uint8 query_ps2 = 0xF2; |
502 struct timeval tv; | 522 fd_set fdset; |
503 | 523 struct timeval tv; |
504 /* Get rid of any mouse motion noise */ | 524 |
505 FD_ZERO(&fdset); | 525 /* Get rid of any mouse motion noise */ |
506 FD_SET(fd, &fdset); | 526 FD_ZERO(&fdset); |
507 tv.tv_sec = 0; | 527 FD_SET(fd, &fdset); |
508 tv.tv_usec = 0; | 528 tv.tv_sec = 0; |
509 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | 529 tv.tv_usec = 0; |
510 char temp[32]; | 530 while (select(fd + 1, &fdset, 0, 0, &tv) > 0) { |
511 read(fd, temp, sizeof(temp)); | 531 char temp[32]; |
512 } | 532 read(fd, temp, sizeof(temp)); |
513 | 533 } |
514 /* Query for the type of mouse protocol */ | 534 |
515 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { | 535 /* Query for the type of mouse protocol */ |
516 Uint8 ch = 0; | 536 if (write(fd, &query_ps2, sizeof(query_ps2)) == sizeof(query_ps2)) { |
517 | 537 Uint8 ch = 0; |
518 /* Get the mouse protocol response */ | 538 |
519 do { | 539 /* Get the mouse protocol response */ |
520 FD_ZERO(&fdset); | 540 do { |
521 FD_SET(fd, &fdset); | 541 FD_ZERO(&fdset); |
522 tv.tv_sec = 1; | 542 FD_SET(fd, &fdset); |
523 tv.tv_usec = 0; | 543 tv.tv_sec = 1; |
524 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) { | 544 tv.tv_usec = 0; |
525 break; | 545 if (select(fd + 1, &fdset, 0, 0, &tv) < 1) { |
526 } | 546 break; |
527 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) && | 547 } |
528 ((ch == 0xFA) || (ch == 0xAA)) ); | 548 } |
529 | 549 while ((read(fd, &ch, sizeof(ch)) == sizeof(ch)) && |
530 /* Experimental values (Logitech wheelmouse) */ | 550 ((ch == 0xFA) || (ch == 0xAA))); |
551 | |
552 /* Experimental values (Logitech wheelmouse) */ | |
531 #ifdef DEBUG_MOUSE | 553 #ifdef DEBUG_MOUSE |
532 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); | 554 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); |
533 #endif | 555 #endif |
534 if ( (ch == 3) || (ch == 4) ) { | 556 if ((ch == 3) || (ch == 4)) { |
535 imps2 = 1; | 557 imps2 = 1; |
536 } | 558 } |
537 } | 559 } |
538 } | 560 } |
539 return imps2; | 561 return imps2; |
540 } | 562 } |
541 | 563 |
542 int FB_OpenMouse(_THIS) | 564 int |
543 { | 565 FB_OpenMouse(_THIS) |
544 int i; | 566 { |
545 const char *mousedev; | 567 int i; |
546 const char *mousedrv; | 568 const char *mousedev; |
547 | 569 const char *mousedrv; |
548 mousedrv = SDL_getenv("SDL_MOUSEDRV"); | 570 |
549 mousedev = SDL_getenv("SDL_MOUSEDEV"); | 571 mousedrv = SDL_getenv("SDL_MOUSEDRV"); |
550 mouse_fd = -1; | 572 mousedev = SDL_getenv("SDL_MOUSEDEV"); |
573 mouse_fd = -1; | |
551 | 574 |
552 #if SDL_INPUT_TSLIB | 575 #if SDL_INPUT_TSLIB |
553 if ( mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0) ) { | 576 if (mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0)) { |
554 if (mousedev == NULL) mousedev = SDL_getenv("TSLIB_TSDEVICE"); | 577 if (mousedev == NULL) |
555 if (mousedev != NULL) { | 578 mousedev = SDL_getenv("TSLIB_TSDEVICE"); |
556 ts_dev = ts_open(mousedev, 1); | 579 if (mousedev != NULL) { |
557 if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) { | 580 ts_dev = ts_open(mousedev, 1); |
581 if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) { | |
558 #ifdef DEBUG_MOUSE | 582 #ifdef DEBUG_MOUSE |
559 fprintf(stderr, "Using tslib touchscreen\n"); | 583 fprintf(stderr, "Using tslib touchscreen\n"); |
560 #endif | 584 #endif |
561 mouse_drv = MOUSE_TSLIB; | 585 mouse_drv = MOUSE_TSLIB; |
562 mouse_fd = ts_fd(ts_dev); | 586 mouse_fd = ts_fd(ts_dev); |
563 return mouse_fd; | 587 return mouse_fd; |
564 } | 588 } |
565 } | 589 } |
566 mouse_drv = MOUSE_NONE; | 590 mouse_drv = MOUSE_NONE; |
567 return mouse_fd; | 591 return mouse_fd; |
568 } | 592 } |
569 #endif /* SDL_INPUT_TSLIB */ | 593 #endif /* SDL_INPUT_TSLIB */ |
570 | 594 |
571 /* ELO TOUCHSCREEN SUPPORT */ | 595 /* ELO TOUCHSCREEN SUPPORT */ |
572 | 596 |
573 if ( mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0) ) { | 597 if (mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0)) { |
574 mouse_fd = open(mousedev, O_RDWR); | 598 mouse_fd = open(mousedev, O_RDWR); |
575 if ( mouse_fd >= 0 ) { | 599 if (mouse_fd >= 0) { |
576 if(eloInitController(mouse_fd)) { | 600 if (eloInitController(mouse_fd)) { |
577 #ifdef DEBUG_MOUSE | 601 #ifdef DEBUG_MOUSE |
578 fprintf(stderr, "Using ELO touchscreen\n"); | 602 fprintf(stderr, "Using ELO touchscreen\n"); |
579 #endif | 603 #endif |
580 mouse_drv = MOUSE_ELO; | 604 mouse_drv = MOUSE_ELO; |
581 } | 605 } |
582 | 606 |
583 } | 607 } else if (mouse_fd < 0) { |
584 else if ( mouse_fd < 0 ) { | 608 mouse_drv = MOUSE_NONE; |
585 mouse_drv = MOUSE_NONE; | 609 } |
586 } | 610 |
587 | 611 return (mouse_fd); |
588 return(mouse_fd); | 612 } |
589 } | 613 |
590 | 614 /* STD MICE */ |
591 /* STD MICE */ | 615 |
592 | 616 if (mousedev == NULL) { |
593 if ( mousedev == NULL ) { | 617 /* FIXME someday... allow multiple mice in this driver */ |
594 /* FIXME someday... allow multiple mice in this driver */ | 618 static const char *ps2mice[] = { |
595 static const char *ps2mice[] = { | 619 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL |
596 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL | 620 }; |
597 }; | 621 /* First try to use GPM in repeater mode */ |
598 /* First try to use GPM in repeater mode */ | 622 if (mouse_fd < 0) { |
599 if ( mouse_fd < 0 ) { | 623 char proto[10]; |
600 char proto[10]; | 624 if (gpm_available(proto, SDL_arraysize(proto))) { |
601 if ( gpm_available(proto, SDL_arraysize(proto)) ) { | 625 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); |
602 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); | 626 if (mouse_fd >= 0) { |
603 if ( mouse_fd >= 0 ) { | 627 if (SDL_strcmp(proto, "msc") == 0) { |
604 if ( SDL_strcmp(proto, "msc") == 0 ) { | 628 mouse_drv = MOUSE_MSC; |
605 mouse_drv = MOUSE_MSC; | 629 } else if (SDL_strcmp(proto, "ps2") == 0) { |
606 } else if ( SDL_strcmp(proto, "ps2") == 0 ) { | 630 mouse_drv = MOUSE_PS2; |
607 mouse_drv = MOUSE_PS2; | 631 } else if (SDL_strcmp(proto, "imps2") == 0) { |
608 } else if ( SDL_strcmp(proto, "imps2") == 0 ) { | 632 mouse_drv = MOUSE_IMPS2; |
609 mouse_drv = MOUSE_IMPS2; | 633 } else if (SDL_strcmp(proto, "ms") == 0 || |
610 } else if ( SDL_strcmp(proto, "ms") == 0 || | 634 SDL_strcmp(proto, "bare") == 0) { |
611 SDL_strcmp(proto, "bare") == 0 ) { | 635 mouse_drv = MOUSE_MS; |
612 mouse_drv = MOUSE_MS; | 636 } else if (SDL_strcmp(proto, "bm") == 0) { |
613 } else if ( SDL_strcmp(proto, "bm") == 0 ) { | 637 mouse_drv = MOUSE_BM; |
614 mouse_drv = MOUSE_BM; | 638 } else { |
615 } else { | 639 /* Unknown protocol... */ |
616 /* Unknown protocol... */ | |
617 #ifdef DEBUG_MOUSE | 640 #ifdef DEBUG_MOUSE |
618 fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto); | 641 fprintf(stderr, |
619 #endif | 642 "GPM mouse using unknown protocol = %s\n", |
620 close(mouse_fd); | 643 proto); |
621 mouse_fd = -1; | 644 #endif |
622 } | 645 close(mouse_fd); |
623 } | 646 mouse_fd = -1; |
647 } | |
648 } | |
624 #ifdef DEBUG_MOUSE | 649 #ifdef DEBUG_MOUSE |
625 if ( mouse_fd >= 0 ) { | 650 if (mouse_fd >= 0) { |
626 fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto); | 651 fprintf(stderr, |
627 } | 652 "Using GPM mouse, protocol = %s\n", proto); |
653 } | |
628 #endif /* DEBUG_MOUSE */ | 654 #endif /* DEBUG_MOUSE */ |
629 } | 655 } |
630 } | 656 } |
631 /* Now try to use a modern PS/2 mouse */ | 657 /* Now try to use a modern PS/2 mouse */ |
632 for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) { | 658 for (i = 0; (mouse_fd < 0) && ps2mice[i]; ++i) { |
633 mouse_fd = open(ps2mice[i], O_RDWR, 0); | 659 mouse_fd = open(ps2mice[i], O_RDWR, 0); |
634 if (mouse_fd < 0) { | 660 if (mouse_fd < 0) { |
635 mouse_fd = open(ps2mice[i], O_RDONLY, 0); | 661 mouse_fd = open(ps2mice[i], O_RDONLY, 0); |
636 } | 662 } |
637 if (mouse_fd >= 0) { | 663 if (mouse_fd >= 0) { |
638 /* rcg06112001 Attempt to set IMPS/2 mode */ | 664 /* rcg06112001 Attempt to set IMPS/2 mode */ |
639 set_imps2_mode(mouse_fd); | 665 set_imps2_mode(mouse_fd); |
640 if (detect_imps2(mouse_fd)) { | 666 if (detect_imps2(mouse_fd)) { |
641 #ifdef DEBUG_MOUSE | 667 #ifdef DEBUG_MOUSE |
642 fprintf(stderr, "Using IMPS2 mouse\n"); | 668 fprintf(stderr, "Using IMPS2 mouse\n"); |
643 #endif | 669 #endif |
644 mouse_drv = MOUSE_IMPS2; | 670 mouse_drv = MOUSE_IMPS2; |
645 } else { | 671 } else { |
646 #ifdef DEBUG_MOUSE | 672 #ifdef DEBUG_MOUSE |
647 fprintf(stderr, "Using PS2 mouse\n"); | 673 fprintf(stderr, "Using PS2 mouse\n"); |
648 #endif | 674 #endif |
649 mouse_drv = MOUSE_PS2; | 675 mouse_drv = MOUSE_PS2; |
650 } | 676 } |
651 } | 677 } |
652 } | 678 } |
653 /* Next try to use a PPC ADB port mouse */ | 679 /* Next try to use a PPC ADB port mouse */ |
654 if ( mouse_fd < 0 ) { | 680 if (mouse_fd < 0) { |
655 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); | 681 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); |
656 if ( mouse_fd >= 0 ) { | 682 if (mouse_fd >= 0) { |
657 #ifdef DEBUG_MOUSE | 683 #ifdef DEBUG_MOUSE |
658 fprintf(stderr, "Using ADB mouse\n"); | 684 fprintf(stderr, "Using ADB mouse\n"); |
659 #endif | 685 #endif |
660 mouse_drv = MOUSE_BM; | 686 mouse_drv = MOUSE_BM; |
661 } | 687 } |
662 } | 688 } |
663 } | 689 } |
664 /* Default to a serial Microsoft mouse */ | 690 /* Default to a serial Microsoft mouse */ |
665 if ( mouse_fd < 0 ) { | 691 if (mouse_fd < 0) { |
666 if ( mousedev == NULL ) { | 692 if (mousedev == NULL) { |
667 mousedev = "/dev/mouse"; | 693 mousedev = "/dev/mouse"; |
668 } | 694 } |
669 mouse_fd = open(mousedev, O_RDONLY, 0); | 695 mouse_fd = open(mousedev, O_RDONLY, 0); |
670 if ( mouse_fd >= 0 ) { | 696 if (mouse_fd >= 0) { |
671 struct termios mouse_termios; | 697 struct termios mouse_termios; |
672 | 698 |
673 /* Set the sampling speed to 1200 baud */ | 699 /* Set the sampling speed to 1200 baud */ |
674 tcgetattr(mouse_fd, &mouse_termios); | 700 tcgetattr(mouse_fd, &mouse_termios); |
675 mouse_termios.c_iflag = IGNBRK | IGNPAR; | 701 mouse_termios.c_iflag = IGNBRK | IGNPAR; |
676 mouse_termios.c_oflag = 0; | 702 mouse_termios.c_oflag = 0; |
677 mouse_termios.c_lflag = 0; | 703 mouse_termios.c_lflag = 0; |
678 mouse_termios.c_line = 0; | 704 mouse_termios.c_line = 0; |
679 mouse_termios.c_cc[VTIME] = 0; | 705 mouse_termios.c_cc[VTIME] = 0; |
680 mouse_termios.c_cc[VMIN] = 1; | 706 mouse_termios.c_cc[VMIN] = 1; |
681 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; | 707 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; |
682 mouse_termios.c_cflag |= CS8; | 708 mouse_termios.c_cflag |= CS8; |
683 mouse_termios.c_cflag |= B1200; | 709 mouse_termios.c_cflag |= B1200; |
684 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); | 710 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); |
685 if ( mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0) ) { | 711 if (mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0)) { |
686 #ifdef DEBUG_MOUSE | 712 #ifdef DEBUG_MOUSE |
687 fprintf(stderr, "Using (user specified) PS2 mouse on %s\n", mousedev); | 713 fprintf(stderr, |
688 #endif | 714 "Using (user specified) PS2 mouse on %s\n", mousedev); |
689 mouse_drv = MOUSE_PS2; | 715 #endif |
690 } else { | 716 mouse_drv = MOUSE_PS2; |
717 } else { | |
691 #ifdef DEBUG_MOUSE | 718 #ifdef DEBUG_MOUSE |
692 fprintf(stderr, "Using (default) MS mouse on %s\n", mousedev); | 719 fprintf(stderr, "Using (default) MS mouse on %s\n", mousedev); |
693 #endif | 720 #endif |
694 mouse_drv = MOUSE_MS; | 721 mouse_drv = MOUSE_MS; |
695 } | 722 } |
696 } | 723 } |
697 } | 724 } |
698 if ( mouse_fd < 0 ) { | 725 if (mouse_fd < 0) { |
699 mouse_drv = MOUSE_NONE; | 726 mouse_drv = MOUSE_NONE; |
700 } | 727 } |
701 return(mouse_fd); | 728 return (mouse_fd); |
702 } | 729 } |
703 | 730 |
704 static int posted = 0; | 731 static int posted = 0; |
705 | 732 |
706 void FB_vgamousecallback(int button, int relative, int dx, int dy) | 733 void |
707 { | 734 FB_vgamousecallback(int button, int relative, int dx, int dy) |
708 int button_1, button_3; | 735 { |
709 int button_state; | 736 int button_1, button_3; |
710 int state_changed; | 737 int button_state; |
711 int i; | 738 int state_changed; |
712 Uint8 state; | 739 int i; |
713 | 740 Uint8 state; |
714 if ( dx || dy ) { | 741 |
715 posted += SDL_PrivateMouseMotion(0, relative, dx, dy); | 742 if (dx || dy) { |
716 } | 743 posted += SDL_PrivateMouseMotion(0, relative, dx, dy); |
717 | 744 } |
718 /* Swap button 1 and 3 */ | 745 |
719 button_1 = (button & 0x04) >> 2; | 746 /* Swap button 1 and 3 */ |
720 button_3 = (button & 0x01) << 2; | 747 button_1 = (button & 0x04) >> 2; |
721 button &= ~0x05; | 748 button_3 = (button & 0x01) << 2; |
722 button |= (button_1|button_3); | 749 button &= ~0x05; |
723 | 750 button |= (button_1 | button_3); |
724 /* See what changed */ | 751 |
725 button_state = SDL_GetMouseState(NULL, NULL); | 752 /* See what changed */ |
726 state_changed = button_state ^ button; | 753 button_state = SDL_GetMouseState(NULL, NULL); |
727 for ( i=0; i<8; ++i ) { | 754 state_changed = button_state ^ button; |
728 if ( state_changed & (1<<i) ) { | 755 for (i = 0; i < 8; ++i) { |
729 if ( button & (1<<i) ) { | 756 if (state_changed & (1 << i)) { |
730 state = SDL_PRESSED; | 757 if (button & (1 << i)) { |
731 } else { | 758 state = SDL_PRESSED; |
732 state = SDL_RELEASED; | 759 } else { |
733 } | 760 state = SDL_RELEASED; |
734 posted += SDL_PrivateMouseButton(state, i+1, 0, 0); | 761 } |
735 } | 762 posted += SDL_PrivateMouseButton(state, i + 1, 0, 0); |
736 } | 763 } |
764 } | |
737 } | 765 } |
738 | 766 |
739 /* Handle input from tslib */ | 767 /* Handle input from tslib */ |
740 #if SDL_INPUT_TSLIB | 768 #if SDL_INPUT_TSLIB |
741 static void handle_tslib(_THIS) | 769 static void |
742 { | 770 handle_tslib(_THIS) |
743 struct ts_sample sample; | 771 { |
744 int button; | 772 struct ts_sample sample; |
745 | 773 int button; |
746 while (ts_read(ts_dev, &sample, 1) > 0) { | 774 |
747 button = (sample.pressure > 0) ? 1 : 0; | 775 while (ts_read(ts_dev, &sample, 1) > 0) { |
748 button <<= 2; /* must report it as button 3 */ | 776 button = (sample.pressure > 0) ? 1 : 0; |
749 FB_vgamousecallback(button, 0, sample.x, sample.y); | 777 button <<= 2; /* must report it as button 3 */ |
750 } | 778 FB_vgamousecallback(button, 0, sample.x, sample.y); |
751 return; | 779 } |
780 return; | |
752 } | 781 } |
753 #endif /* SDL_INPUT_TSLIB */ | 782 #endif /* SDL_INPUT_TSLIB */ |
754 | 783 |
755 /* For now, use MSC, PS/2, and MS protocols | 784 /* For now, use MSC, PS/2, and MS protocols |
756 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) | 785 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) |
757 */ | 786 */ |
758 static void handle_mouse(_THIS) | 787 static void |
759 { | 788 handle_mouse(_THIS) |
760 static int start = 0; | 789 { |
761 static unsigned char mousebuf[BUFSIZ]; | 790 static int start = 0; |
762 static int relative = 1; | 791 static unsigned char mousebuf[BUFSIZ]; |
763 | 792 static int relative = 1; |
764 int i, nread; | 793 |
765 int button = 0; | 794 int i, nread; |
766 int dx = 0, dy = 0; | 795 int button = 0; |
767 int packetsize = 0; | 796 int dx = 0, dy = 0; |
768 int realx, realy; | 797 int packetsize = 0; |
769 | 798 int realx, realy; |
770 /* Figure out the mouse packet size */ | 799 |
771 switch (mouse_drv) { | 800 /* Figure out the mouse packet size */ |
772 case MOUSE_NONE: | 801 switch (mouse_drv) { |
773 /* Ack! */ | 802 case MOUSE_NONE: |
774 read(mouse_fd, mousebuf, BUFSIZ); | 803 /* Ack! */ |
775 return; | 804 read(mouse_fd, mousebuf, BUFSIZ); |
776 case MOUSE_MSC: | 805 return; |
777 packetsize = 5; | 806 case MOUSE_MSC: |
778 break; | 807 packetsize = 5; |
779 case MOUSE_IMPS2: | 808 break; |
780 packetsize = 4; | 809 case MOUSE_IMPS2: |
781 break; | 810 packetsize = 4; |
782 case MOUSE_PS2: | 811 break; |
783 case MOUSE_MS: | 812 case MOUSE_PS2: |
784 case MOUSE_BM: | 813 case MOUSE_MS: |
785 packetsize = 3; | 814 case MOUSE_BM: |
786 break; | 815 packetsize = 3; |
787 case MOUSE_ELO: | 816 break; |
788 /* try to read the next packet */ | 817 case MOUSE_ELO: |
789 if(eloReadPosition(this, mouse_fd, &dx, &dy, &button, &realx, &realy)) { | 818 /* try to read the next packet */ |
790 button = (button & 0x01) << 2; | 819 if (eloReadPosition |
791 FB_vgamousecallback(button, 0, dx, dy); | 820 (this, mouse_fd, &dx, &dy, &button, &realx, &realy)) { |
792 } | 821 button = (button & 0x01) << 2; |
793 return; /* nothing left to do */ | 822 FB_vgamousecallback(button, 0, dx, dy); |
794 case MOUSE_TSLIB: | 823 } |
824 return; /* nothing left to do */ | |
825 case MOUSE_TSLIB: | |
795 #if SDL_INPUT_TSLIB | 826 #if SDL_INPUT_TSLIB |
796 handle_tslib(this); | 827 handle_tslib(this); |
797 #endif | 828 #endif |
798 return; /* nothing left to do */ | 829 return; /* nothing left to do */ |
799 default: | 830 default: |
800 /* Uh oh.. */ | 831 /* Uh oh.. */ |
801 packetsize = 0; | 832 packetsize = 0; |
802 break; | 833 break; |
803 } | 834 } |
804 | 835 |
805 /* Special handling for the quite sensitive ELO controller */ | 836 /* Special handling for the quite sensitive ELO controller */ |
806 if (mouse_drv == MOUSE_ELO) { | 837 if (mouse_drv == MOUSE_ELO) { |
807 | 838 |
808 } | 839 } |
809 | 840 |
810 /* Read as many packets as possible */ | 841 /* Read as many packets as possible */ |
811 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start); | 842 nread = read(mouse_fd, &mousebuf[start], BUFSIZ - start); |
812 if ( nread < 0 ) { | 843 if (nread < 0) { |
813 return; | 844 return; |
814 } | 845 } |
815 nread += start; | 846 nread += start; |
816 #ifdef DEBUG_MOUSE | 847 #ifdef DEBUG_MOUSE |
817 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start); | 848 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start); |
818 #endif | 849 #endif |
819 for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) { | 850 for (i = 0; i < (nread - (packetsize - 1)); i += packetsize) { |
820 switch (mouse_drv) { | 851 switch (mouse_drv) { |
821 case MOUSE_NONE: | 852 case MOUSE_NONE: |
822 break; | 853 break; |
823 case MOUSE_MSC: | 854 case MOUSE_MSC: |
824 /* MSC protocol has 0x80 in high byte */ | 855 /* MSC protocol has 0x80 in high byte */ |
825 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | 856 if ((mousebuf[i] & 0xF8) != 0x80) { |
826 /* Go to next byte */ | 857 /* Go to next byte */ |
827 i -= (packetsize-1); | 858 i -= (packetsize - 1); |
828 continue; | 859 continue; |
829 } | 860 } |
830 /* Get current mouse state */ | 861 /* Get current mouse state */ |
831 button = (~mousebuf[i]) & 0x07; | 862 button = (~mousebuf[i]) & 0x07; |
832 dx = (signed char)(mousebuf[i+1]) + | 863 dx = (signed char) (mousebuf[i + 1]) + |
833 (signed char)(mousebuf[i+3]); | 864 (signed char) (mousebuf[i + 3]); |
834 dy = -((signed char)(mousebuf[i+2]) + | 865 dy = -((signed char) (mousebuf[i + 2]) + |
835 (signed char)(mousebuf[i+4])); | 866 (signed char) (mousebuf[i + 4])); |
836 break; | 867 break; |
837 case MOUSE_PS2: | 868 case MOUSE_PS2: |
838 /* PS/2 protocol has nothing in high byte */ | 869 /* PS/2 protocol has nothing in high byte */ |
839 if ( (mousebuf[i] & 0xC0) != 0 ) { | 870 if ((mousebuf[i] & 0xC0) != 0) { |
840 /* Go to next byte */ | 871 /* Go to next byte */ |
841 i -= (packetsize-1); | 872 i -= (packetsize - 1); |
842 continue; | 873 continue; |
843 } | 874 } |
844 /* Get current mouse state */ | 875 /* Get current mouse state */ |
845 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | 876 button = (mousebuf[i] & 0x04) >> 1 | /*Middle */ |
846 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | 877 (mousebuf[i] & 0x02) >> 1 | /*Right */ |
847 (mousebuf[i] & 0x01) << 2; /*Left*/ | 878 (mousebuf[i] & 0x01) << 2; /*Left */ |
848 dx = (mousebuf[i] & 0x10) ? | 879 dx = (mousebuf[i] & 0x10) ? |
849 mousebuf[i+1] - 256 : mousebuf[i+1]; | 880 mousebuf[i + 1] - 256 : mousebuf[i + 1]; |
850 dy = (mousebuf[i] & 0x20) ? | 881 dy = (mousebuf[i] & 0x20) ? |
851 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | 882 -(mousebuf[i + 2] - 256) : -mousebuf[i + 2]; |
852 break; | 883 break; |
853 case MOUSE_IMPS2: | 884 case MOUSE_IMPS2: |
854 /* Get current mouse state */ | 885 /* Get current mouse state */ |
855 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | 886 button = (mousebuf[i] & 0x04) >> 1 | /*Middle */ |
856 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | 887 (mousebuf[i] & 0x02) >> 1 | /*Right */ |
857 (mousebuf[i] & 0x01) << 2 | /*Left*/ | 888 (mousebuf[i] & 0x01) << 2 | /*Left */ |
858 (mousebuf[i] & 0x40) >> 3 | /* 4 */ | 889 (mousebuf[i] & 0x40) >> 3 | /* 4 */ |
859 (mousebuf[i] & 0x80) >> 3; /* 5 */ | 890 (mousebuf[i] & 0x80) >> 3; /* 5 */ |
860 dx = (mousebuf[i] & 0x10) ? | 891 dx = (mousebuf[i] & 0x10) ? |
861 mousebuf[i+1] - 256 : mousebuf[i+1]; | 892 mousebuf[i + 1] - 256 : mousebuf[i + 1]; |
862 dy = (mousebuf[i] & 0x20) ? | 893 dy = (mousebuf[i] & 0x20) ? |
863 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | 894 -(mousebuf[i + 2] - 256) : -mousebuf[i + 2]; |
864 switch (mousebuf[i+3]&0x0F) { | 895 switch (mousebuf[i + 3] & 0x0F) { |
865 case 0x0E: /* DX = +1 */ | 896 case 0x0E: /* DX = +1 */ |
866 case 0x02: /* DX = -1 */ | 897 case 0x02: /* DX = -1 */ |
867 break; | 898 break; |
868 case 0x0F: /* DY = +1 (map button 4) */ | 899 case 0x0F: /* DY = +1 (map button 4) */ |
869 FB_vgamousecallback(button | (1<<3), | 900 FB_vgamousecallback(button | (1 << 3), 1, 0, 0); |
870 1, 0, 0); | 901 break; |
871 break; | 902 case 0x01: /* DY = -1 (map button 5) */ |
872 case 0x01: /* DY = -1 (map button 5) */ | 903 FB_vgamousecallback(button | (1 << 4), 1, 0, 0); |
873 FB_vgamousecallback(button | (1<<4), | 904 break; |
874 1, 0, 0); | 905 } |
875 break; | 906 break; |
876 } | 907 case MOUSE_MS: |
877 break; | 908 /* Microsoft protocol has 0x40 in high byte */ |
878 case MOUSE_MS: | 909 if ((mousebuf[i] & 0x40) != 0x40) { |
879 /* Microsoft protocol has 0x40 in high byte */ | 910 /* Go to next byte */ |
880 if ( (mousebuf[i] & 0x40) != 0x40 ) { | 911 i -= (packetsize - 1); |
881 /* Go to next byte */ | 912 continue; |
882 i -= (packetsize-1); | 913 } |
883 continue; | 914 /* Get current mouse state */ |
884 } | 915 button = ((mousebuf[i] & 0x20) >> 3) | |
885 /* Get current mouse state */ | 916 ((mousebuf[i] & 0x10) >> 4); |
886 button = ((mousebuf[i] & 0x20) >> 3) | | 917 dx = (signed char) (((mousebuf[i] & 0x03) << 6) | |
887 ((mousebuf[i] & 0x10) >> 4); | 918 (mousebuf[i + 1] & 0x3F)); |
888 dx = (signed char)(((mousebuf[i] & 0x03) << 6) | | 919 dy = (signed char) (((mousebuf[i] & 0x0C) << 4) | |
889 (mousebuf[i + 1] & 0x3F)); | 920 (mousebuf[i + 2] & 0x3F)); |
890 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) | | 921 break; |
891 (mousebuf[i + 2] & 0x3F)); | 922 case MOUSE_BM: |
892 break; | 923 /* BusMouse protocol has 0xF8 in high byte */ |
893 case MOUSE_BM: | 924 if ((mousebuf[i] & 0xF8) != 0x80) { |
894 /* BusMouse protocol has 0xF8 in high byte */ | 925 /* Go to next byte */ |
895 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | 926 i -= (packetsize - 1); |
896 /* Go to next byte */ | 927 continue; |
897 i -= (packetsize-1); | 928 } |
898 continue; | 929 /* Get current mouse state */ |
899 } | 930 button = (~mousebuf[i]) & 0x07; |
900 /* Get current mouse state */ | 931 dx = (signed char) mousebuf[i + 1]; |
901 button = (~mousebuf[i]) & 0x07; | 932 dy = -(signed char) mousebuf[i + 2]; |
902 dx = (signed char)mousebuf[i+1]; | 933 break; |
903 dy = -(signed char)mousebuf[i+2]; | 934 default: |
904 break; | 935 /* Uh oh.. */ |
905 default: | 936 dx = 0; |
906 /* Uh oh.. */ | 937 dy = 0; |
907 dx = 0; | 938 break; |
908 dy = 0; | 939 } |
909 break; | 940 FB_vgamousecallback(button, relative, dx, dy); |
910 } | 941 } |
911 FB_vgamousecallback(button, relative, dx, dy); | 942 if (i < nread) { |
912 } | 943 SDL_memcpy(mousebuf, &mousebuf[i], (nread - i)); |
913 if ( i < nread ) { | 944 start = (nread - i); |
914 SDL_memcpy(mousebuf, &mousebuf[i], (nread-i)); | 945 } else { |
915 start = (nread-i); | 946 start = 0; |
916 } else { | 947 } |
917 start = 0; | 948 return; |
918 } | |
919 return; | |
920 } | 949 } |
921 | 950 |
922 /* Handle switching to another VC, returns when our VC is back */ | 951 /* Handle switching to another VC, returns when our VC is back */ |
923 static void switch_vt_prep(_THIS) | 952 static void |
924 { | 953 switch_vt_prep(_THIS) |
925 SDL_Surface *screen = SDL_VideoSurface; | 954 { |
926 | 955 SDL_Surface *screen = SDL_VideoSurface; |
927 SDL_PrivateAppActive(0, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)); | 956 |
928 | 957 SDL_PrivateAppActive(0, |
929 /* Save the contents of the screen, and go to text mode */ | 958 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | |
930 wait_idle(this); | 959 SDL_APPMOUSEFOCUS)); |
931 screen_arealen = ((screen->h + (2*this->offset_y)) * screen->pitch); | 960 |
932 screen_contents = (Uint8 *)SDL_malloc(screen_arealen); | 961 /* Save the contents of the screen, and go to text mode */ |
933 if ( screen_contents ) { | 962 wait_idle(this); |
934 SDL_memcpy(screen_contents, screen->pixels, screen_arealen); | 963 screen_arealen = ((screen->h + (2 * this->offset_y)) * screen->pitch); |
935 } | 964 screen_contents = (Uint8 *) SDL_malloc(screen_arealen); |
936 FB_SavePaletteTo(this, 256, screen_palette); | 965 if (screen_contents) { |
937 ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo); | 966 SDL_memcpy(screen_contents, screen->pixels, screen_arealen); |
938 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); | 967 } |
939 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); | 968 FB_SavePaletteTo(this, 256, screen_palette); |
940 } | 969 ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo); |
941 static void switch_vt_done(_THIS) | 970 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
942 { | 971 ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1); |
943 SDL_Surface *screen = SDL_VideoSurface; | 972 } |
944 | 973 static void |
945 /* Restore graphics mode and the contents of the screen */ | 974 switch_vt_done(_THIS) |
946 ioctl(keyboard_fd, VT_LOCKSWITCH, 1); | 975 { |
947 ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS); | 976 SDL_Surface *screen = SDL_VideoSurface; |
948 ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo); | 977 |
949 FB_RestorePaletteFrom(this, 256, screen_palette); | 978 /* Restore graphics mode and the contents of the screen */ |
950 if ( screen_contents ) { | 979 ioctl(keyboard_fd, VT_LOCKSWITCH, 1); |
951 SDL_memcpy(screen->pixels, screen_contents, screen_arealen); | 980 ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS); |
952 SDL_free(screen_contents); | 981 ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo); |
953 screen_contents = NULL; | 982 FB_RestorePaletteFrom(this, 256, screen_palette); |
954 } | 983 if (screen_contents) { |
955 | 984 SDL_memcpy(screen->pixels, screen_contents, screen_arealen); |
956 /* Get updates to the shadow surface while switched away */ | 985 SDL_free(screen_contents); |
957 if ( SDL_ShadowSurface ) { | 986 screen_contents = NULL; |
958 SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0); | 987 } |
959 } | 988 |
960 | 989 /* Get updates to the shadow surface while switched away */ |
961 SDL_PrivateAppActive(1, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)); | 990 if (SDL_ShadowSurface) { |
962 } | 991 SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0); |
963 static void switch_vt(_THIS, unsigned short which) | 992 } |
964 { | 993 |
965 struct vt_stat vtstate; | 994 SDL_PrivateAppActive(1, |
966 | 995 (SDL_APPACTIVE | SDL_APPINPUTFOCUS | |
967 /* Figure out whether or not we're switching to a new console */ | 996 SDL_APPMOUSEFOCUS)); |
968 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) || | 997 } |
969 (which == vtstate.v_active) ) { | 998 static void |
970 return; | 999 switch_vt(_THIS, unsigned short which) |
971 } | 1000 { |
972 | 1001 struct vt_stat vtstate; |
973 /* New console, switch to it */ | 1002 |
974 SDL_mutexP(hw_lock); | 1003 /* Figure out whether or not we're switching to a new console */ |
975 switch_vt_prep(this); | 1004 if ((ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) || |
976 if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) { | 1005 (which == vtstate.v_active)) { |
977 ioctl(keyboard_fd, VT_WAITACTIVE, which); | 1006 return; |
978 switched_away = 1; | 1007 } |
979 } else { | 1008 |
980 switch_vt_done(this); | 1009 /* New console, switch to it */ |
981 } | 1010 SDL_mutexP(hw_lock); |
982 SDL_mutexV(hw_lock); | 1011 switch_vt_prep(this); |
983 } | 1012 if (ioctl(keyboard_fd, VT_ACTIVATE, which) == 0) { |
984 | 1013 ioctl(keyboard_fd, VT_WAITACTIVE, which); |
985 static void handle_keyboard(_THIS) | 1014 switched_away = 1; |
986 { | 1015 } else { |
987 unsigned char keybuf[BUFSIZ]; | 1016 switch_vt_done(this); |
988 int i, nread; | 1017 } |
989 int pressed; | 1018 SDL_mutexV(hw_lock); |
990 int scancode; | 1019 } |
991 SDL_keysym keysym; | 1020 |
992 | 1021 static void |
993 nread = read(keyboard_fd, keybuf, BUFSIZ); | 1022 handle_keyboard(_THIS) |
994 for ( i=0; i<nread; ++i ) { | 1023 { |
995 scancode = keybuf[i] & 0x7F; | 1024 unsigned char keybuf[BUFSIZ]; |
996 if ( keybuf[i] & 0x80 ) { | 1025 int i, nread; |
997 pressed = SDL_RELEASED; | 1026 int pressed; |
998 } else { | 1027 int scancode; |
999 pressed = SDL_PRESSED; | 1028 SDL_keysym keysym; |
1000 } | 1029 |
1001 TranslateKey(scancode, &keysym); | 1030 nread = read(keyboard_fd, keybuf, BUFSIZ); |
1002 /* Handle Ctrl-Alt-FN for vt switch */ | 1031 for (i = 0; i < nread; ++i) { |
1003 switch (keysym.sym) { | 1032 scancode = keybuf[i] & 0x7F; |
1004 case SDLK_F1: | 1033 if (keybuf[i] & 0x80) { |
1005 case SDLK_F2: | 1034 pressed = SDL_RELEASED; |
1006 case SDLK_F3: | 1035 } else { |
1007 case SDLK_F4: | 1036 pressed = SDL_PRESSED; |
1008 case SDLK_F5: | 1037 } |
1009 case SDLK_F6: | 1038 TranslateKey(scancode, &keysym); |
1010 case SDLK_F7: | 1039 /* Handle Ctrl-Alt-FN for vt switch */ |
1011 case SDLK_F8: | 1040 switch (keysym.sym) { |
1012 case SDLK_F9: | 1041 case SDLK_F1: |
1013 case SDLK_F10: | 1042 case SDLK_F2: |
1014 case SDLK_F11: | 1043 case SDLK_F3: |
1015 case SDLK_F12: | 1044 case SDLK_F4: |
1016 if ( (SDL_GetModState() & KMOD_CTRL) && | 1045 case SDLK_F5: |
1017 (SDL_GetModState() & KMOD_ALT) ) { | 1046 case SDLK_F6: |
1018 if ( pressed ) { | 1047 case SDLK_F7: |
1019 switch_vt(this, (keysym.sym-SDLK_F1)+1); | 1048 case SDLK_F8: |
1020 } | 1049 case SDLK_F9: |
1021 break; | 1050 case SDLK_F10: |
1022 } | 1051 case SDLK_F11: |
1023 /* Fall through to normal processing */ | 1052 case SDLK_F12: |
1024 default: | 1053 if ((SDL_GetModState() & KMOD_CTRL) && |
1025 posted += SDL_PrivateKeyboard(pressed, &keysym); | 1054 (SDL_GetModState() & KMOD_ALT)) { |
1026 break; | 1055 if (pressed) { |
1027 } | 1056 switch_vt(this, (keysym.sym - SDLK_F1) + 1); |
1028 } | 1057 } |
1029 } | 1058 break; |
1030 | 1059 } |
1031 void FB_PumpEvents(_THIS) | 1060 /* Fall through to normal processing */ |
1032 { | 1061 default: |
1033 fd_set fdset; | 1062 posted += SDL_PrivateKeyboard(pressed, &keysym); |
1034 int max_fd; | 1063 break; |
1035 static struct timeval zero; | 1064 } |
1036 | 1065 } |
1037 do { | 1066 } |
1038 if ( switched_away ) { | 1067 |
1039 struct vt_stat vtstate; | 1068 void |
1040 | 1069 FB_PumpEvents(_THIS) |
1041 SDL_mutexP(hw_lock); | 1070 { |
1042 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) && | 1071 fd_set fdset; |
1043 vtstate.v_active == current_vt ) { | 1072 int max_fd; |
1044 switched_away = 0; | 1073 static struct timeval zero; |
1045 switch_vt_done(this); | 1074 |
1046 } | 1075 do { |
1047 SDL_mutexV(hw_lock); | 1076 if (switched_away) { |
1048 } | 1077 struct vt_stat vtstate; |
1049 | 1078 |
1050 posted = 0; | 1079 SDL_mutexP(hw_lock); |
1051 | 1080 if ((ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) && |
1052 FD_ZERO(&fdset); | 1081 vtstate.v_active == current_vt) { |
1053 max_fd = 0; | 1082 switched_away = 0; |
1054 if ( keyboard_fd >= 0 ) { | 1083 switch_vt_done(this); |
1055 FD_SET(keyboard_fd, &fdset); | 1084 } |
1056 if ( max_fd < keyboard_fd ) { | 1085 SDL_mutexV(hw_lock); |
1057 max_fd = keyboard_fd; | 1086 } |
1058 } | 1087 |
1059 } | 1088 posted = 0; |
1060 if ( mouse_fd >= 0 ) { | 1089 |
1061 FD_SET(mouse_fd, &fdset); | 1090 FD_ZERO(&fdset); |
1062 if ( max_fd < mouse_fd ) { | 1091 max_fd = 0; |
1063 max_fd = mouse_fd; | 1092 if (keyboard_fd >= 0) { |
1064 } | 1093 FD_SET(keyboard_fd, &fdset); |
1065 } | 1094 if (max_fd < keyboard_fd) { |
1066 if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) { | 1095 max_fd = keyboard_fd; |
1067 if ( keyboard_fd >= 0 ) { | 1096 } |
1068 if ( FD_ISSET(keyboard_fd, &fdset) ) { | 1097 } |
1069 handle_keyboard(this); | 1098 if (mouse_fd >= 0) { |
1070 } | 1099 FD_SET(mouse_fd, &fdset); |
1071 } | 1100 if (max_fd < mouse_fd) { |
1072 if ( mouse_fd >= 0 ) { | 1101 max_fd = mouse_fd; |
1073 if ( FD_ISSET(mouse_fd, &fdset) ) { | 1102 } |
1074 handle_mouse(this); | 1103 } |
1075 } | 1104 if (select(max_fd + 1, &fdset, NULL, NULL, &zero) > 0) { |
1076 } | 1105 if (keyboard_fd >= 0) { |
1077 } | 1106 if (FD_ISSET(keyboard_fd, &fdset)) { |
1078 } while ( posted ); | 1107 handle_keyboard(this); |
1079 } | 1108 } |
1080 | 1109 } |
1081 void FB_InitOSKeymap(_THIS) | 1110 if (mouse_fd >= 0) { |
1082 { | 1111 if (FD_ISSET(mouse_fd, &fdset)) { |
1083 int i; | 1112 handle_mouse(this); |
1084 | 1113 } |
1085 /* Initialize the Linux key translation table */ | 1114 } |
1086 | 1115 } |
1087 /* First get the ascii keys and others not well handled */ | 1116 } |
1088 for (i=0; i<SDL_arraysize(keymap); ++i) { | 1117 while (posted); |
1089 switch(i) { | 1118 } |
1090 /* These aren't handled by the x86 kernel keymapping (?) */ | 1119 |
1091 case SCANCODE_PRINTSCREEN: | 1120 void |
1092 keymap[i] = SDLK_PRINT; | 1121 FB_InitOSKeymap(_THIS) |
1093 break; | 1122 { |
1094 case SCANCODE_BREAK: | 1123 int i; |
1095 keymap[i] = SDLK_BREAK; | 1124 |
1096 break; | 1125 /* Initialize the Linux key translation table */ |
1097 case SCANCODE_BREAK_ALTERNATIVE: | 1126 |
1098 keymap[i] = SDLK_PAUSE; | 1127 /* First get the ascii keys and others not well handled */ |
1099 break; | 1128 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
1100 case SCANCODE_LEFTSHIFT: | 1129 switch (i) { |
1101 keymap[i] = SDLK_LSHIFT; | 1130 /* These aren't handled by the x86 kernel keymapping (?) */ |
1102 break; | 1131 case SCANCODE_PRINTSCREEN: |
1103 case SCANCODE_RIGHTSHIFT: | 1132 keymap[i] = SDLK_PRINT; |
1104 keymap[i] = SDLK_RSHIFT; | 1133 break; |
1105 break; | 1134 case SCANCODE_BREAK: |
1106 case SCANCODE_LEFTCONTROL: | 1135 keymap[i] = SDLK_BREAK; |
1107 keymap[i] = SDLK_LCTRL; | 1136 break; |
1108 break; | 1137 case SCANCODE_BREAK_ALTERNATIVE: |
1109 case SCANCODE_RIGHTCONTROL: | 1138 keymap[i] = SDLK_PAUSE; |
1110 keymap[i] = SDLK_RCTRL; | 1139 break; |
1111 break; | 1140 case SCANCODE_LEFTSHIFT: |
1112 case SCANCODE_RIGHTWIN: | 1141 keymap[i] = SDLK_LSHIFT; |
1113 keymap[i] = SDLK_RSUPER; | 1142 break; |
1114 break; | 1143 case SCANCODE_RIGHTSHIFT: |
1115 case SCANCODE_LEFTWIN: | 1144 keymap[i] = SDLK_RSHIFT; |
1116 keymap[i] = SDLK_LSUPER; | 1145 break; |
1117 break; | 1146 case SCANCODE_LEFTCONTROL: |
1118 case SCANCODE_LEFTALT: | 1147 keymap[i] = SDLK_LCTRL; |
1119 keymap[i] = SDLK_LALT; | 1148 break; |
1120 break; | 1149 case SCANCODE_RIGHTCONTROL: |
1121 case SCANCODE_RIGHTALT: | 1150 keymap[i] = SDLK_RCTRL; |
1122 keymap[i] = SDLK_RALT; | 1151 break; |
1123 break; | 1152 case SCANCODE_RIGHTWIN: |
1124 case 127: | 1153 keymap[i] = SDLK_RSUPER; |
1125 keymap[i] = SDLK_MENU; | 1154 break; |
1126 break; | 1155 case SCANCODE_LEFTWIN: |
1127 /* this should take care of all standard ascii keys */ | 1156 keymap[i] = SDLK_LSUPER; |
1128 default: | 1157 break; |
1129 keymap[i] = KVAL(vga_keymap[0][i]); | 1158 case SCANCODE_LEFTALT: |
1130 break; | 1159 keymap[i] = SDLK_LALT; |
1131 } | 1160 break; |
1132 } | 1161 case SCANCODE_RIGHTALT: |
1133 for (i=0; i<SDL_arraysize(keymap); ++i) { | 1162 keymap[i] = SDLK_RALT; |
1134 switch(keymap_temp[i]) { | 1163 break; |
1135 case K_F1: keymap[i] = SDLK_F1; break; | 1164 case 127: |
1136 case K_F2: keymap[i] = SDLK_F2; break; | 1165 keymap[i] = SDLK_MENU; |
1137 case K_F3: keymap[i] = SDLK_F3; break; | 1166 break; |
1138 case K_F4: keymap[i] = SDLK_F4; break; | 1167 /* this should take care of all standard ascii keys */ |
1139 case K_F5: keymap[i] = SDLK_F5; break; | 1168 default: |
1140 case K_F6: keymap[i] = SDLK_F6; break; | 1169 keymap[i] = KVAL(vga_keymap[0][i]); |
1141 case K_F7: keymap[i] = SDLK_F7; break; | 1170 break; |
1142 case K_F8: keymap[i] = SDLK_F8; break; | 1171 } |
1143 case K_F9: keymap[i] = SDLK_F9; break; | 1172 } |
1144 case K_F10: keymap[i] = SDLK_F10; break; | 1173 for (i = 0; i < SDL_arraysize(keymap); ++i) { |
1145 case K_F11: keymap[i] = SDLK_F11; break; | 1174 switch (keymap_temp[i]) { |
1146 case K_F12: keymap[i] = SDLK_F12; break; | 1175 case K_F1: |
1147 | 1176 keymap[i] = SDLK_F1; |
1148 case K_DOWN: keymap[i] = SDLK_DOWN; break; | 1177 break; |
1149 case K_LEFT: keymap[i] = SDLK_LEFT; break; | 1178 case K_F2: |
1150 case K_RIGHT: keymap[i] = SDLK_RIGHT; break; | 1179 keymap[i] = SDLK_F2; |
1151 case K_UP: keymap[i] = SDLK_UP; break; | 1180 break; |
1152 | 1181 case K_F3: |
1153 case K_P0: keymap[i] = SDLK_KP0; break; | 1182 keymap[i] = SDLK_F3; |
1154 case K_P1: keymap[i] = SDLK_KP1; break; | 1183 break; |
1155 case K_P2: keymap[i] = SDLK_KP2; break; | 1184 case K_F4: |
1156 case K_P3: keymap[i] = SDLK_KP3; break; | 1185 keymap[i] = SDLK_F4; |
1157 case K_P4: keymap[i] = SDLK_KP4; break; | 1186 break; |
1158 case K_P5: keymap[i] = SDLK_KP5; break; | 1187 case K_F5: |
1159 case K_P6: keymap[i] = SDLK_KP6; break; | 1188 keymap[i] = SDLK_F5; |
1160 case K_P7: keymap[i] = SDLK_KP7; break; | 1189 break; |
1161 case K_P8: keymap[i] = SDLK_KP8; break; | 1190 case K_F6: |
1162 case K_P9: keymap[i] = SDLK_KP9; break; | 1191 keymap[i] = SDLK_F6; |
1163 case K_PPLUS: keymap[i] = SDLK_KP_PLUS; break; | 1192 break; |
1164 case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break; | 1193 case K_F7: |
1165 case K_PSTAR: keymap[i] = SDLK_KP_MULTIPLY; break; | 1194 keymap[i] = SDLK_F7; |
1166 case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break; | 1195 break; |
1167 case K_PENTER: keymap[i] = SDLK_KP_ENTER; break; | 1196 case K_F8: |
1168 case K_PDOT: keymap[i] = SDLK_KP_PERIOD; break; | 1197 keymap[i] = SDLK_F8; |
1169 | 1198 break; |
1170 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT ) | 1199 case K_F9: |
1171 keymap[i] = SDLK_LSHIFT; | 1200 keymap[i] = SDLK_F9; |
1172 break; | 1201 break; |
1173 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break; | 1202 case K_F10: |
1174 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break; | 1203 keymap[i] = SDLK_F10; |
1175 case K_CTRL: if ( keymap[i] != SDLK_RCTRL ) | 1204 break; |
1176 keymap[i] = SDLK_LCTRL; | 1205 case K_F11: |
1177 break; | 1206 keymap[i] = SDLK_F11; |
1178 case K_CTRLL: keymap[i] = SDLK_LCTRL; break; | 1207 break; |
1179 case K_CTRLR: keymap[i] = SDLK_RCTRL; break; | 1208 case K_F12: |
1180 case K_ALT: keymap[i] = SDLK_LALT; break; | 1209 keymap[i] = SDLK_F12; |
1181 case K_ALTGR: keymap[i] = SDLK_RALT; break; | 1210 break; |
1182 | 1211 |
1183 case K_INSERT: keymap[i] = SDLK_INSERT; break; | 1212 case K_DOWN: |
1184 case K_REMOVE: keymap[i] = SDLK_DELETE; break; | 1213 keymap[i] = SDLK_DOWN; |
1185 case K_PGUP: keymap[i] = SDLK_PAGEUP; break; | 1214 break; |
1186 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break; | 1215 case K_LEFT: |
1187 case K_FIND: keymap[i] = SDLK_HOME; break; | 1216 keymap[i] = SDLK_LEFT; |
1188 case K_SELECT: keymap[i] = SDLK_END; break; | 1217 break; |
1189 | 1218 case K_RIGHT: |
1190 case K_NUM: keymap[i] = SDLK_NUMLOCK; break; | 1219 keymap[i] = SDLK_RIGHT; |
1191 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break; | 1220 break; |
1192 | 1221 case K_UP: |
1193 case K_F13: keymap[i] = SDLK_PRINT; break; | 1222 keymap[i] = SDLK_UP; |
1194 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break; | 1223 break; |
1195 case K_PAUSE: keymap[i] = SDLK_PAUSE; break; | 1224 |
1196 | 1225 case K_P0: |
1197 case 127: keymap[i] = SDLK_BACKSPACE; break; | 1226 keymap[i] = SDLK_KP0; |
1198 | 1227 break; |
1199 default: break; | 1228 case K_P1: |
1200 } | 1229 keymap[i] = SDLK_KP1; |
1201 } | 1230 break; |
1202 } | 1231 case K_P2: |
1203 | 1232 keymap[i] = SDLK_KP2; |
1204 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | 1233 break; |
1205 { | 1234 case K_P3: |
1206 /* Set the keysym information */ | 1235 keymap[i] = SDLK_KP3; |
1207 keysym->scancode = scancode; | 1236 break; |
1208 keysym->sym = keymap[scancode]; | 1237 case K_P4: |
1209 keysym->mod = KMOD_NONE; | 1238 keymap[i] = SDLK_KP4; |
1210 | 1239 break; |
1211 /* If UNICODE is on, get the UNICODE value for the key */ | 1240 case K_P5: |
1212 keysym->unicode = 0; | 1241 keymap[i] = SDLK_KP5; |
1213 if ( SDL_TranslateUNICODE ) { | 1242 break; |
1214 int map; | 1243 case K_P6: |
1215 SDLMod modstate; | 1244 keymap[i] = SDLK_KP6; |
1216 | 1245 break; |
1217 modstate = SDL_GetModState(); | 1246 case K_P7: |
1218 map = 0; | 1247 keymap[i] = SDLK_KP7; |
1219 if ( modstate & KMOD_SHIFT ) { | 1248 break; |
1220 map |= (1<<KG_SHIFT); | 1249 case K_P8: |
1221 } | 1250 keymap[i] = SDLK_KP8; |
1222 if ( modstate & KMOD_CTRL ) { | 1251 break; |
1223 map |= (1<<KG_CTRL); | 1252 case K_P9: |
1224 } | 1253 keymap[i] = SDLK_KP9; |
1225 if ( modstate & KMOD_LALT ) { | 1254 break; |
1226 map |= (1<<KG_ALT); | 1255 case K_PPLUS: |
1227 } | 1256 keymap[i] = SDLK_KP_PLUS; |
1228 if ( modstate & KMOD_RALT ) { | 1257 break; |
1229 map |= (1<<KG_ALTGR); | 1258 case K_PMINUS: |
1230 } | 1259 keymap[i] = SDLK_KP_MINUS; |
1231 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) { | 1260 break; |
1232 if ( modstate & KMOD_CAPS ) { | 1261 case K_PSTAR: |
1233 map ^= (1<<KG_SHIFT); | 1262 keymap[i] = SDLK_KP_MULTIPLY; |
1234 } | 1263 break; |
1235 } | 1264 case K_PSLASH: |
1236 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) { | 1265 keymap[i] = SDLK_KP_DIVIDE; |
1237 if ( modstate & KMOD_NUM ) { | 1266 break; |
1238 keysym->unicode=KVAL(vga_keymap[map][scancode]); | 1267 case K_PENTER: |
1239 } | 1268 keymap[i] = SDLK_KP_ENTER; |
1240 } else { | 1269 break; |
1241 keysym->unicode = KVAL(vga_keymap[map][scancode]); | 1270 case K_PDOT: |
1242 } | 1271 keymap[i] = SDLK_KP_PERIOD; |
1243 } | 1272 break; |
1244 return(keysym); | 1273 |
1245 } | 1274 case K_SHIFT: |
1275 if (keymap[i] != SDLK_RSHIFT) | |
1276 keymap[i] = SDLK_LSHIFT; | |
1277 break; | |
1278 case K_SHIFTL: | |
1279 keymap[i] = SDLK_LSHIFT; | |
1280 break; | |
1281 case K_SHIFTR: | |
1282 keymap[i] = SDLK_RSHIFT; | |
1283 break; | |
1284 case K_CTRL: | |
1285 if (keymap[i] != SDLK_RCTRL) | |
1286 keymap[i] = SDLK_LCTRL; | |
1287 break; | |
1288 case K_CTRLL: | |
1289 keymap[i] = SDLK_LCTRL; | |
1290 break; | |
1291 case K_CTRLR: | |
1292 keymap[i] = SDLK_RCTRL; | |
1293 break; | |
1294 case K_ALT: | |
1295 keymap[i] = SDLK_LALT; | |
1296 break; | |
1297 case K_ALTGR: | |
1298 keymap[i] = SDLK_RALT; | |
1299 break; | |
1300 | |
1301 case K_INSERT: | |
1302 keymap[i] = SDLK_INSERT; | |
1303 break; | |
1304 case K_REMOVE: | |
1305 keymap[i] = SDLK_DELETE; | |
1306 break; | |
1307 case K_PGUP: | |
1308 keymap[i] = SDLK_PAGEUP; | |
1309 break; | |
1310 case K_PGDN: | |
1311 keymap[i] = SDLK_PAGEDOWN; | |
1312 break; | |
1313 case K_FIND: | |
1314 keymap[i] = SDLK_HOME; | |
1315 break; | |
1316 case K_SELECT: | |
1317 keymap[i] = SDLK_END; | |
1318 break; | |
1319 | |
1320 case K_NUM: | |
1321 keymap[i] = SDLK_NUMLOCK; | |
1322 break; | |
1323 case K_CAPS: | |
1324 keymap[i] = SDLK_CAPSLOCK; | |
1325 break; | |
1326 | |
1327 case K_F13: | |
1328 keymap[i] = SDLK_PRINT; | |
1329 break; | |
1330 case K_HOLD: | |
1331 keymap[i] = SDLK_SCROLLOCK; | |
1332 break; | |
1333 case K_PAUSE: | |
1334 keymap[i] = SDLK_PAUSE; | |
1335 break; | |
1336 | |
1337 case 127: | |
1338 keymap[i] = SDLK_BACKSPACE; | |
1339 break; | |
1340 | |
1341 default: | |
1342 break; | |
1343 } | |
1344 } | |
1345 } | |
1346 | |
1347 static SDL_keysym * | |
1348 TranslateKey(int scancode, SDL_keysym * keysym) | |
1349 { | |
1350 /* Set the keysym information */ | |
1351 keysym->scancode = scancode; | |
1352 keysym->sym = keymap[scancode]; | |
1353 keysym->mod = KMOD_NONE; | |
1354 | |
1355 /* If UNICODE is on, get the UNICODE value for the key */ | |
1356 keysym->unicode = 0; | |
1357 if (SDL_TranslateUNICODE) { | |
1358 int map; | |
1359 SDLMod modstate; | |
1360 | |
1361 modstate = SDL_GetModState(); | |
1362 map = 0; | |
1363 if (modstate & KMOD_SHIFT) { | |
1364 map |= (1 << KG_SHIFT); | |
1365 } | |
1366 if (modstate & KMOD_CTRL) { | |
1367 map |= (1 << KG_CTRL); | |
1368 } | |
1369 if (modstate & KMOD_LALT) { | |
1370 map |= (1 << KG_ALT); | |
1371 } | |
1372 if (modstate & KMOD_RALT) { | |
1373 map |= (1 << KG_ALTGR); | |
1374 } | |
1375 if (KTYP(vga_keymap[map][scancode]) == KT_LETTER) { | |
1376 if (modstate & KMOD_CAPS) { | |
1377 map ^= (1 << KG_SHIFT); | |
1378 } | |
1379 } | |
1380 if (KTYP(vga_keymap[map][scancode]) == KT_PAD) { | |
1381 if (modstate & KMOD_NUM) { | |
1382 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
1383 } | |
1384 } else { | |
1385 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
1386 } | |
1387 } | |
1388 return (keysym); | |
1389 } | |
1390 | |
1391 /* vi: set ts=4 sw=4 expandtab: */ |