src/video/photon/SDL_ph_events.c
changeset 571 8e3ce997621c
parent 320 66f815c147ed
child 663 8bedd6d61642
     1.1 --- a/src/video/photon/SDL_ph_events.c	Mon Jan 20 01:37:07 2003 +0000
     1.2 +++ b/src/video/photon/SDL_ph_events.c	Mon Jan 20 01:38:37 2003 +0000
     1.3 @@ -55,67 +55,28 @@
     1.4     (idea shamelessly lifted from GII -- thanks guys! :)
     1.5   */
     1.6  
     1.7 -#if 0
     1.8 -static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
     1.9 -{
    1.10 -//	PhEvent_t* peekevent;
    1.11 -	PhKeyEvent_t* keyEvent;
    1.12 -	int repeated;
    1.13 -
    1.14 -	repeated = 0;
    1.15 -	switch (PhEventPeek( peekevent, EVENT_SIZE ))
    1.16 -	{
    1.17 -		case Ph_EVENT_MSG: {
    1.18 -			if(peekevent->type == Ph_EV_KEY)
    1.19 -			{
    1.20 -				keyEvent = PhGetData( peekevent );
    1.21 -				if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
    1.22 -					(keyEvent->key_cap == keyevent->key_cap) &&
    1.23 -					(peekevent->timestamp == event->timestamp)	
    1.24 -				) {
    1.25 -					repeated = 1;
    1.26 -					 /* PhEventNext( peekevent, EVENT_SIZE ); */
    1.27 -				}				
    1.28 -			}
    1.29 -		}
    1.30 -		break;
    1.31 -
    1.32 -		case -1: {
    1.33 -			perror( "PhEventPeek failed" );
    1.34 -		}
    1.35 -		break;
    1.36 -
    1.37 -		default: /* no events pending */
    1.38 -	}
    1.39 -	return(repeated);
    1.40 -}
    1.41 -#endif
    1.42 -
    1.43  static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
    1.44  {
    1.45 -/*	PhPointerEvent_t *pointer = PhGetData( winEvent ); */
    1.46 -	PhRect_t *rect = PhGetRects( winEvent );
    1.47 +    PhRect_t *rect = PhGetRects( winEvent );
    1.48  
    1.49 -	int centre_x, centre_y;
    1.50 -	int dx, dy;
    1.51 -        short abs_x, abs_y;
    1.52 -	int posted;
    1.53 +    int centre_x, centre_y;
    1.54 +    int dx, dy;
    1.55 +    short abs_x, abs_y;
    1.56 +    int posted;
    1.57  
    1.58 -	centre_x = SDL_VideoSurface->w / 2;
    1.59 -	centre_y = SDL_VideoSurface->h / 2;
    1.60 +    centre_x = SDL_VideoSurface->w / 2;
    1.61 +    centre_y = SDL_VideoSurface->h / 2;
    1.62  
    1.63 -	dx = rect->ul.x - centre_x;
    1.64 -	dy = rect->ul.y - centre_y;
    1.65 +    dx = rect->ul.x - centre_x;
    1.66 +    dy = rect->ul.y - centre_y;
    1.67  
    1.68 -	posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
    1.69 +    posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
    1.70  
    1.71 -	/* Move mouse cursor to middle of the window */
    1.72 -	PtGetAbsPosition( window, &abs_x, &abs_y );
    1.73 -	PhMoveCursorAbs( PhInputGroup(NULL),
    1.74 -			abs_x + centre_x,
    1.75 -			abs_y + centre_y );
    1.76 +    /* Move mouse cursor to middle of the window */
    1.77 +    PtGetAbsPosition( window, &abs_x, &abs_y );
    1.78 +    PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
    1.79  
    1.80 -	return(posted);
    1.81 +    return (posted);
    1.82  }
    1.83  
    1.84  /* Control which motion flags the window has set, a flags value of -1 sets
    1.85 @@ -123,35 +84,34 @@
    1.86  
    1.87  static void set_motion_sensitivity(_THIS, unsigned int flags)
    1.88  {
    1.89 -	int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
    1.90 -	PhRegion_t region;
    1.91 +    int rid;
    1.92 +    int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
    1.93 +    PhRegion_t region;
    1.94  
    1.95 -	if( window )
    1.96 -	{
    1.97 -		rid = PtWidgetRid( window );
    1.98 -		if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
    1.99 -		{
   1.100 -			region.events_sense = ( region.events_sense & ~fields ) |
   1.101 -				( flags & fields );
   1.102 -			PhRegionChange( Ph_REGION_EV_SENSE, 0, &region,
   1.103 -					NULL, NULL );
   1.104 -		}
   1.105 -	}
   1.106 +    if( window )
   1.107 +    {
   1.108 +        rid = PtWidgetRid( window );
   1.109 +        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
   1.110 +        {
   1.111 +            region.events_sense=(region.events_sense & ~fields)|(flags & fields);
   1.112 +            PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
   1.113 +        }
   1.114 +    }
   1.115  }
   1.116  
   1.117  /* Convert the photon button state value to an SDL value */
   1.118 -static Uint8 ph2sdl_mousebutton( unsigned short button_state )
   1.119 +static Uint8 ph2sdl_mousebutton(unsigned short button_state)
   1.120  {
   1.121 -	Uint8 mouse_button = 0;
   1.122 +    Uint8 mouse_button = 0;
   1.123  
   1.124 -	if( button_state & Ph_BUTTON_SELECT )
   1.125 -			mouse_button |= SDL_BUTTON_LEFT;
   1.126 -	if( button_state & Ph_BUTTON_MENU )
   1.127 -			mouse_button |= SDL_BUTTON_RIGHT;
   1.128 -	if( button_state & Ph_BUTTON_ADJUST )
   1.129 -			mouse_button |= SDL_BUTTON_MIDDLE;
   1.130 +    if (button_state & Ph_BUTTON_SELECT)
   1.131 +        mouse_button |= SDL_BUTTON_LEFT;
   1.132 +    if (button_state & Ph_BUTTON_MENU)
   1.133 +        mouse_button |= SDL_BUTTON_RIGHT;
   1.134 +    if (button_state & Ph_BUTTON_ADJUST)
   1.135 +        mouse_button |= SDL_BUTTON_MIDDLE;
   1.136  
   1.137 -	return( mouse_button );
   1.138 +    return (mouse_button);
   1.139  }
   1.140  
   1.141  static int ph_DispatchEvent(_THIS)
   1.142 @@ -245,10 +205,6 @@
   1.143              {
   1.144                  set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
   1.145                  posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   1.146 -
   1.147 -                /* Queue leaving fullscreen mode */
   1.148 -                switch_waiting = 0x01;
   1.149 -                switch_time = SDL_GetTicks() + 200;
   1.150              }
   1.151              /* gaining focus */
   1.152              else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   1.153 @@ -323,271 +279,187 @@
   1.154  /* perform a blocking read if no events available */
   1.155  int ph_Pending(_THIS)
   1.156  {
   1.157 -	/* Flush the display connection and look to see if events are queued */
   1.158 -	PgFlush();
   1.159 +    /* Flush the display connection and look to see if events are queued */
   1.160 +    PgFlush();
   1.161  
   1.162 -     while( 1 )
   1.163 -      {   //note this is a non-blocking call
   1.164 -          switch( PhEventPeek( event, EVENT_SIZE ) )
   1.165 -           {
   1.166 -              case Ph_EVENT_MSG:
   1.167 -                 
   1.168 +    while( 1 )
   1.169 +    {   /* note this is a non-blocking call */
   1.170 +        switch( PhEventPeek( event, EVENT_SIZE ) )
   1.171 +        {
   1.172 +            case Ph_EVENT_MSG:
   1.173                   return 1;
   1.174                   break;
   1.175 -              case -1:
   1.176 -                 perror( "PhEventNext failed" );
   1.177 +            case -1:
   1.178 +                 perror("ph_Pending(): PhEventNext failed");
   1.179                   break;
   1.180 -              default:
   1.181 -             	  
   1.182 -                return 0;
   1.183 -       }
   1.184 -   }
   1.185 -
   1.186 -	/* Oh well, nothing is ready .. */
   1.187 -	return(0);
   1.188 -}
   1.189 -
   1.190 -/*
   1.191 -SAMPLE EVENT PUMP
   1.192 -=================
   1.193 -static void update( int block ){
   1.194 -
   1.195 -    int ch,fl;
   1.196 -    PhKeyEvent_t *key;
   1.197 -
   1.198 -    for( ;; ){
   1.199 -
   1.200 -        if( block ){
   1.201 -            do{
   1.202 -                fl=PhEventNext( event,EVENT_SIZE );
   1.203 -            }while( fl!=Ph_EVENT_MSG );
   1.204 -            block=0;
   1.205 -        }else{
   1.206 -            do{
   1.207 -                fl=PhEventPeek( event,EVENT_SIZE );
   1.208 -                if( !fl ) return;
   1.209 -            }while( fl!=Ph_EVENT_MSG );
   1.210 -        }
   1.211 -
   1.212 -        switch( event->type ){
   1.213 -        case Ph_EV_KEY:
   1.214 -            key=PhGetData( event );
   1.215 -            ch=key->key_cap;    // & 127;
   1.216 -            fl=key->key_flags;
   1.217 -            if( ch<32 || ch>127 ) break;
   1.218 -            if( fl & Pk_KF_Key_Down ){
   1.219 -                if( !(fl & Pk_KF_Key_Repeat) ){
   1.220 -                    if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch;
   1.221 -                    keyMatrix[ch]=1;
   1.222 -                }
   1.223 -            }else{
   1.224 -                keyMatrix[ch]=0;
   1.225 -            }
   1.226 -            break;
   1.227 -        default:
   1.228 -            PtEventHandler( event );
   1.229 +            default:
   1.230 +                 return 0;
   1.231          }
   1.232      }
   1.233 +
   1.234 +    /* Oh well, nothing is ready .. */
   1.235 +    return(0);
   1.236  }
   1.237 -*/
   1.238  
   1.239  void ph_PumpEvents(_THIS)
   1.240  {
   1.241 -	int pending;
   1.242 +    /* Flush the display connection and look to see if events are queued */
   1.243 +    PgFlush();
   1.244  
   1.245 -	/* Keep processing pending events */
   1.246 -	pending = 0;
   1.247 -	while ( ph_Pending(this) ) {
   1.248 -		ph_DispatchEvent(this);
   1.249 -		++pending;
   1.250 -	}
   1.251 -	if ( switch_waiting ) {
   1.252 -		Uint32 now;
   1.253 -
   1.254 -		now  = SDL_GetTicks();
   1.255 -#if 0
   1.256 -		if ( pending || !SDL_VideoSurface ) {
   1.257 -			/* Try again later... */
   1.258 -			if ( switch_waiting & SDL_FULLSCREEN ) {
   1.259 -				switch_time = now + 1500;
   1.260 -			} else {
   1.261 -				switch_time = now + 200;
   1.262 -			}
   1.263 -		} else if ( now >= switch_time ) {
   1.264 -			Uint32 go_fullscreen;
   1.265 -
   1.266 -			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
   1.267 -			switch_waiting = 0;
   1.268 -			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
   1.269 -				if ( go_fullscreen ) {
   1.270 -					ph_EnterFullScreen(this);
   1.271 -				} else {
   1.272 -					ph_LeaveFullScreen(this);
   1.273 -				}
   1.274 -			}
   1.275 -			/* Handle focus in/out when grabbed */
   1.276 -/*
   1.277 -			if ( go_fullscreen ) {
   1.278 -				ph_GrabInputNoLock(this, this->input_grab);
   1.279 -			} else {
   1.280 -				ph_GrabInputNoLock(this, SDL_GRAB_OFF);
   1.281 -			}
   1.282 -*/
   1.283 -		}
   1.284 -#endif
   1.285 -	}
   1.286 +    while (ph_Pending(this))
   1.287 +    {
   1.288 +        ph_DispatchEvent(this);
   1.289 +    }
   1.290  }
   1.291  
   1.292  void ph_InitKeymap(void)
   1.293  {
   1.294 -	int i;
   1.295 +    int i;
   1.296  
   1.297 -	/* Odd keys used in international keyboards */
   1.298 -	for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
   1.299 -		ODD_keymap[i] = SDLK_UNKNOWN;
   1.300 +    /* Odd keys used in international keyboards */
   1.301 +    for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
   1.302 +        ODD_keymap[i] = SDLK_UNKNOWN;
   1.303  
   1.304 -	/* Map the miscellaneous keys */
   1.305 -	for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
   1.306 -		MISC_keymap[i] = SDLK_UNKNOWN;
   1.307 +    /* Map the miscellaneous keys */
   1.308 +    for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
   1.309 +        MISC_keymap[i] = SDLK_UNKNOWN;
   1.310  
   1.311 -	MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   1.312 -	MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   1.313 -	MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
   1.314 -	MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
   1.315 -	MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
   1.316 -	MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
   1.317 -	MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
   1.318 +    MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   1.319 +    MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   1.320 +    MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
   1.321 +    MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
   1.322 +    MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
   1.323 +    MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
   1.324 +    MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
   1.325  
   1.326 -	MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
   1.327 -	MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
   1.328 -	MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
   1.329 -	MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
   1.330 -	MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
   1.331 -	MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
   1.332 -	MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
   1.333 -	MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
   1.334 -	MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
   1.335 -	MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
   1.336 +    MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
   1.337 +    MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
   1.338 +    MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
   1.339 +    MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
   1.340 +    MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
   1.341 +    MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
   1.342 +    MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
   1.343 +    MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
   1.344 +    MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
   1.345 +    MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
   1.346  
   1.347 -	MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
   1.348 -	MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
   1.349 -	MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
   1.350 -	MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
   1.351 -	MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
   1.352 -	MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
   1.353 -	MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
   1.354 +    MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
   1.355 +    MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
   1.356 +    MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
   1.357 +    MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
   1.358 +    MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
   1.359 +    MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
   1.360 +    MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
   1.361  
   1.362 -	MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
   1.363 -	MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
   1.364 -	MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
   1.365 -	MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
   1.366 -	MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
   1.367 -	MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
   1.368 -	MISC_keymap[Pk_End&0xFF] = SDLK_END;
   1.369 -	MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
   1.370 -	MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
   1.371 +    MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
   1.372 +    MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
   1.373 +    MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
   1.374 +    MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
   1.375 +    MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
   1.376 +    MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
   1.377 +    MISC_keymap[Pk_End&0xFF] = SDLK_END;
   1.378 +    MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
   1.379 +    MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
   1.380  
   1.381 -	MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
   1.382 -	MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
   1.383 -	MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
   1.384 -	MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
   1.385 -	MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
   1.386 -	MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
   1.387 -	MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
   1.388 -	MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
   1.389 -	MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
   1.390 -	MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
   1.391 -	MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
   1.392 -	MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
   1.393 -	MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
   1.394 -	MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
   1.395 -	MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
   1.396 +    MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
   1.397 +    MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
   1.398 +    MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
   1.399 +    MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
   1.400 +    MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
   1.401 +    MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
   1.402 +    MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
   1.403 +    MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
   1.404 +    MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
   1.405 +    MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
   1.406 +    MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
   1.407 +    MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
   1.408 +    MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
   1.409 +    MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
   1.410 +    MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
   1.411  
   1.412 -	MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
   1.413 -	MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
   1.414 -	MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
   1.415 -	MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
   1.416 -	MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
   1.417 -	MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
   1.418 -	MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
   1.419 -	MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
   1.420 -	MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   1.421 -	MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   1.422 -	MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   1.423 -	MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
   1.424 -	MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
   1.425 -	MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
   1.426 +    MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
   1.427 +    MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
   1.428 +    MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
   1.429 +    MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
   1.430 +    MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
   1.431 +    MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
   1.432 +    MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
   1.433 +    MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
   1.434 +    MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   1.435 +    MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   1.436 +    MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   1.437 +    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
   1.438 +    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   1.439 +    MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
   1.440  
   1.441 -	MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   1.442 -	MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   1.443 -//	MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
   1.444 -	MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   1.445 -	MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   1.446 -	MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   1.447 +    MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   1.448 +    MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   1.449 +    MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   1.450 +    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   1.451 +    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   1.452  }
   1.453  
   1.454  static unsigned long cap;
   1.455  
   1.456  SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
   1.457  {
   1.458 -/*	
   1.459 -	'sym' is set to the value of the key with modifiers applied to it. 
   1.460 -	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   1.461 -	We will assume it is valid.
   1.462 -*/
   1.463 -	/* FIXME: This needs to check whether the cap & scancode is valid */
   1.464 -	cap = key->key_cap;
   1.465 -	switch (cap>>8) {
   1.466 -            case 0x00:  /* Latin 1 */
   1.467 -            case 0x01:  /* Latin 2 */
   1.468 -            case 0x02:  /* Latin 3 */
   1.469 -            case 0x03:  /* Latin 4 */
   1.470 -            case 0x04:  /* Katakana */
   1.471 -            case 0x05:  /* Arabic */
   1.472 -            case 0x06:  /* Cyrillic */
   1.473 -            case 0x07:  /* Greek */
   1.474 -            case 0x08:  /* Technical */
   1.475 -            case 0x0A:  /* Publishing */
   1.476 -            case 0x0C:  /* Hebrew */
   1.477 -            case 0x0D:  /* Thai */
   1.478 -                keysym->sym = (SDLKey)(cap&0xFF);
   1.479 -                /* Map capital letter syms to lowercase */
   1.480 -                if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
   1.481 -                    keysym->sym += ('a'-'A');
   1.482 -                break;
   1.483 -//            case 0xFE:
   1.484 -//                keysym->sym = ODD_keymap[sym&0xFF];
   1.485 -//                break;
   1.486 -            case 0xF0:
   1.487 -                keysym->sym = MISC_keymap[cap&0xFF];
   1.488 -                break;
   1.489 -            default:
   1.490 -/*                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
   1.491 -		keysym->sym = SDLK_UNKNOWN;                
   1.492 -                break;
   1.493 -	}
   1.494 -	keysym->scancode = key->key_scan;
   1.495 -	keysym->unicode = 0;
   1.496 -	if( SDL_TranslateUNICODE )
   1.497 -	{
   1.498 -		char utf8[MB_CUR_MAX];
   1.499 -		int utf8len;
   1.500 -		wchar_t unicode;
   1.501 +    /* 'sym' is set to the value of the key with modifiers applied to it.
   1.502 +       This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   1.503 +       We will assume it is valid. */
   1.504  
   1.505 -		utf8len = PhKeyToMb( utf8, key );
   1.506 -		if( utf8len > 0 )
   1.507 -		{
   1.508 -			utf8len = mbtowc( &unicode, utf8, utf8len );
   1.509 -			if( utf8len > 0)
   1.510 -				keysym->unicode = unicode;
   1.511 -		}
   1.512 -	}
   1.513 +    /* FIXME: This needs to check whether the cap & scancode is valid */
   1.514  
   1.515 -	return (keysym);
   1.516 +    cap = key->key_cap;
   1.517 +
   1.518 +    switch (cap>>8)
   1.519 +    {
   1.520 +        case 0x00:  /* Latin 1 */
   1.521 +        case 0x01:  /* Latin 2 */
   1.522 +        case 0x02:  /* Latin 3 */
   1.523 +        case 0x03:  /* Latin 4 */
   1.524 +        case 0x04:  /* Katakana */
   1.525 +        case 0x05:  /* Arabic */
   1.526 +        case 0x06:  /* Cyrillic */
   1.527 +        case 0x07:  /* Greek */
   1.528 +        case 0x08:  /* Technical */
   1.529 +        case 0x0A:  /* Publishing */
   1.530 +        case 0x0C:  /* Hebrew */
   1.531 +        case 0x0D:  /* Thai */
   1.532 +                   keysym->sym = (SDLKey)(cap&0xFF);
   1.533 +                   /* Map capital letter syms to lowercase */
   1.534 +                   if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
   1.535 +                       keysym->sym += ('a'-'A');
   1.536 +                   break;
   1.537 +        case 0xF0:
   1.538 +                   keysym->sym = MISC_keymap[cap&0xFF];
   1.539 +                   break;
   1.540 +        default:
   1.541 +                   keysym->sym = SDLK_UNKNOWN;                
   1.542 +                   break;
   1.543 +    }
   1.544 +
   1.545 +    keysym->scancode = key->key_scan;
   1.546 +    keysym->unicode = 0;
   1.547 +
   1.548 +    if (SDL_TranslateUNICODE)
   1.549 +    {
   1.550 +        char utf8[MB_CUR_MAX];
   1.551 +        int utf8len;
   1.552 +        wchar_t unicode;
   1.553 +
   1.554 +        utf8len = PhKeyToMb(utf8, key);
   1.555 +        if (utf8len > 0)
   1.556 +        {
   1.557 +            utf8len = mbtowc(&unicode, utf8, utf8len);
   1.558 +            if (utf8len > 0)
   1.559 +                keysym->unicode = unicode;
   1.560 +        }
   1.561 +    }
   1.562 +
   1.563 +    return (keysym);
   1.564  }
   1.565  
   1.566  void ph_InitOSKeymap(_THIS)
   1.567  {
   1.568 -	ph_InitKeymap();
   1.569 +    ph_InitKeymap();
   1.570  }
   1.571 -