diff 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
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_events.c	Mon Jan 20 01:37:07 2003 +0000
+++ b/src/video/photon/SDL_ph_events.c	Mon Jan 20 01:38:37 2003 +0000
@@ -55,67 +55,28 @@
    (idea shamelessly lifted from GII -- thanks guys! :)
  */
 
-#if 0
-static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
-{
-//	PhEvent_t* peekevent;
-	PhKeyEvent_t* keyEvent;
-	int repeated;
-
-	repeated = 0;
-	switch (PhEventPeek( peekevent, EVENT_SIZE ))
-	{
-		case Ph_EVENT_MSG: {
-			if(peekevent->type == Ph_EV_KEY)
-			{
-				keyEvent = PhGetData( peekevent );
-				if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
-					(keyEvent->key_cap == keyevent->key_cap) &&
-					(peekevent->timestamp == event->timestamp)	
-				) {
-					repeated = 1;
-					 /* PhEventNext( peekevent, EVENT_SIZE ); */
-				}				
-			}
-		}
-		break;
-
-		case -1: {
-			perror( "PhEventPeek failed" );
-		}
-		break;
-
-		default: /* no events pending */
-	}
-	return(repeated);
-}
-#endif
-
 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
 {
-/*	PhPointerEvent_t *pointer = PhGetData( winEvent ); */
-	PhRect_t *rect = PhGetRects( winEvent );
+    PhRect_t *rect = PhGetRects( winEvent );
 
-	int centre_x, centre_y;
-	int dx, dy;
-        short abs_x, abs_y;
-	int posted;
+    int centre_x, centre_y;
+    int dx, dy;
+    short abs_x, abs_y;
+    int posted;
 
-	centre_x = SDL_VideoSurface->w / 2;
-	centre_y = SDL_VideoSurface->h / 2;
+    centre_x = SDL_VideoSurface->w / 2;
+    centre_y = SDL_VideoSurface->h / 2;
 
-	dx = rect->ul.x - centre_x;
-	dy = rect->ul.y - centre_y;
+    dx = rect->ul.x - centre_x;
+    dy = rect->ul.y - centre_y;
 
-	posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
+    posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
 
-	/* Move mouse cursor to middle of the window */
-	PtGetAbsPosition( window, &abs_x, &abs_y );
-	PhMoveCursorAbs( PhInputGroup(NULL),
-			abs_x + centre_x,
-			abs_y + centre_y );
+    /* Move mouse cursor to middle of the window */
+    PtGetAbsPosition( window, &abs_x, &abs_y );
+    PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
 
-	return(posted);
+    return (posted);
 }
 
 /* Control which motion flags the window has set, a flags value of -1 sets
@@ -123,35 +84,34 @@
 
 static void set_motion_sensitivity(_THIS, unsigned int flags)
 {
-	int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
-	PhRegion_t region;
+    int rid;
+    int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
+    PhRegion_t region;
 
-	if( window )
-	{
-		rid = PtWidgetRid( window );
-		if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
-		{
-			region.events_sense = ( region.events_sense & ~fields ) |
-				( flags & fields );
-			PhRegionChange( Ph_REGION_EV_SENSE, 0, &region,
-					NULL, NULL );
-		}
-	}
+    if( window )
+    {
+        rid = PtWidgetRid( window );
+        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
+        {
+            region.events_sense=(region.events_sense & ~fields)|(flags & fields);
+            PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
+        }
+    }
 }
 
 /* Convert the photon button state value to an SDL value */
-static Uint8 ph2sdl_mousebutton( unsigned short button_state )
+static Uint8 ph2sdl_mousebutton(unsigned short button_state)
 {
-	Uint8 mouse_button = 0;
+    Uint8 mouse_button = 0;
 
-	if( button_state & Ph_BUTTON_SELECT )
-			mouse_button |= SDL_BUTTON_LEFT;
-	if( button_state & Ph_BUTTON_MENU )
-			mouse_button |= SDL_BUTTON_RIGHT;
-	if( button_state & Ph_BUTTON_ADJUST )
-			mouse_button |= SDL_BUTTON_MIDDLE;
+    if (button_state & Ph_BUTTON_SELECT)
+        mouse_button |= SDL_BUTTON_LEFT;
+    if (button_state & Ph_BUTTON_MENU)
+        mouse_button |= SDL_BUTTON_RIGHT;
+    if (button_state & Ph_BUTTON_ADJUST)
+        mouse_button |= SDL_BUTTON_MIDDLE;
 
-	return( mouse_button );
+    return (mouse_button);
 }
 
 static int ph_DispatchEvent(_THIS)
@@ -245,10 +205,6 @@
             {
                 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
                 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
-
-                /* Queue leaving fullscreen mode */
-                switch_waiting = 0x01;
-                switch_time = SDL_GetTicks() + 200;
             }
             /* gaining focus */
             else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
