comparison src/video/photon/SDL_ph_events.c @ 571:8e3ce997621c

Date: Thu, 16 Jan 2003 13:48:31 +0200 From: "Mike Gorchak" Subject: All QNX patches whole patches concerning QNX. Almost all code has been rewritten by Julian and me. Added initial support for hw overlays in QNX and many many others fixes. P.S. This patches has been reviewed by Dave Rempel from QSSL and included in SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1 version of QNX, which will be available soon.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Jan 2003 01:38:37 +0000
parents 66f815c147ed
children 8bedd6d61642
comparison
equal deleted inserted replaced
570:04d6411da49d 571:8e3ce997621c
53 53
54 /* Check to see if this is a repeated key. 54 /* Check to see if this is a repeated key.
55 (idea shamelessly lifted from GII -- thanks guys! :) 55 (idea shamelessly lifted from GII -- thanks guys! :)
56 */ 56 */
57 57
58 #if 0
59 static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
60 {
61 // PhEvent_t* peekevent;
62 PhKeyEvent_t* keyEvent;
63 int repeated;
64
65 repeated = 0;
66 switch (PhEventPeek( peekevent, EVENT_SIZE ))
67 {
68 case Ph_EVENT_MSG: {
69 if(peekevent->type == Ph_EV_KEY)
70 {
71 keyEvent = PhGetData( peekevent );
72 if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
73 (keyEvent->key_cap == keyevent->key_cap) &&
74 (peekevent->timestamp == event->timestamp)
75 ) {
76 repeated = 1;
77 /* PhEventNext( peekevent, EVENT_SIZE ); */
78 }
79 }
80 }
81 break;
82
83 case -1: {
84 perror( "PhEventPeek failed" );
85 }
86 break;
87
88 default: /* no events pending */
89 }
90 return(repeated);
91 }
92 #endif
93
94 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent) 58 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
95 { 59 {
96 /* PhPointerEvent_t *pointer = PhGetData( winEvent ); */ 60 PhRect_t *rect = PhGetRects( winEvent );
97 PhRect_t *rect = PhGetRects( winEvent ); 61
98 62 int centre_x, centre_y;
99 int centre_x, centre_y; 63 int dx, dy;
100 int dx, dy; 64 short abs_x, abs_y;
101 short abs_x, abs_y; 65 int posted;
102 int posted; 66
103 67 centre_x = SDL_VideoSurface->w / 2;
104 centre_x = SDL_VideoSurface->w / 2; 68 centre_y = SDL_VideoSurface->h / 2;
105 centre_y = SDL_VideoSurface->h / 2; 69
106 70 dx = rect->ul.x - centre_x;
107 dx = rect->ul.x - centre_x; 71 dy = rect->ul.y - centre_y;
108 dy = rect->ul.y - centre_y; 72
109 73 posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
110 posted = SDL_PrivateMouseMotion( 0, 1, dx, dy ); 74
111 75 /* Move mouse cursor to middle of the window */
112 /* Move mouse cursor to middle of the window */ 76 PtGetAbsPosition( window, &abs_x, &abs_y );
113 PtGetAbsPosition( window, &abs_x, &abs_y ); 77 PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
114 PhMoveCursorAbs( PhInputGroup(NULL), 78
115 abs_x + centre_x, 79 return (posted);
116 abs_y + centre_y );
117
118 return(posted);
119 } 80 }
120 81
121 /* Control which motion flags the window has set, a flags value of -1 sets 82 /* Control which motion flags the window has set, a flags value of -1 sets
122 * MOTION_BUTTON and MOTION_NOBUTTON */ 83 * MOTION_BUTTON and MOTION_NOBUTTON */
123 84
124 static void set_motion_sensitivity(_THIS, unsigned int flags) 85 static void set_motion_sensitivity(_THIS, unsigned int flags)
125 { 86 {
126 int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON; 87 int rid;
127 PhRegion_t region; 88 int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
128 89 PhRegion_t region;
129 if( window ) 90
130 { 91 if( window )
131 rid = PtWidgetRid( window ); 92 {
132 if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 ) 93 rid = PtWidgetRid( window );
133 { 94 if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
134 region.events_sense = ( region.events_sense & ~fields ) | 95 {
135 ( flags & fields ); 96 region.events_sense=(region.events_sense & ~fields)|(flags & fields);
136 PhRegionChange( Ph_REGION_EV_SENSE, 0, &region, 97 PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
137 NULL, NULL ); 98 }
138 } 99 }
139 }
140 } 100 }
141 101
142 /* Convert the photon button state value to an SDL value */ 102 /* Convert the photon button state value to an SDL value */
143 static Uint8 ph2sdl_mousebutton( unsigned short button_state ) 103 static Uint8 ph2sdl_mousebutton(unsigned short button_state)
144 { 104 {
145 Uint8 mouse_button = 0; 105 Uint8 mouse_button = 0;
146 106
147 if( button_state & Ph_BUTTON_SELECT ) 107 if (button_state & Ph_BUTTON_SELECT)
148 mouse_button |= SDL_BUTTON_LEFT; 108 mouse_button |= SDL_BUTTON_LEFT;
149 if( button_state & Ph_BUTTON_MENU ) 109 if (button_state & Ph_BUTTON_MENU)
150 mouse_button |= SDL_BUTTON_RIGHT; 110 mouse_button |= SDL_BUTTON_RIGHT;
151 if( button_state & Ph_BUTTON_ADJUST ) 111 if (button_state & Ph_BUTTON_ADJUST)
152 mouse_button |= SDL_BUTTON_MIDDLE; 112 mouse_button |= SDL_BUTTON_MIDDLE;
153 113
154 return( mouse_button ); 114 return (mouse_button);
155 } 115 }
156 116
157 static int ph_DispatchEvent(_THIS) 117 static int ph_DispatchEvent(_THIS)
158 { 118 {
159 int posted; 119 int posted;
243 /* losing focus */ 203 /* losing focus */
244 if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) 204 if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
245 { 205 {
246 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); 206 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
247 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 207 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
248
249 /* Queue leaving fullscreen mode */
250 switch_waiting = 0x01;
251 switch_time = SDL_GetTicks() + 200;
252 } 208 }
253 /* gaining focus */ 209 /* gaining focus */
254 else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) 210 else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
255 { 211 {
256 set_motion_sensitivity(this, -1); 212 set_motion_sensitivity(this, -1);
321 } 277 }
322 278
323 /* perform a blocking read if no events available */ 279 /* perform a blocking read if no events available */
324 int ph_Pending(_THIS) 280 int ph_Pending(_THIS)
325 { 281 {
326 /* Flush the display connection and look to see if events are queued */ 282 /* Flush the display connection and look to see if events are queued */
327 PgFlush(); 283 PgFlush();
328 284
329 while( 1 ) 285 while( 1 )
330 { //note this is a non-blocking call 286 { /* note this is a non-blocking call */
331 switch( PhEventPeek( event, EVENT_SIZE ) ) 287 switch( PhEventPeek( event, EVENT_SIZE ) )
332 { 288 {
333 case Ph_EVENT_MSG: 289 case Ph_EVENT_MSG:
334
335 return 1; 290 return 1;
336 break; 291 break;
337 case -1: 292 case -1:
338 perror( "PhEventNext failed" ); 293 perror("ph_Pending(): PhEventNext failed");
339 break; 294 break;
340 default: 295 default:
341 296 return 0;
342 return 0; 297 }
343 } 298 }
344 } 299
345 300 /* Oh well, nothing is ready .. */
346 /* Oh well, nothing is ready .. */ 301 return(0);
347 return(0); 302 }
348 } 303
349 304 void ph_PumpEvents(_THIS)
350 /* 305 {
351 SAMPLE EVENT PUMP 306 /* Flush the display connection and look to see if events are queued */
352 ================= 307 PgFlush();
353 static void update( int block ){ 308
354 309 while (ph_Pending(this))
355 int ch,fl; 310 {
356 PhKeyEvent_t *key; 311 ph_DispatchEvent(this);
357 312 }
358 for( ;; ){ 313 }
359 314
360 if( block ){ 315 void ph_InitKeymap(void)
361 do{ 316 {
362 fl=PhEventNext( event,EVENT_SIZE ); 317 int i;
363 }while( fl!=Ph_EVENT_MSG ); 318
364 block=0; 319 /* Odd keys used in international keyboards */
365 }else{ 320 for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
366 do{ 321 ODD_keymap[i] = SDLK_UNKNOWN;
367 fl=PhEventPeek( event,EVENT_SIZE ); 322
368 if( !fl ) return; 323 /* Map the miscellaneous keys */
369 }while( fl!=Ph_EVENT_MSG ); 324 for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
370 } 325 MISC_keymap[i] = SDLK_UNKNOWN;
371 326
372 switch( event->type ){ 327 MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
373 case Ph_EV_KEY: 328 MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
374 key=PhGetData( event ); 329 MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
375 ch=key->key_cap; // & 127; 330 MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
376 fl=key->key_flags; 331 MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
377 if( ch<32 || ch>127 ) break; 332 MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
378 if( fl & Pk_KF_Key_Down ){ 333 MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
379 if( !(fl & Pk_KF_Key_Repeat) ){ 334
380 if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch; 335 MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
381 keyMatrix[ch]=1; 336 MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
382 } 337 MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
383 }else{ 338 MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
384 keyMatrix[ch]=0; 339 MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
385 } 340 MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
386 break; 341 MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
342 MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
343 MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
344 MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
345
346 MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
347 MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
348 MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
349 MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
350 MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
351 MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
352 MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
353
354 MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
355 MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
356 MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
357 MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
358 MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
359 MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
360 MISC_keymap[Pk_End&0xFF] = SDLK_END;
361 MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
362 MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
363
364 MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
365 MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
366 MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
367 MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
368 MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
369 MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
370 MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
371 MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
372 MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
373 MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
374 MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
375 MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
376 MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
377 MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
378 MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
379
380 MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
381 MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
382 MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
383 MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
384 MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
385 MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
386 MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
387 MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
388 MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
389 MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
390 MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
391 MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
392 MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows" */
393 MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
394
395 MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
396 MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
397 MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
398 MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
399 MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */
400 }
401
402 static unsigned long cap;
403
404 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
405 {
406 /* 'sym' is set to the value of the key with modifiers applied to it.
407 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
408 We will assume it is valid. */
409
410 /* FIXME: This needs to check whether the cap & scancode is valid */
411
412 cap = key->key_cap;
413
414 switch (cap>>8)
415 {
416 case 0x00: /* Latin 1 */
417 case 0x01: /* Latin 2 */
418 case 0x02: /* Latin 3 */
419 case 0x03: /* Latin 4 */
420 case 0x04: /* Katakana */
421 case 0x05: /* Arabic */
422 case 0x06: /* Cyrillic */
423 case 0x07: /* Greek */
424 case 0x08: /* Technical */
425 case 0x0A: /* Publishing */
426 case 0x0C: /* Hebrew */
427 case 0x0D: /* Thai */
428 keysym->sym = (SDLKey)(cap&0xFF);
429 /* Map capital letter syms to lowercase */
430 if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
431 keysym->sym += ('a'-'A');
432 break;
433 case 0xF0:
434 keysym->sym = MISC_keymap[cap&0xFF];
435 break;
387 default: 436 default:
388 PtEventHandler( event ); 437 keysym->sym = SDLK_UNKNOWN;
389 } 438 break;
390 } 439 }
391 } 440
392 */ 441 keysym->scancode = key->key_scan;
393 442 keysym->unicode = 0;
394 void ph_PumpEvents(_THIS) 443
395 { 444 if (SDL_TranslateUNICODE)
396 int pending; 445 {
397 446 char utf8[MB_CUR_MAX];
398 /* Keep processing pending events */ 447 int utf8len;
399 pending = 0; 448 wchar_t unicode;
400 while ( ph_Pending(this) ) { 449
401 ph_DispatchEvent(this); 450 utf8len = PhKeyToMb(utf8, key);
402 ++pending; 451 if (utf8len > 0)
403 } 452 {
404 if ( switch_waiting ) { 453 utf8len = mbtowc(&unicode, utf8, utf8len);
405 Uint32 now; 454 if (utf8len > 0)
406 455 keysym->unicode = unicode;
407 now = SDL_GetTicks(); 456 }
408 #if 0 457 }
409 if ( pending || !SDL_VideoSurface ) { 458
410 /* Try again later... */ 459 return (keysym);
411 if ( switch_waiting & SDL_FULLSCREEN ) {
412 switch_time = now + 1500;
413 } else {
414 switch_time = now + 200;
415 }
416 } else if ( now >= switch_time ) {
417 Uint32 go_fullscreen;
418
419 go_fullscreen = switch_waiting & SDL_FULLSCREEN;
420 switch_waiting = 0;
421 if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
422 if ( go_fullscreen ) {
423 ph_EnterFullScreen(this);
424 } else {
425 ph_LeaveFullScreen(this);
426 }
427 }
428 /* Handle focus in/out when grabbed */
429 /*
430 if ( go_fullscreen ) {
431 ph_GrabInputNoLock(this, this->input_grab);
432 } else {
433 ph_GrabInputNoLock(this, SDL_GRAB_OFF);
434 }
435 */
436 }
437 #endif
438 }
439 }
440
441 void ph_InitKeymap(void)
442 {
443 int i;
444
445 /* Odd keys used in international keyboards */
446 for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
447 ODD_keymap[i] = SDLK_UNKNOWN;
448
449 /* Map the miscellaneous keys */
450 for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
451 MISC_keymap[i] = SDLK_UNKNOWN;
452
453 MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
454 MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
455 MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
456 MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
457 MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
458 MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
459 MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
460
461 MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
462 MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
463 MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
464 MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
465 MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
466 MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
467 MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
468 MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
469 MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
470 MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
471
472 MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
473 MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
474 MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
475 MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
476 MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
477 MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
478 MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
479
480 MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
481 MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
482 MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
483 MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
484 MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
485 MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
486 MISC_keymap[Pk_End&0xFF] = SDLK_END;
487 MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
488 MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
489
490 MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
491 MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
492 MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
493 MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
494 MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
495 MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
496 MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
497 MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
498 MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
499 MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
500 MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
501 MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
502 MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
503 MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
504 MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
505
506 MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
507 MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
508 MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
509 MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
510 MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
511 MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
512 MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
513 MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
514 MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
515 MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
516 MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
517 MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
518 MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
519 MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
520
521 MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
522 MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
523 // MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
524 MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
525 MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
526 MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */
527 }
528
529 static unsigned long cap;
530
531 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
532 {
533 /*
534 'sym' is set to the value of the key with modifiers applied to it.
535 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
536 We will assume it is valid.
537 */
538 /* FIXME: This needs to check whether the cap & scancode is valid */
539 cap = key->key_cap;
540 switch (cap>>8) {
541 case 0x00: /* Latin 1 */
542 case 0x01: /* Latin 2 */
543 case 0x02: /* Latin 3 */
544 case 0x03: /* Latin 4 */
545 case 0x04: /* Katakana */
546 case 0x05: /* Arabic */
547 case 0x06: /* Cyrillic */
548 case 0x07: /* Greek */
549 case 0x08: /* Technical */
550 case 0x0A: /* Publishing */
551 case 0x0C: /* Hebrew */
552 case 0x0D: /* Thai */
553 keysym->sym = (SDLKey)(cap&0xFF);
554 /* Map capital letter syms to lowercase */
555 if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
556 keysym->sym += ('a'-'A');
557 break;
558 // case 0xFE:
559 // keysym->sym = ODD_keymap[sym&0xFF];
560 // break;
561 case 0xF0:
562 keysym->sym = MISC_keymap[cap&0xFF];
563 break;
564 default:
565 /* fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
566 keysym->sym = SDLK_UNKNOWN;
567 break;
568 }
569 keysym->scancode = key->key_scan;
570 keysym->unicode = 0;
571 if( SDL_TranslateUNICODE )
572 {
573 char utf8[MB_CUR_MAX];
574 int utf8len;
575 wchar_t unicode;
576
577 utf8len = PhKeyToMb( utf8, key );
578 if( utf8len > 0 )
579 {
580 utf8len = mbtowc( &unicode, utf8, utf8len );
581 if( utf8len > 0)
582 keysym->unicode = unicode;
583 }
584 }
585
586 return (keysym);
587 } 460 }
588 461
589 void ph_InitOSKeymap(_THIS) 462 void ph_InitOSKeymap(_THIS)
590 { 463 {
591 ph_InitKeymap(); 464 ph_InitKeymap();
592 } 465 }
593