src/video/photon/SDL_ph_events.c
author Sam Lantinga <slouken@lokigames.com>
Thu, 26 Apr 2001 16:45:43 +0000
changeset 0 74212992fb08
child 19 8cc4dbfab9ab
permissions -rw-r--r--
Initial revision
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@0
    20
    slouken@devolution.com
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* Handle the event stream, converting photon events into SDL events */
slouken@0
    29
slouken@0
    30
#include <Ph.h>
slouken@0
    31
#include <stdio.h>
slouken@0
    32
#include <setjmp.h>
slouken@0
    33
#include <photon/PkKeyDef.h>
slouken@0
    34
#include <sys/time.h>
slouken@0
    35
slouken@0
    36
#include "SDL.h"
slouken@0
    37
#include "SDL_syswm.h"
slouken@0
    38
#include "SDL_sysevents.h"
slouken@0
    39
#include "SDL_sysvideo.h"
slouken@0
    40
#include "SDL_events_c.h"
slouken@0
    41
#include "SDL_ph_video.h"
slouken@0
    42
#include "SDL_ph_modes_c.h"
slouken@0
    43
#include "SDL_ph_image_c.h"
slouken@0
    44
#include "SDL_ph_events_c.h"
slouken@0
    45
slouken@0
    46
slouken@0
    47
/* The translation tables from a photon keysym to a SDL keysym */
slouken@0
    48
static SDLKey ODD_keymap[256];
slouken@0
    49
static SDLKey MISC_keymap[0xFF + 1];
slouken@0
    50
SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
slouken@0
    51
slouken@0
    52
/* Check to see if this is a repeated key.
slouken@0
    53
   (idea shamelessly lifted from GII -- thanks guys! :)
slouken@0
    54
 */
slouken@0
    55
slouken@0
    56
static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
slouken@0
    57
{
slouken@0
    58
	PhEvent_t* peekevent;
slouken@0
    59
	PhKeyEvent_t* keyEvent;
slouken@0
    60
	int repeated;
slouken@0
    61
slouken@0
    62
	repeated = 0;
slouken@0
    63
	switch (PhEventPeek( peekevent, EVENT_SIZE ))
slouken@0
    64
	{
slouken@0
    65
		case Ph_EVENT_MSG: {
slouken@0
    66
			if(peekevent->type == Ph_EV_KEY)
slouken@0
    67
			{
slouken@0
    68
				keyEvent = PhGetData( peekevent );
slouken@0
    69
				if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
slouken@0
    70
					(keyEvent->key_cap == keyevent->key_cap) &&
slouken@0
    71
					(peekevent->timestamp == event->timestamp)	
slouken@0
    72
				) {
slouken@0
    73
					repeated = 1;
slouken@0
    74
					 //PhEventNext( peekevent, EVENT_SIZE );  
slouken@0
    75
				}				
slouken@0
    76
			}
slouken@0
    77
		}
slouken@0
    78
		break;
slouken@0
    79
slouken@0
    80
		case -1: {
slouken@0
    81
			perror( "PhEventPeek failed" );
slouken@0
    82
		}
slouken@0
    83
		break;
slouken@0
    84
slouken@0
    85
		default: /* no events pending */
slouken@0
    86
	}
slouken@0
    87
	return(repeated);
slouken@0
    88
}
slouken@0
    89
slouken@0
    90
/* Note:  The X server buffers and accumulates mouse motion events, so
slouken@0
    91
   the motion event generated by the warp may not appear exactly as we
slouken@0
    92
   expect it to.  We work around this (and improve performance) by only
slouken@0
    93
   warping the pointer when it reaches the edge, and then wait for it.
slouken@0
    94
*/
slouken@0
    95