@@ -323,271 +279,187 @@
 /* perform a blocking read if no events available */
 int ph_Pending(_THIS)
 {
-	/* Flush the display connection and look to see if events are queued */
-	PgFlush();
+    /* Flush the display connection and look to see if events are queued */
+    PgFlush();
 
-     while( 1 )
-      {   //note this is a non-blocking call
-          switch( PhEventPeek( event, EVENT_SIZE ) )
-           {
-              case Ph_EVENT_MSG:
-                 
+    while( 1 )
+    {   /* note this is a non-blocking call */
+        switch( PhEventPeek( event, EVENT_SIZE ) )
+        {
+            case Ph_EVENT_MSG:
                  return 1;
                  break;
-              case -1:
-                 perror( "PhEventNext failed" );
+            case -1:
+                 perror("ph_Pending(): PhEventNext failed");
                  break;
-              default:
-             	  
-                return 0;
-       }
-   }
-
-	/* Oh well, nothing is ready .. */
-	return(0);
-}
-
-/*
-SAMPLE EVENT PUMP
-=================
-static void update( int block ){
-
-    int ch,fl;
-    PhKeyEvent_t *key;
-
-    for( ;; ){
-
-        if( block ){
-            do{
-                fl=PhEventNext( event,EVENT_SIZE );
-            }while( fl!=Ph_EVENT_MSG );
-            block=0;
-        }else{
-            do{
-                fl=PhEventPeek( event,EVENT_SIZE );
-                if( !fl ) return;
-            }while( fl!=Ph_EVENT_MSG );
-        }
-
-        switch( event->type ){
-        case Ph_EV_KEY:
-            key=PhGetData( event );
-            ch=key->key_cap;    // & 127;
-            fl=key->key_flags;
-            if( ch<32 || ch>127 ) break;
-            if( fl & Pk_KF_Key_Down ){
-                if( !(fl & Pk_KF_Key_Repeat) ){
-                    if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch;
-                    keyMatrix[ch]=1;
-                }
-            }else{
-                keyMatrix[ch]=0;
-            }
-            break;
-        default:
-            PtEventHandler( event );
+            default:
+                 return 0;
         }
     }
+
+    /* Oh well, nothing is ready .. */
+    return(0);
 }
-*/
 
 void ph_PumpEvents(_THIS)
 {
-	int pending;
-
-	/* Keep processing pending events */
-	pending = 0;
-	while ( ph_Pending(this) ) {
-		ph_DispatchEvent(this);
-		++pending;
-	}
-	if ( switch_waiting ) {
-		Uint32 now;
+    /* Flush the display connection and look to see if events are queued */
+    PgFlush();
 
-		now  = SDL_GetTicks();
-#if 0
-		if ( pending || !SDL_VideoSurface ) {
-			/* Try again later... */
-			if ( switch_waiting & SDL_FULLSCREEN ) {
-				switch_time = now + 1500;
-			} else {
-				switch_time = now + 200;
-			}
-		} else if ( now >= switch_time ) {
-			Uint32 go_fullscreen;
-
-			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
-			switch_waiting = 0;
-			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
-				if ( go_fullscreen ) {
-					ph_EnterFullScreen(this);
-				} else {
-					ph_LeaveFullScreen(this);
-				}
-			}
-			/* Handle focus in/out when grabbed */
-/*
-			if ( go_fullscreen ) {
-				ph_GrabInputNoLock(this, this->input_grab);
-			} else {
-				ph_GrabInputNoLock(this, SDL_GRAB_OFF);
-			}
-*/
-		}
-#endif
-	}
+    while (ph_Pending(this))
+    {
+        ph_DispatchEvent(this);
+    }
 }
 
 void ph_InitKeymap(void)
 {
-	int i;
+    int i;
 
-	/* Odd keys used in international keyboards */
-	for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
-		ODD_keymap[i] = SDLK_UNKNOWN;
+    /* Odd keys used in international keyboards */
+    for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
+        ODD_keymap[i] = SDLK_UNKNOWN;
 
-	/* Map the miscellaneous keys */
-	for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
-		MISC_keymap[i] = SDLK_UNKNOWN;
+    /* Map the miscellaneous keys */
+    for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
+        MISC_keymap[i] = SDLK_UNKNOWN;
 
-	MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
-	MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
-	MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
-	MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
-	MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
-	MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
-	MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
+    MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
+    MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
+    MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
+    MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
+    MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
+    MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
+    MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
 
-	MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
-	MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
-	MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
-	MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
-	MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
-	MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
-	MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
-	MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
-	MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
-	MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
+    MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
+    MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
+    MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
+    MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
+    MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
+    MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
+    MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
+    MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
+    MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
+    MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
 
-	MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
-	MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
-	MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
-	MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
-	MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
-	MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
-	MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
+    MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
+    MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
+    MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
+    MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
+    MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
+    MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
+    MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
 
-	MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
-	MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
-	MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
-	MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
-	MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
-	MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
-	MISC_keymap[Pk_End&0xFF] = SDLK_END;
-	MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
-	MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
+    MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
+    MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
+    MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
+    MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
+    MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
+    MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
+    MISC_keymap[Pk_End&0xFF] = SDLK_END;
+    MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
+    MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
 
-	MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
-	MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
-	MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
-	MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
-	MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
-	MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
-	MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
-	MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
-	MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
-	MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
-	MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
-	MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
-	MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
-	MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
-	MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
+    MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
+    MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
+    MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
+    MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
+    MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
+    MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
+    MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
+    MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
+    MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
+    MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
+    MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
+    MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
+    MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
+    MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
+    MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
 
-	MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
-	MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
-	MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
-	MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
-	MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
-	MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
-	MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
-	MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
-	MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
-	MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
-	MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
-	MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
-	MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
-	MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
+    MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
+    MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
+    MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
+    MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
+    MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
+    MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
+    MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
+    MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
+    MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
+    MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
+    MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
+    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
+    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
+    MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
 
-	MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
-	MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
-//	MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
-	MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
-	MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
-	MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
+    MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
+    MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
+    MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
+    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
+    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
 }
 
 static unsigned long cap;
 
 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
 {
-/*	
-	'sym' is set to the value of the key with modifiers applied to it. 
-	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
-	We will assume it is valid.
-*/
-	/* FIXME: This needs to check whether the cap & scancode is valid */
-	cap = key->key_cap;
-	switch (cap>>8) {
-            case 0x00:  /* Latin 1 */
-            case 0x01:  /* Latin 2 */
-            case 0x02:  /* Latin 3 */
-            case 0x03:  /* Latin 4 */
-            case 0x04:  /* Katakana */
-            case 0x05:  /* Arabic */
-            case 0x06:  /* Cyrillic */
-            case 0x07:  /* Greek */
-            case 0x08:  /* Technical */
-            case 0x0A:  /* Publishing */
-            case 0x0C:  /* Hebrew */
-            case 0x0D:  /* Thai */
-                keysym->sym = (SDLKey)(cap&0xFF);
-                /* Map capital letter syms to lowercase */
-                if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
-                    keysym->sym += ('a'-'A');
-                break;
-//            case 0xFE:
-//                keysym->sym = ODD_keymap[sym&0xFF];
-//                break;
-            case 0xF0:
-                keysym->sym = MISC_keymap[cap&0xFF];
-                break;
-            default:
-/*                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
-		keysym->sym = SDLK_UNKNOWN;                
-                break;
-	}
-	keysym->scancode = key->key_scan;
-	keysym->unicode = 0;
-	if( SDL_TranslateUNICODE )
-	{
-		char utf8[MB_CUR_MAX];
-		int utf8len;
-		wchar_t unicode;
+    /* 'sym' is set to the value of the key with modifiers applied to it.
+       This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
+       We will assume it is valid. */
+
+    /* FIXME: This needs to check whether the cap & scancode is valid */
+
+    cap = key->key_cap;
 
-		utf8len = PhKeyToMb( utf8, key );
-		if( utf8len > 0 )
-		{
-			utf8len = mbtowc( &unicode, utf8, utf8len );
-			if( utf8len > 0)
-				keysym->unicode = unicode;
-		}
-	}
+    switch (cap>>8)
+    {
+        case 0x00:  /* Latin 1 */
+        case 0x01:  /* Latin 2 */
+        case 0x02:  /* Latin 3 */
+        case 0x03:  /* Latin 4 */
+        case 0x04:  /* Katakana */
+        case 0x05:  /* Arabic */
+        case 0x06:  /* Cyrillic */
+        case 0x07:  /* Greek */
+        case 0x08:  /* Technical */
+        case 0x0A:  /* Publishing */
+        case 0x0C:  /* Hebrew */
+        case 0x0D:  /* Thai */
+                   keysym->sym = (SDLKey)(cap&0xFF);
+                   /* Map capital letter syms to lowercase */
+                   if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
+                       keysym->sym += ('a'-'A');
+                   break;
+        case 0xF0:
+                   keysym->sym = MISC_keymap[cap&0xFF];
+                   break;
+        default:
+                   keysym->sym = SDLK_UNKNOWN;                
+                   break;
+    }
 
-	return (keysym);
+    keysym->scancode = key->key_scan;
+    keysym->unicode = 0;
+
+    if (SDL_TranslateUNICODE)
+    {
+        char utf8[MB_CUR_MAX];
+        int utf8len;
+        wchar_t unicode;
+
+        utf8len = PhKeyToMb(utf8, key);
+        if (utf8len > 0)
+        {
+            utf8len = mbtowc(&unicode, utf8, utf8len);
+            if (utf8len > 0)
+                keysym->unicode = unicode;
+        }
+    }
+
+    return (keysym);
 }
 
 void ph_InitOSKeymap(_THIS)
 {
-	ph_InitKeymap();
+    ph_InitKeymap();
 }
-