src/video/photon/SDL_ph_events.c
changeset 0 74212992fb08
child 19 8cc4dbfab9ab
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/photon/SDL_ph_events.c	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,563 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* Handle the event stream, converting photon events into SDL events */
    1.32 +
    1.33 +#include <Ph.h>
    1.34 +#include <stdio.h>
    1.35 +#include <setjmp.h>
    1.36 +#include <photon/PkKeyDef.h>
    1.37 +#include <sys/time.h>
    1.38 +
    1.39 +#include "SDL.h"
    1.40 +#include "SDL_syswm.h"
    1.41 +#include "SDL_sysevents.h"
    1.42 +#include "SDL_sysvideo.h"
    1.43 +#include "SDL_events_c.h"
    1.44 +#include "SDL_ph_video.h"
    1.45 +#include "SDL_ph_modes_c.h"
    1.46 +#include "SDL_ph_image_c.h"
    1.47 +#include "SDL_ph_events_c.h"
    1.48 +
    1.49 +
    1.50 +/* The translation tables from a photon keysym to a SDL keysym */
    1.51 +static SDLKey ODD_keymap[256];
    1.52 +static SDLKey MISC_keymap[0xFF + 1];
    1.53 +SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
    1.54 +
    1.55 +/* Check to see if this is a repeated key.
    1.56 +   (idea shamelessly lifted from GII -- thanks guys! :)
    1.57 + */
    1.58 +
    1.59 +static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
    1.60 +{
    1.61 +	PhEvent_t* peekevent;
    1.62 +	PhKeyEvent_t* keyEvent;
    1.63 +	int repeated;
    1.64 +
    1.65 +	repeated = 0;
    1.66 +	switch (PhEventPeek( peekevent, EVENT_SIZE ))
    1.67 +	{
    1.68 +		case Ph_EVENT_MSG: {
    1.69 +			if(peekevent->type == Ph_EV_KEY)
    1.70 +			{
    1.71 +				keyEvent = PhGetData( peekevent );
    1.72 +				if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
    1.73 +					(keyEvent->key_cap == keyevent->key_cap) &&
    1.74 +					(peekevent->timestamp == event->timestamp)	
    1.75 +				) {
    1.76 +					repeated = 1;
    1.77 +					 //PhEventNext( peekevent, EVENT_SIZE );  
    1.78 +				}				
    1.79 +			}
    1.80 +		}
    1.81 +		break;
    1.82 +
    1.83 +		case -1: {
    1.84 +			perror( "PhEventPeek failed" );
    1.85 +		}
    1.86 +		break;
    1.87 +
    1.88 +		default: /* no events pending */
    1.89 +	}
    1.90 +	return(repeated);
    1.91 +}
    1.92 +
    1.93 +/* Note:  The X server buffers and accumulates mouse motion events, so
    1.94 +   the motion event generated by the warp may not appear exactly as we
    1.95 +   expect it to.  We work around this (and improve performance) by only
    1.96 +   warping the pointer when it reaches the edge, and then wait for it.
    1.97 +*/
    1.98 +/*
    1.99 +#define MOUSE_FUDGE_FACTOR	8
   1.100 +
   1.101 +static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
   1.102 +{
   1.103 +	int w, h, i;
   1.104 +	int deltax, deltay;
   1.105 +	int posted;
   1.106 +
   1.107 +	w = SDL_VideoSurface->w;
   1.108 +	h = SDL_VideoSurface->h;
   1.109 +	deltax = xevent->xmotion.x - mouse_last.x;
   1.110 +	deltay = xevent->xmotion.y - mouse_last.y;
   1.111 +#ifdef DEBUG_MOTION
   1.112 +  printf("Warped mouse motion: %d,%d\n", deltax, deltay);
   1.113 +#endif
   1.114 +	mouse_last.x = xevent->xmotion.x;
   1.115 +	mouse_last.y = xevent->xmotion.y;
   1.116 +	posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
   1.117 +
   1.118 +	if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
   1.119 +	     (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
   1.120 +	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
   1.121 +	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
   1.122 +		/* Get the events that have accumulated */
   1.123 +/*		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
   1.124 +			deltax = xevent->xmotion.x - mouse_last.x;
   1.125 +			deltay = xevent->xmotion.y - mouse_last.y;
   1.126 +#ifdef DEBUG_MOTION
   1.127 +  printf("Extra mouse motion: %d,%d\n", deltax, deltay);
   1.128 +#endif
   1.129 +			mouse_last.x = xevent->xmotion.x;
   1.130 +			mouse_last.y = xevent->xmotion.y;
   1.131 +			posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
   1.132 +		}
   1.133 +		mouse_last.x = w/2;
   1.134 +		mouse_last.y = h/2;
   1.135 +		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
   1.136 +					mouse_last.x, mouse_last.y);
   1.137 +		for ( i=0; i<10; ++i ) {
   1.138 +        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
   1.139 +			if ( (xevent->xmotion.x >
   1.140 +			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
   1.141 +			     (xevent->xmotion.x <
   1.142 +			          (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
   1.143 +			     (xevent->xmotion.y >
   1.144 +			          (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
   1.145 +			     (xevent->xmotion.y <
   1.146 +			          (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
   1.147 +				break;
   1.148 +			}
   1.149 +#ifdef DEBUG_XEVENTS
   1.150 +  printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
   1.151 +#endif
   1.152 +		}
   1.153 +#ifdef DEBUG_XEVENTS
   1.154 +		if ( i == 10 ) {
   1.155 +			printf("Warning: didn't detect mouse warp motion\n");
   1.156 +		}
   1.157 +#endif
   1.158 +	}
   1.159 +	return(posted);
   1.160 +}
   1.161 +*/
   1.162 +
   1.163 +static int ph_DispatchEvent(_THIS)
   1.164 +{
   1.165 +	int posted;
   1.166 +	PhRect_t* rect;
   1.167 +	PhPointerEvent_t* pointerEvent;
   1.168 +	PhKeyEvent_t* keyEvent;
   1.169 +	PhWindowEvent_t* winEvent;
   1.170 +	int i;
   1.171 +	SDL_Rect sdlrects[50]; 
   1.172 +	
   1.173 +	posted = 0;
   1.174 +	
   1.175 +	switch (event->type) {
   1.176 +		case Ph_EV_BOUNDARY:
   1.177 +		{
   1.178 +		
   1.179 +			if (event->subtype == Ph_EV_PTR_ENTER)
   1.180 +				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   1.181 +			else if (event->subtype ==Ph_EV_PTR_LEAVE)
   1.182 +				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
   1.183 +		}
   1.184 +		break;
   1.185 +
   1.186 +		case Ph_EV_PTR_MOTION_BUTTON:
   1.187 +		case Ph_EV_PTR_MOTION_NOBUTTON:
   1.188 +		{
   1.189 +		
   1.190 +			if ( SDL_VideoSurface ) {
   1.191 +				pointerEvent = PhGetData( event );
   1.192 +				rect = PhGetRects( event );
   1.193 +				posted = SDL_PrivateMouseMotion(0, 1,
   1.194 +                		pointerEvent->pos.x - rect[0].ul.x,
   1.195 +                		pointerEvent->pos.y - rect[0].ul.y);		
   1.196 +			}
   1.197 +		}
   1.198 +		break;
   1.199 +
   1.200 +		case Ph_EV_BUT_PRESS:
   1.201 +		{
   1.202 +
   1.203 +			pointerEvent = PhGetData( event );
   1.204 +			/* TODO: is 'buttons' the right mapping? */
   1.205 +			posted = SDL_PrivateMouseButton(SDL_PRESSED,
   1.206 +                        	pointerEvent->buttons, 0, 0);
   1.207 +		}
   1.208 +		break;
   1.209 +
   1.210 +		case Ph_EV_BUT_RELEASE:
   1.211 +		{
   1.212 +			
   1.213 +			pointerEvent = PhGetData( event );
   1.214 +			 posted = SDL_PrivateMouseButton(SDL_RELEASED,
   1.215 +         			pointerEvent->buttons, 0, 0);
   1.216 +		}
   1.217 +		break;
   1.218 +
   1.219 +		case Ph_EV_WM:
   1.220 +		{
   1.221 +
   1.222 +		
   1.223 +			winEvent = PhGetData( event );
   1.224 +			
   1.225 +			/* losing focus */
   1.226 +			if ((winEvent->event_f==Ph_WM_FOCUS)&&
   1.227 +				(winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
   1.228 +			{
   1.229 +				posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   1.230 +
   1.231 +				/* Queue leaving fullscreen mode */
   1.232 +				switch_waiting = 0x01;
   1.233 +				switch_time = SDL_GetTicks() + 200;
   1.234 +			}
   1.235 +
   1.236 +			/* gaining focus */
   1.237 +			else if ((winEvent->event_f==Ph_WM_FOCUS)&&
   1.238 +					(winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   1.239 +			{
   1.240 +				posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.241 +
   1.242 +				/* Queue entry into fullscreen mode */
   1.243 +				switch_waiting = 0x01 | SDL_FULLSCREEN;
   1.244 +				switch_time = SDL_GetTicks() + 1500;
   1.245 +			}
   1.246 +
   1.247 +			/* request to quit */
   1.248 +			else if (winEvent->event_f==Ph_WM_CLOSE)
   1.249 +			{
   1.250 +				posted = SDL_PrivateQuit();
   1.251 +			}
   1.252 +		}
   1.253 +		break;
   1.254 +		
   1.255 +		/* window has been resized, moved or removed */
   1.256 +		case Ph_EV_EXPOSE:
   1.257 +		{
   1.258 +
   1.259 +			if (SDL_VideoSurface)
   1.260 +			{
   1.261 +			  
   1.262 +			  
   1.263 +					rect = PhGetRects( event );
   1.264 +
   1.265 +				//PgSetClipping(1, rect );
   1.266 +				 for(i=0;i<event->num_rects;i++)
   1.267 +			   {
   1.268 +			      sdlrects[i].x = rect[i].ul.x;
   1.269 +			      sdlrects[i].y = rect[i].ul.y;
   1.270 +			      sdlrects[i].w = rect[i].lr.x - rect[i].ul.x;
   1.271 +			      sdlrects[i].h = rect[i].lr.y - rect[i].ul.y;
   1.272 +			      	
   1.273 +				}
   1.274 +			
   1.275 +					this->UpdateRects(this, event->num_rects, sdlrects);
   1.276 +
   1.277 +			}
   1.278 +		}
   1.279 +		break;
   1.280 +
   1.281 +		case Ph_EV_KEY:
   1.282 +		{
   1.283 +	
   1.284 +			SDL_keysym keysym;
   1.285 +			
   1.286 +			posted = 0;
   1.287 +			
   1.288 +			keyEvent = PhGetData( event );
   1.289 +
   1.290 +			if (Pk_KF_Key_Down & keyEvent->key_flags)
   1.291 +			{
   1.292 +				
   1.293 +				posted = SDL_PrivateKeyboard(SDL_PRESSED,
   1.294 +                			ph_TranslateKey( keyEvent, &keysym));
   1.295 +			}
   1.296 +			else /* must be key release */
   1.297 + 			{
   1.298 + 				/* Ignore repeated key release events */
   1.299 +				/*if (! Pk_KF_Key_Repeat & keyEvent->key_flags )*/
   1.300 +				
   1.301 +					posted = SDL_PrivateKeyboard(SDL_RELEASED,
   1.302 +        					ph_TranslateKey( keyEvent, &keysym));
   1.303 +				/*}*/
   1.304 +			}
   1.305 +		}
   1.306 +		break;
   1.307 +	}
   1.308 +	
   1.309 +		
   1.310 +	
   1.311 +	return(posted);
   1.312 +}
   1.313 +
   1.314 +/* perform a blocking read if no events available */
   1.315 +int ph_Pending(_THIS)
   1.316 +{
   1.317 +	
   1.318 +	/* Flush the display connection and look to see if events are queued */
   1.319 +
   1.320 +	PgFlush();
   1.321 +
   1.322 +     while( 1 )
   1.323 +      {   //note this is a non-blocking call
   1.324 +          switch( PhEventPeek( event, EVENT_SIZE ) )
   1.325 +           {
   1.326 +              case Ph_EVENT_MSG:
   1.327 +                 
   1.328 +                 return 1;
   1.329 +                 break;
   1.330 +              case -1:
   1.331 +                 perror( "PhEventNext failed" );
   1.332 +                 break;
   1.333 +              default:
   1.334 +             	  
   1.335 +                return 0;
   1.336 +       }
   1.337 +   }
   1.338 +
   1.339 +	/* Oh well, nothing is ready .. */
   1.340 +	return(0);
   1.341 +}
   1.342 +
   1.343 +/*
   1.344 +SAMPLE EVENT PUMP
   1.345 +=================
   1.346 +static void update( int block ){
   1.347 +
   1.348 +    int ch,fl;
   1.349 +    PhKeyEvent_t *key;
   1.350 +
   1.351 +    for( ;; ){
   1.352 +
   1.353 +        if( block ){
   1.354 +            do{
   1.355 +                fl=PhEventNext( event,EVENT_SIZE );
   1.356 +            }while( fl!=Ph_EVENT_MSG );
   1.357 +            block=0;
   1.358 +        }else{
   1.359 +            do{
   1.360 +                fl=PhEventPeek( event,EVENT_SIZE );
   1.361 +                if( !fl ) return;
   1.362 +            }while( fl!=Ph_EVENT_MSG );
   1.363 +        }
   1.364 +
   1.365 +        switch( event->type ){
   1.366 +        case Ph_EV_KEY:
   1.367 +            key=PhGetData( event );
   1.368 +            ch=key->key_cap;    // & 127;
   1.369 +            fl=key->key_flags;
   1.370 +            if( ch<32 || ch>127 ) break;
   1.371 +            if( fl & Pk_KF_Key_Down ){
   1.372 +                if( !(fl & Pk_KF_Key_Repeat) ){
   1.373 +                    if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch;
   1.374 +                    keyMatrix[ch]=1;
   1.375 +                }
   1.376 +            }else{
   1.377 +                keyMatrix[ch]=0;
   1.378 +            }
   1.379 +            break;
   1.380 +        default:
   1.381 +            PtEventHandler( event );
   1.382 +        }
   1.383 +    }
   1.384 +}
   1.385 +*/
   1.386 +
   1.387 +void ph_PumpEvents(_THIS)
   1.388 +{
   1.389 +	int pending;
   1.390 +
   1.391 +	/* Keep processing pending events */
   1.392 +	pending = 0;
   1.393 +	while ( ph_Pending(this) ) {
   1.394 +		ph_DispatchEvent(this);
   1.395 +		++pending;
   1.396 +	}
   1.397 +	if ( switch_waiting ) {
   1.398 +		Uint32 now;
   1.399 +
   1.400 +		now  = SDL_GetTicks();
   1.401 +		if ( pending || !SDL_VideoSurface ) {
   1.402 +			/* Try again later... */
   1.403 +			if ( switch_waiting & SDL_FULLSCREEN ) {
   1.404 +				switch_time = now + 1500;
   1.405 +			} else {
   1.406 +				switch_time = now + 200;
   1.407 +			}
   1.408 +		} else if ( now >= switch_time ) {
   1.409 +			Uint32 go_fullscreen;
   1.410 +
   1.411 +			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
   1.412 +			switch_waiting = 0;
   1.413 +			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
   1.414 +				if ( go_fullscreen ) {
   1.415 +					ph_EnterFullScreen(this);
   1.416 +				} else {
   1.417 +					ph_LeaveFullScreen(this);
   1.418 +				}
   1.419 +			}
   1.420 +			/* Handle focus in/out when grabbed */
   1.421 +/*
   1.422 +			if ( go_fullscreen ) {
   1.423 +				ph_GrabInputNoLock(this, this->input_grab);
   1.424 +			} else {
   1.425 +				ph_GrabInputNoLock(this, SDL_GRAB_OFF);
   1.426 +			}
   1.427 +*/
   1.428 +		}
   1.429 +	}
   1.430 +}
   1.431 +
   1.432 +void ph_InitKeymap(void)
   1.433 +{
   1.434 +	int i;
   1.435 +
   1.436 +	/* Odd keys used in international keyboards */
   1.437 +	for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
   1.438 +		ODD_keymap[i] = SDLK_UNKNOWN;
   1.439 +
   1.440 +	/* Map the miscellaneous keys */
   1.441 +	for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
   1.442 +		MISC_keymap[i] = SDLK_UNKNOWN;
   1.443 +
   1.444 +	MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   1.445 +	MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   1.446 +	MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
   1.447 +	MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
   1.448 +	MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
   1.449 +	MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
   1.450 +	MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
   1.451 +
   1.452 +	MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
   1.453 +	MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
   1.454 +	MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
   1.455 +	MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
   1.456 +	MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
   1.457 +	MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
   1.458 +	MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
   1.459 +	MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
   1.460 +	MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
   1.461 +	MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
   1.462 +
   1.463 +	MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
   1.464 +	MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
   1.465 +	MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
   1.466 +	MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
   1.467 +	MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
   1.468 +	MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
   1.469 +	MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
   1.470 +
   1.471 +	MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
   1.472 +	MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
   1.473 +	MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
   1.474 +	MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
   1.475 +	MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
   1.476 +	MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
   1.477 +	MISC_keymap[Pk_End&0xFF] = SDLK_END;
   1.478 +	MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
   1.479 +	MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
   1.480 +
   1.481 +	MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
   1.482 +	MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
   1.483 +	MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
   1.484 +	MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
   1.485 +	MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
   1.486 +	MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
   1.487 +	MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
   1.488 +	MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
   1.489 +	MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
   1.490 +	MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
   1.491 +	MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
   1.492 +	MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
   1.493 +	MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
   1.494 +	MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
   1.495 +	MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
   1.496 +
   1.497 +	MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
   1.498 +	MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
   1.499 +	MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
   1.500 +	MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
   1.501 +	MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
   1.502 +	MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
   1.503 +	MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
   1.504 +	MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
   1.505 +	MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   1.506 +	MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   1.507 +	MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   1.508 +	MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
   1.509 +	MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
   1.510 +	MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
   1.511 +
   1.512 +	MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   1.513 +	MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   1.514 +//	MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
   1.515 +	MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   1.516 +	MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   1.517 +	MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   1.518 +}
   1.519 +
   1.520 +static unsigned long cap;
   1.521 +
   1.522 +SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
   1.523 +{
   1.524 +/*	
   1.525 +	'sym' is set to the value of the key with modifiers applied to it. 
   1.526 +	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
   1.527 +	We will assume it is valid.
   1.528 +*/
   1.529 +	cap = key->key_cap;
   1.530 +    switch (cap>>8) {
   1.531 +            case 0x00:  /* Latin 1 */
   1.532 +            case 0x01:  /* Latin 2 */
   1.533 +            case 0x02:  /* Latin 3 */
   1.534 +            case 0x03:  /* Latin 4 */
   1.535 +            case 0x04:  /* Katakana */
   1.536 +            case 0x05:  /* Arabic */
   1.537 +            case 0x06:  /* Cyrillic */
   1.538 +            case 0x07:  /* Greek */
   1.539 +            case 0x08:  /* Technical */
   1.540 +            case 0x0A:  /* Publishing */
   1.541 +            case 0x0C:  /* Hebrew */
   1.542 +            case 0x0D:  /* Thai */
   1.543 +                keysym->sym = (SDLKey)(cap&0xFF);
   1.544 +                /* Map capital letter syms to lowercase */
   1.545 +                if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
   1.546 +                    keysym->sym += ('a'-'A');
   1.547 +                break;
   1.548 +//            case 0xFE:
   1.549 +//                keysym->sym = ODD_keymap[sym&0xFF];
   1.550 +//                break;
   1.551 +            case 0xF0:
   1.552 +                keysym->sym = MISC_keymap[cap&0xFF];
   1.553 +                break;
   1.554 +            default:
   1.555 +                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap);
   1.556 +                break;
   1.557 +    }	
   1.558 +	return (keysym);
   1.559 +}
   1.560 +
   1.561 +void ph_InitOSKeymap(_THIS)
   1.562 +{
   1.563 +
   1.564 +	ph_InitKeymap();
   1.565 +}
   1.566 +