/*
slouken@0
    96
#define MOUSE_FUDGE_FACTOR	8
slouken@0
    97
slouken@0
    98
static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
slouken@0
    99
{
slouken@0
   100
	int w, h, i;
slouken@0
   101
	int deltax, deltay;
slouken@0
   102
	int posted;
slouken@0
   103
slouken@0
   104
	w = SDL_VideoSurface->w;
slouken@0
   105
	h = SDL_VideoSurface->h;
slouken@0
   106
	deltax = xevent->xmotion.x - mouse_last.x;
slouken@0
   107
	deltay = xevent->xmotion.y - mouse_last.y;
slouken@0
   108
#ifdef DEBUG_MOTION
slouken@0
   109
  printf("Warped mouse motion: %d,%d\n", deltax, deltay);
slouken@0
   110
#endif
slouken@0
   111
	mouse_last.x = xevent->xmotion.x;
slouken@0
   112
	mouse_last.y = xevent->xmotion.y;
slouken@0
   113
	posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
slouken@0
   114
slouken@0
   115
	if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
slouken@0
   116
	     (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
slouken@0
   117
	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
slouken@0
   118
	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
slouken@0
   119
		/* Get the events that have accumulated */
slouken@0
   120
/*		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
slouken@0
   121
			deltax = xevent->xmotion.x - mouse_last.x;
slouken@0
   122
			deltay = xevent->xmotion.y - mouse_last.y;
slouken@0
   123
#ifdef DEBUG_MOTION
slouken@0
   124
  printf("Extra mouse motion: %d,%d\n", deltax, deltay);
slouken@0
   125
#endif
slouken@0
   126
			mouse_last.x = xevent->xmotion.x;
slouken@0
   127
			mouse_last.y = xevent->xmotion.y;
slouken@0
   128
			posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
slouken@0
   129
		}
slouken@0
   130
		mouse_last.x = w/2;
slouken@0
   131
		mouse_last.y = h/2;
slouken@0
   132
		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
slouken@0
   133
					mouse_last.x, mouse_last.y);
slouken@0
   134
		for ( i=0; i<10; ++i ) {
slouken@0
   135
        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
slouken@0
   136
			if ( (xevent->xmotion.x >
slouken@0
   137
			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
slouken@0
   138
			     (xevent->xmotion.x <
slouken@0
   139
			          (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
slouken@0
   140
			     (xevent->xmotion.y >
slouken@0
   141
			          (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
slouken@0
   142
			     (xevent->xmotion.y <
slouken@0
   143
			          (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
slouken@0
   144
				break;
slouken@0
   145
			}
slouken@0
   146
#ifdef DEBUG_XEVENTS
slouken@0
   147
  printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
slouken@0
   148
#endif
slouken@0
   149
		}
slouken@0
   150
#ifdef DEBUG_XEVENTS
slouken@0
   151
		if ( i == 10 ) {
slouken@0
   152
			printf("Warning: didn't detect mouse warp motion\n");
slouken@0
   153
		}
slouken@0
   154
#endif
slouken@0
   155
	}
slouken@0
   156
	return(posted);
slouken@0
   157
}
slouken@0
   158
*/
slouken@0
   159
slouken@0
   160
