comparison src/video/svga/SDL_svgaevents.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
49 static keymap_t *vga_keymap = NULL; 49 static keymap_t *vga_keymap = NULL;
50 #else 50 #else
51 #error You must choose your operating system here 51 #error You must choose your operating system here
52 #endif 52 #endif
53 static SDLKey keymap[128]; 53 static SDLKey keymap[128];
54 static SDL_keysym *TranslateKey (int scancode, SDL_keysym * keysym); 54 static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym);
55 55
56 /* Ugh, we have to duplicate the kernel's keysym mapping code... 56 /* Ugh, we have to duplicate the kernel's keysym mapping code...
57 Oh, it's not so bad. :-) 57 Oh, it's not so bad. :-)
58 58
59 FIXME: Add keyboard LED handling code 59 FIXME: Add keyboard LED handling code
60 */ 60 */
61 #if defined(linux) 61 #if defined(linux)
62 int 62 int
63 SVGA_initkeymaps (int fd) 63 SVGA_initkeymaps(int fd)
64 { 64 {
65 struct kbentry entry; 65 struct kbentry entry;
66 int map, i; 66 int map, i;
67 67
68 /* Load all the keysym mappings */ 68 /* Load all the keysym mappings */
69 for (map = 0; map < NUM_VGAKEYMAPS; ++map) { 69 for (map = 0; map < NUM_VGAKEYMAPS; ++map) {
70 SDL_memset (vga_keymap[map], 0, NR_KEYS * sizeof (Uint16)); 70 SDL_memset(vga_keymap[map], 0, NR_KEYS * sizeof(Uint16));
71 for (i = 0; i < NR_KEYS; ++i) { 71 for (i = 0; i < NR_KEYS; ++i) {
72 entry.kb_table = map; 72 entry.kb_table = map;
73 entry.kb_index = i; 73 entry.kb_index = i;
74 if (ioctl (fd, KDGKBENT, &entry) == 0) { 74 if (ioctl(fd, KDGKBENT, &entry) == 0) {
75 /* The "Enter" key is a special case */ 75 /* The "Enter" key is a special case */
76 if (entry.kb_value == K_ENTER) { 76 if (entry.kb_value == K_ENTER) {
77 entry.kb_value = K (KT_ASCII, 13); 77 entry.kb_value = K(KT_ASCII, 13);
78 } 78 }
79 /* Handle numpad specially as well */ 79 /* Handle numpad specially as well */
80 if (KTYP (entry.kb_value) == KT_PAD) { 80 if (KTYP(entry.kb_value) == KT_PAD) {
81 switch (entry.kb_value) { 81 switch (entry.kb_value) {
82 case K_P0: 82 case K_P0:
83 case K_P1: 83 case K_P1:
84 case K_P2: 84 case K_P2:
85 case K_P3: 85 case K_P3:
91 case K_P9: 91 case K_P9:
92 vga_keymap[map][i] = entry.kb_value; 92 vga_keymap[map][i] = entry.kb_value;
93 vga_keymap[map][i] += '0'; 93 vga_keymap[map][i] += '0';
94 break; 94 break;
95 case K_PPLUS: 95 case K_PPLUS:
96 vga_keymap[map][i] = K (KT_ASCII, '+'); 96 vga_keymap[map][i] = K(KT_ASCII, '+');
97 break; 97 break;
98 case K_PMINUS: 98 case K_PMINUS:
99 vga_keymap[map][i] = K (KT_ASCII, '-'); 99 vga_keymap[map][i] = K(KT_ASCII, '-');
100 break; 100 break;
101 case K_PSTAR: 101 case K_PSTAR:
102 vga_keymap[map][i] = K (KT_ASCII, '*'); 102 vga_keymap[map][i] = K(KT_ASCII, '*');
103 break; 103 break;
104 case K_PSLASH: 104 case K_PSLASH:
105 vga_keymap[map][i] = K (KT_ASCII, '/'); 105 vga_keymap[map][i] = K(KT_ASCII, '/');
106 break; 106 break;
107 case K_PENTER: 107 case K_PENTER:
108 vga_keymap[map][i] = K (KT_ASCII, '\r'); 108 vga_keymap[map][i] = K(KT_ASCII, '\r');
109 break; 109 break;
110 case K_PCOMMA: 110 case K_PCOMMA:
111 vga_keymap[map][i] = K (KT_ASCII, ','); 111 vga_keymap[map][i] = K(KT_ASCII, ',');
112 break; 112 break;
113 case K_PDOT: 113 case K_PDOT:
114 vga_keymap[map][i] = K (KT_ASCII, '.'); 114 vga_keymap[map][i] = K(KT_ASCII, '.');
115 break; 115 break;
116 default: 116 default:
117 break; 117 break;
118 } 118 }
119 } 119 }
120 /* Do the normal key translation */ 120 /* Do the normal key translation */
121 if ((KTYP (entry.kb_value) == KT_LATIN) || 121 if ((KTYP(entry.kb_value) == KT_LATIN) ||
122 (KTYP (entry.kb_value) == KT_ASCII) || 122 (KTYP(entry.kb_value) == KT_ASCII) ||
123 (KTYP (entry.kb_value) == KT_LETTER)) { 123 (KTYP(entry.kb_value) == KT_LETTER)) {
124 vga_keymap[map][i] = entry.kb_value; 124 vga_keymap[map][i] = entry.kb_value;
125 } 125 }
126 } 126 }
127 } 127 }
128 } 128 }
129 return (0); 129 return (0);
130 } 130 }
131 #elif defined(__FREEBSD__) 131 #elif defined(__FREEBSD__)
132 int 132 int
133 SVGA_initkeymaps (int fd) 133 SVGA_initkeymaps(int fd)
134 { 134 {
135 vga_keymap = SDL_malloc (sizeof (keymap_t)); 135 vga_keymap = SDL_malloc(sizeof(keymap_t));
136 if (!vga_keymap) { 136 if (!vga_keymap) {
137 SDL_OutOfMemory (); 137 SDL_OutOfMemory();
138 return (-1); 138 return (-1);
139 } 139 }
140 if (ioctl (fd, GIO_KEYMAP, vga_keymap) == -1) { 140 if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) {
141 SDL_free (vga_keymap); 141 SDL_free(vga_keymap);
142 vga_keymap = NULL; 142 vga_keymap = NULL;
143 SDL_SetError ("Unable to get keyboard map"); 143 SDL_SetError("Unable to get keyboard map");
144 return (-1); 144 return (-1);
145 } 145 }
146 return (0); 146 return (0);
147 } 147 }
148 #else 148 #else
150 #endif 150 #endif
151 151
152 int posted = 0; 152 int posted = 0;
153 153
154 void 154 void
155 SVGA_mousecallback (int button, int dx, int dy, 155 SVGA_mousecallback(int button, int dx, int dy, int u1, int u2, int u3, int u4)
156 int u1, int u2, int u3, int u4)
157 { 156 {
158 if (dx || dy) { 157 if (dx || dy) {
159 posted += SDL_PrivateMouseMotion (0, 1, dx, dy); 158 posted += SDL_PrivateMouseMotion(0, 1, dx, dy);
160 } 159 }
161 if (button & MOUSE_LEFTBUTTON) { 160 if (button & MOUSE_LEFTBUTTON) {
162 if (!(SDL_GetMouseState (NULL, NULL) & SDL_BUTTON (1))) { 161 if (!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1))) {
163 posted += SDL_PrivateMouseButton (SDL_PRESSED, 1, 0, 0); 162 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0);
164 } 163 }
165 } else { 164 } else {
166 if ((SDL_GetMouseState (NULL, NULL) & SDL_BUTTON (1))) { 165 if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1))) {
167 posted += SDL_PrivateMouseButton (SDL_RELEASED, 1, 0, 0); 166 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0);
168 } 167 }
169 } 168 }
170 if (button & MOUSE_MIDDLEBUTTON) { 169 if (button & MOUSE_MIDDLEBUTTON) {
171 if (!(SDL_GetMouseState (NULL, NULL) & SDL_BUTTON (2))) { 170 if (!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2))) {
172 posted += SDL_PrivateMouseButton (SDL_PRESSED, 2, 0, 0); 171 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0);
173 } 172 }
174 } else { 173 } else {
175 if ((SDL_GetMouseState (NULL, NULL) & SDL_BUTTON (2))) { 174 if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2))) {
176 posted += SDL_PrivateMouseButton (SDL_RELEASED, 2, 0, 0); 175 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0);
177 } 176 }
178 } 177 }
179 if (button & MOUSE_RIGHTBUTTON) { 178 if (button & MOUSE_RIGHTBUTTON) {
180 if (!(SDL_GetMouseState (NULL, NULL) & SDL_BUTTON (3))) { 179 if (!(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3))) {
181 posted += SDL_PrivateMouseButton (SDL_PRESSED, 3, 0, 0); 180 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0);
182 } 181 }
183 } else { 182 } else {
184 if ((SDL_GetMouseState (NULL, NULL) & SDL_BUTTON (3))) { 183 if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3))) {
185 posted += SDL_PrivateMouseButton (SDL_RELEASED, 3, 0, 0); 184 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0);
186 } 185 }
187 } 186 }
188 } 187 }
189 188
190 void 189 void
191 SVGA_keyboardcallback (int scancode, int pressed) 190 SVGA_keyboardcallback(int scancode, int pressed)
192 { 191 {
193 SDL_keysym keysym; 192 SDL_keysym keysym;
194 193
195 if (pressed) { 194 if (pressed) {
196 posted += SDL_PrivateKeyboard (SDL_PRESSED, 195 posted += SDL_PrivateKeyboard(SDL_PRESSED,
197 TranslateKey (scancode, &keysym)); 196 TranslateKey(scancode, &keysym));
198 } else { 197 } else {
199 posted += SDL_PrivateKeyboard (SDL_RELEASED, 198 posted += SDL_PrivateKeyboard(SDL_RELEASED,
200 TranslateKey (scancode, &keysym)); 199 TranslateKey(scancode, &keysym));
201 } 200 }
202 } 201 }
203 202
204 void 203 void
205 SVGA_PumpEvents (_THIS) 204 SVGA_PumpEvents(_THIS)
206 { 205 {
207 do { 206 do {
208 posted = 0; 207 posted = 0;
209 mouse_update (); 208 mouse_update();
210 keyboard_update (); 209 keyboard_update();
211 } 210 }
212 while (posted); 211 while (posted);
213 } 212 }
214 213
215 void 214 void
216 SVGA_InitOSKeymap (_THIS) 215 SVGA_InitOSKeymap(_THIS)
217 { 216 {
218 int i; 217 int i;
219 218
220 /* Initialize the BeOS key translation table */ 219 /* Initialize the BeOS key translation table */
221 for (i = 0; i < SDL_arraysize (keymap); ++i) 220 for (i = 0; i < SDL_arraysize(keymap); ++i)
222 keymap[i] = SDLK_UNKNOWN; 221 keymap[i] = SDLK_UNKNOWN;
223 222
224 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; 223 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
225 keymap[SCANCODE_1] = SDLK_1; 224 keymap[SCANCODE_1] = SDLK_1;
226 keymap[SCANCODE_2] = SDLK_2; 225 keymap[SCANCODE_2] = SDLK_2;
339 keymap[127] = SDLK_MENU; 338 keymap[127] = SDLK_MENU;
340 } 339 }
341 340
342 #if defined(linux) 341 #if defined(linux)
343 static SDL_keysym * 342 static SDL_keysym *
344 TranslateKey (int scancode, SDL_keysym * keysym) 343 TranslateKey(int scancode, SDL_keysym * keysym)
345 { 344 {
346 /* Set the keysym information */ 345 /* Set the keysym information */
347 keysym->scancode = scancode; 346 keysym->scancode = scancode;
348 keysym->sym = keymap[scancode]; 347 keysym->sym = keymap[scancode];
349 keysym->mod = KMOD_NONE; 348 keysym->mod = KMOD_NONE;
352 keysym->unicode = 0; 351 keysym->unicode = 0;
353 if (SDL_TranslateUNICODE) { 352 if (SDL_TranslateUNICODE) {
354 int map; 353 int map;
355 SDLMod modstate; 354 SDLMod modstate;
356 355
357 modstate = SDL_GetModState (); 356 modstate = SDL_GetModState();
358 map = 0; 357 map = 0;
359 if (modstate & KMOD_SHIFT) { 358 if (modstate & KMOD_SHIFT) {
360 map |= (1 << KG_SHIFT); 359 map |= (1 << KG_SHIFT);
361 } 360 }
362 if (modstate & KMOD_CTRL) { 361 if (modstate & KMOD_CTRL) {
366 map |= (1 << KG_ALT); 365 map |= (1 << KG_ALT);
367 } 366 }
368 if (modstate & KMOD_MODE) { 367 if (modstate & KMOD_MODE) {
369 map |= (1 << KG_ALTGR); 368 map |= (1 << KG_ALTGR);
370 } 369 }
371 if (KTYP (vga_keymap[map][scancode]) == KT_LETTER) { 370 if (KTYP(vga_keymap[map][scancode]) == KT_LETTER) {
372 if (modstate & KMOD_CAPS) { 371 if (modstate & KMOD_CAPS) {
373 map ^= (1 << KG_SHIFT); 372 map ^= (1 << KG_SHIFT);
374 } 373 }
375 } 374 }
376 if (KTYP (vga_keymap[map][scancode]) == KT_PAD) { 375 if (KTYP(vga_keymap[map][scancode]) == KT_PAD) {
377 if (modstate & KMOD_NUM) { 376 if (modstate & KMOD_NUM) {
378 keysym->unicode = KVAL (vga_keymap[map][scancode]); 377 keysym->unicode = KVAL(vga_keymap[map][scancode]);
379 } 378 }
380 } else { 379 } else {
381 keysym->unicode = KVAL (vga_keymap[map][scancode]); 380 keysym->unicode = KVAL(vga_keymap[map][scancode]);
382 } 381 }
383 } 382 }
384 return (keysym); 383 return (keysym);
385 } 384 }
386 #elif defined(__FREEBSD__) 385 #elif defined(__FREEBSD__)
387 static SDL_keysym * 386 static SDL_keysym *
388 TranslateKey (int scancode, SDL_keysym * keysym) 387 TranslateKey(int scancode, SDL_keysym * keysym)
389 { 388 {
390 /* Set the keysym information */ 389 /* Set the keysym information */
391 keysym->scancode = scancode; 390 keysym->scancode = scancode;
392 keysym->sym = keymap[scancode]; 391 keysym->sym = keymap[scancode];
393 keysym->mod = KMOD_NONE; 392 keysym->mod = KMOD_NONE;
396 keysym->unicode = 0; 395 keysym->unicode = 0;
397 if (SDL_TranslateUNICODE && vga_keymap) { 396 if (SDL_TranslateUNICODE && vga_keymap) {
398 int map; 397 int map;
399 SDLMod modstate; 398 SDLMod modstate;
400 399
401 modstate = SDL_GetModState (); 400 modstate = SDL_GetModState();
402 map = 0; 401 map = 0;
403 if (modstate & KMOD_SHIFT) { 402 if (modstate & KMOD_SHIFT) {
404 map += 1; 403 map += 1;
405 } 404 }
406 if (modstate & KMOD_CTRL) { 405 if (modstate & KMOD_CTRL) {