static int ph_DispatchEvent(_THIS)
slouken@0
   161
{
slouken@0
   162
	int posted;
slouken@0
   163
	PhRect_t* rect;
slouken@0
   164
	PhPointerEvent_t* pointerEvent;
slouken@0
   165
	PhKeyEvent_t* keyEvent;
slouken@0
   166
	PhWindowEvent_t* winEvent;
slouken@0
   167
	int i;
slouken@0
   168
	SDL_Rect sdlrects[50]; 
slouken@0
   169
	
slouken@0
   170
	posted = 0;
slouken@0
   171
	
slouken@0
   172
	switch (event->type) {
slouken@0
   173
		case Ph_EV_BOUNDARY:
slouken@0
   174
		{
slouken@0
   175
		
slouken@0
   176
			if (event->subtype == Ph_EV_PTR_ENTER)
slouken@0
   177
				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@0
   178
			else if (event->subtype ==Ph_EV_PTR_LEAVE)
slouken@0
   179
				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
slouken@0
   180
		}
slouken@0
   181
		break;
slouken@0
   182
slouken@0
   183
		case Ph_EV_PTR_MOTION_BUTTON:
slouken@0
   184
		case Ph_EV_PTR_MOTION_NOBUTTON:
slouken@0
   185
		{
slouken@0
   186
		
slouken@0
   187
			if ( SDL_VideoSurface ) {
slouken@0
   188
				pointerEvent = PhGetData( event );
slouken@0
   189
				rect = PhGetRects( event );
slouken@0
   190
				posted = SDL_PrivateMouseMotion(0, 1,
slouken@0
   191
                		pointerEvent->pos.x - rect[0].ul.x,
slouken@0
   192
                		pointerEvent->pos.y - rect[0].ul.y);		
slouken@0
   193
			}
slouken@0
   194
		}
slouken@0
   195
		break;
slouken@0
   196
slouken@0
   197
		case Ph_EV_BUT_PRESS:
slouken@0
   198
		{
slouken@0
   199
slouken@0
   200
			pointerEvent = PhGetData( event );
slouken@0
   201
			/* TODO: is 'buttons' the right mapping? */
slouken@0
   202
			posted = SDL_PrivateMouseButton(SDL_PRESSED,
slouken@0
   203
                        	pointerEvent->buttons, 0, 0);
slouken@0
   204
		}
slouken@0
   205
		break;
slouken@0
   206
slouken@0
   207
		case Ph_EV_BUT_RELEASE:
slouken@0
   208
		{
slouken@0
   209
			
slouken@0
   210
			pointerEvent = PhGetData( event );
slouken@0
   211
			 posted = SDL_PrivateMouseButton(SDL_RELEASED,
slouken@0
   212
         			pointerEvent->buttons, 0, 0);
slouken@0
   213
		}
slouken@0
   214
		break;
slouken@0
   215
slouken@0
   216
		case Ph_EV_WM:
slouken@0
   217
		{
slouken@0
   218
slouken@0
   219
		
slouken@0
   220
			winEvent = PhGetData( event );
slouken@0
   221
			
slouken@0
   222
			/* losing focus */
slouken@0
   223
			if ((winEvent->event_f==Ph_WM_FOCUS)&&
slouken@0
   224
				(winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
slouken@0
   225
			{
slouken@0
   226
				posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
slouken@0
   227
slouken@0
   228
				/* Queue leaving fullscreen mode */
slouken@0
   229
				switch_waiting = 0x01;
slouken@0
   230
				switch_time = SDL_GetTicks() + 200;
slouken@0
   231
			}
slouken@0
   232
slouken@0
   233
			/* gaining focus */
slouken@0
   234
			else if ((winEvent->event_f==Ph_WM_FOCUS)&&
slouken@0
   235
					(winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
slouken@0
   236
			{
slouken@0
   237
				posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
slouken@0
   238
slouken@0
   239
				/* Queue entry into fullscreen mode */
slouken@0
   240
				switch_waiting = 0x01 | SDL_FULLSCREEN;
slouken@0
   241
				switch_time = SDL_GetTicks() + 1500;
slouken@0
   242
			}
slouken@0
   243
slouken@0
   244
			/* request to quit */
slouken@0
   245
			else if (winEvent->event_f==Ph_WM_CLOSE)
slouken@0
   246
			{
slouken@0
   247
				posted = SDL_PrivateQuit();
slouken@0
   248
			}
slouken@0
   249
		}
slouken@0
   250
		break;
slouken@0
   251
		
slouken@0
   252
		/* window has been resized, moved or removed */
slouken@0
   253
		case Ph_EV_EXPOSE:
slouken@0
   254
		{
slouken@0
   255
slouken@0
   256
			if (SDL_VideoSurface)
slouken@0
   257
			{
slouken@0
   258
			  
slouken@0
   259
			  
slouken@0
   260
					rect = PhGetRects( event );
slouken@0
   261
slouken@0
   262
				//PgSetClipping(1, rect );
slouken@0
   263
				 for(i=0;i<event->num_rects;i++)
slouken@0
   264
			   {
slouken@0
   265
			      sdlrects[i].x = rect[i].ul.x;
slouken@0
   266
			      sdlrects[i].y = rect[i].ul.y;
slouken@0
   267
			      sdlrects[i].w = rect[i].lr.x - rect[i].ul.x;
slouken@0
   268
			      sdlrects[i].h = rect[i].lr.y - rect[i].ul.y;
slouken@0
   269
			      	
slouken@0
   270
				}
slouken@0
   271
			
slouken@0
   272
					this->UpdateRects(this, event->num_rects, sdlrects);
slouken@0
   273
slouken@0
   274
			}
slouken@0
   275
		}
slouken@0
   276
		break;
slouken@0
   277
slouken@0
   278
		case Ph_EV_KEY:
slouken@0
   279
		{
slouken@0
   280
	
slouken@0
   281
			SDL_keysym keysym;
slouken@0
   282
			
slouken@0
   283
			posted = 0;
slouken@0
   284
			
slouken@0
   285
			keyEvent = PhGetData( event );
slouken@0
   286
slouken@0
   287
			if (Pk_KF_Key_Down & keyEvent->key_flags)
slouken@0
   288
			{
slouken@0
   289
				
slouken@0
   290
				posted = SDL_PrivateKeyboard(SDL_PRESSED,
slouken@0
   291
                			ph_TranslateKey( keyEvent, &keysym));
slouken@0
   292
			}
slouken@0
   293
			else /* must be key release */
slouken@0
   294
 			{
slouken@0
   295
 				/* Ignore repeated key release events */
slouken@0
   296
				/*if (! Pk_KF_Key_Repeat & keyEvent->key_flags )*/
slouken@0
   297
				
slouken@0
   298
					posted = SDL_PrivateKeyboard(SDL_RELEASED,
slouken@0
   299
        					ph_TranslateKey( keyEvent, &keysym));
slouken@0
   300
				/*}*/
slouken@0
   301
			}
slouken@0
   302
		}
slouken@0
   303
		break;
slouken@0
   304
	}
slouken@0
   305
	
slouken@0
   306
		
slouken@0
   307
	
slouken@0
   308
	return(posted);
slouken@0
   309
}
slouken@0
   310
slouken@0
   311
/* perform a blocking read if no events available */
slouken@0
   312
int ph_Pending(_THIS)
slouken@0
   313
{
slouken@0
   314
	
slouken@0
   315
	/* Flush the display connection and look to see if events are queued */
slouken@0
   316
slouken@0
   317
	PgFlush();
slouken@0
   318
slouken@0
   319
     while( 1 )
slouken@0
   320
      {   //note this is a non-blocking call
slouken@0
   321
          switch( PhEventPeek( event, EVENT_SIZE ) )
slouken@0
   322
           {
slouken@0
   323
              case Ph_EVENT_MSG:
slouken@0
   324
                 
slouken@0
   325
                 return 1;
slouken@0
   326
                 break;
slouken@0
   327
              case -1:
slouken@0
   328
                 perror( "PhEventNext failed" );
slouken@0
   329
                 break;
slouken@0
   330
              default:
slouken@0
   331
             	  
slouken@0
   332
                return 0;
slouken@0
   333
       }
slouken@0
   334
   }
slouken@0
   335
slouken@0
   336
	/* Oh well, nothing is ready .. */
slouken@0
   337
	return(0);
slouken@0
   338
}
slouken@0
   339
slouken@0
   340
/*
slouken@0
   341
SAMPLE EVENT PUMP
slouken@0
   342
=================
slouken@0
   343
static void update( int block ){
slouken@0
   344
slouken@0
   345
    int ch,fl;
slouken@0
   346
    PhKeyEvent_t *key;
slouken@0
   347
slouken@0
   348
    for( ;; ){
slouken@0
   349
slouken@0
   350
        if( block ){
slouken@0
   351
            do{
slouken@0
   352
                fl=PhEventNext( event,EVENT_SIZE );
slouken@0
   353
            }while( fl!=Ph_EVENT_MSG );
slouken@0
   354
            block=0;
slouken@0
   355
        }else{
slouken@0
   356
            do{
slouken@0
   357
                fl=PhEventPeek( event,EVENT_SIZE );
slouken@0
   358
                if( !fl ) return;
slouken@0
   359
            }while( fl!=Ph_EVENT_MSG );
slouken@0
   360
        }
slouken@0
   361
slouken@0
   362
        switch( event->type ){
slouken@0
   363
        case Ph_EV_KEY:
slouken@0
   364
            key=PhGetData( event );
slouken@0
   365
            ch=key->key_cap;    // & 127;
slouken@0
   366
            fl=key->key_flags;
slouken@0
   367
            if( ch<32 || ch>127 ) break;
slouken@0
   368
            if( fl & Pk_KF_Key_Down ){
slouken@0
   369
                if( !(fl & Pk_KF_Key_Repeat) ){
slouken@0
   370
                    if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch;
slouken@0
   371
                    keyMatrix[ch]=1;
slouken@0
   372
                }
slouken@0
   373
            }else{
slouken@0
   374
                keyMatrix[ch]=0;
slouken@0
   375
            }
slouken@0
   376
            break;
slouken@0
   377
        default:
slouken@0
   378
            PtEventHandler( event );
slouken@0
   379
        }
slouken@0
   380
    }
slouken@0
   381
}
slouken@0
   382
*/
slouken@0
   383
slouken@0
   384
void ph_PumpEvents(_THIS)
slouken@0
   385
{
slouken@0
   386
	int pending;
slouken@0
   387
slouken@0
   388
	/* Keep processing pending events */
slouken@0
   389
	pending = 0;
slouken@0
   390
	while ( ph_Pending(this) ) {
slouken@0
   391
		ph_DispatchEvent(this);
slouken@0
   392
		++pending;
slouken@0
   393
	}
slouken@0
   394
	if ( switch_waiting ) {
slouken@0
   395
		Uint32 now;
slouken@0
   396
slouken@0
   397
		now  = SDL_GetTicks();
slouken@0
   398
		if ( pending || !SDL_VideoSurface ) {
slouken@0
   399
			/* Try again later... */
slouken@0
   400
			if ( switch_waiting & SDL_FULLSCREEN ) {
slouken@0
   401
				switch_time = now + 1500;
slouken@0
   402
			} else {
slouken@0
   403
				switch_time = now + 200;
slouken@0
   404
			}
slouken@0
   405
		} else if ( now >= switch_time ) {
slouken@0
   406
			Uint32 go_fullscreen;
slouken@0
   407
slouken@0
   408
			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
slouken@0
   409
			switch_waiting = 0;
slouken@0
   410
			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
slouken@0
   411
				if ( go_fullscreen ) {
slouken@0
   412
					ph_EnterFullScreen(this);
slouken@0
   413
				} else {
slouken@0
   414
					ph_LeaveFullScreen(this);
slouken@0
   415
				}
slouken@0
   416
			}
slouken@0
   417
			/* Handle focus in/out when grabbed */
slouken@0
   418
/*
slouken@0
   419
			if ( go_fullscreen ) {
slouken@0
   420
				ph_GrabInputNoLock(this, this->input_grab);
slouken@0
   421
			} else {
slouken@0
   422
				ph_GrabInputNoLock(this, SDL_GRAB_OFF);
slouken@0
   423
			}
slouken@0
   424
*/
slouken@0
   425
		}
slouken@0
   426
	}
slouken@0
   427
}
slouken@0
   428
slouken@0
   429
void ph_InitKeymap(void)
slouken@0
   430
{
slouken@0
   431
	int i;
slouken@0
   432
slouken@0
   433
	/* Odd keys used in international keyboards */
slouken@0
   434
	for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
slouken@0
   435
		ODD_keymap[i] = SDLK_UNKNOWN;
slouken@0
   436
slouken@0
   437
	/* Map the miscellaneous keys */
slouken@0
   438
	for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
slouken@0
   439
		MISC_keymap[i] = SDLK_UNKNOWN;
slouken@0
   440
slouken@0
   441
	MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
slouken@0
   442
	MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
slouken@0
   443
	MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
slouken@0
   444
	MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
slouken@0
   445
	MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
slouken@0
   446
	MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
slouken@0
   447
	MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
slouken@0
   448
slouken@0
   449
	MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
slouken@0
   450
	MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
slouken@0
   451
	MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
slouken@0
   452
	MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
slouken@0
   453
	MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
slouken@0
   454
	MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
slouken@0
   455
	MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
slouken@0
   456
	MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
slouken@0
   457
	MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
slouken@0
   458
	MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
slouken@0
   459
slouken@0
   460
	MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
slouken@0
   461
	MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
slouken@0
   462
	MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
slouken@0
   463
	MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
slouken@0
   464
	MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
slouken@0
   465
	MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
slouken@0
   466
	MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
slouken@0
   467
slouken@0
   468
	MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
slouken@0
   469
	MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
slouken@0
   470
	MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
slouken@0
   471
	MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
slouken@0
   472
	MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
slouken@0
   473
	MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
slouken@0
   474
	MISC_keymap[Pk_End&0xFF] = SDLK_END;
slouken@0
   475
	MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
slouken@0
   476
	MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
slouken@0
   477
slouken@0
   478
	MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
slouken@0
   479
	MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
slouken@0
   480
	MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
slouken@0
   481
	MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
slouken@0
   482
	MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
slouken@0
   483
	MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
slouken@0
   484
	MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
slouken@0
   485
	MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
slouken@0
   486
	MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
slouken@0
   487
	MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
slouken@0
   488
	MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
slouken@0
   489
	MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
slouken@0
   490
	MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
slouken@0
   491
	MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
slouken@0
   492
	MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
slouken@0
   493
slouken@0
   494
	MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
slouken@0
   495
	MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
slouken@0
   496
	MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
slouken@0
   497
	MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
slouken@0
   498
	MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
slouken@0
   499
	MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
slouken@0
   500
	MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
slouken@0
   501
	MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
slouken@0
   502
	MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
slouken@0
   503
	MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
slouken@0
   504
	MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
slouken@0
   505
	MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
slouken@0
   506
	MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
slouken@0
   507
	MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
slouken@0
   508
slouken@0
   509
	MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
slouken@0
   510
	MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
slouken@0
   511
//	MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
slouken@0
   512
	MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
slouken@0
   513
	MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
slouken@0
   514
	MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
slouken@0
   515
}
slouken@0
   516
slouken@0
   517
static unsigned long cap;
slouken@0
   518
slouken@0
   519
SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
slouken@0
   520
{
slouken@0
   521
/*	
slouken@0
   522
	'sym' is set to the value of the key with modifiers applied to it. 
slouken@0
   523
	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
slouken@0
   524
	We will assume it is valid.
slouken@0
   525
*/
slouken@0
   526
	cap = key->key_cap;
slouken@0
   527
    switch (cap>>8) {
slouken@0
   528
            case 0x00:  /* Latin 1 */
slouken@0
   529
            case 0x01:  /* Latin 2 */
slouken@0
   530
            case 0x02:  /* Latin 3 */
slouken@0
   531
            case 0x03:  /* Latin 4 */
slouken@0
   532
            case 0x04:  /* Katakana */
slouken@0
   533
            case 0x05:  /* Arabic */
slouken@0
   534
            case 0x06:  /* Cyrillic */
slouken@0
   535
            case 0x07:  /* Greek */
slouken@0
   536
            case 0x08:  /* Technical */
slouken@0
   537
            case 0x0A:  /* Publishing */
slouken@0
   538
            case 0x0C:  /* Hebrew */
slouken@0
   539
            case 0x0D:  /* Thai */
slouken@0
   540
                keysym->sym = (SDLKey)(cap&0xFF);
slouken@0
   541
                /* Map capital letter syms to lowercase */
slouken@0
   542
                if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
slouken@0
   543
                    keysym->sym += ('a'-'A');
slouken@0
   544
                break;
slouken@0
   545
//            case 0xFE:
slouken@0
   546
//                keysym->sym = ODD_keymap[sym&0xFF];
slouken@0
   547
//                break;
slouken@0
   548
            case 0xF0:
slouken@0
   549
                keysym->sym = MISC_keymap[cap&0xFF];
slouken@0
   550
                break;
slouken@0
   551
            default:
slouken@0
   552
                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap);
slouken@0
   553
                break;
slouken@0
   554
    }	
slouken@0
   555
	return (keysym);
slouken@0
   556
}
slouken@0
   557
slouken@0
   558
void ph_InitOSKeymap(_THIS)
slouken@0
   559
{
slouken@0
   560
slouken@0
   561
	ph_InitKeymap();
slouken@0
   562
}
slouken@0
   563