src/video/photon/SDL_ph_events.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 28 Mar 2002 16:20:10 +0000
changeset 320 66f815c147ed
parent 297 f6ffac90895c
child 571 8e3ce997621c
permissions -rw-r--r--
Date: Thu, 28 Mar 2002 09:20:03 +0200
From: "Mike Gorchak" <mike@malva.ua>
Subject: New QNX patch.

Hi !

1. Removed warning (possible bug) with invalid type, passing to the function
in ph_WarpedMotion.
2. Rewritten handler of Ph_WM_RESIZE message, now works, but buggy (old
handler doesn't work at all).
3. Added stub handler for Ph_WM_MAX (maximize) message.
4. Added more #ifdef HAVE_OPENGL to disable OpenGL stuff when it not needed.
5. Added support for SDL_NOFRAME and SDL_RESIZABLE flags (in OpenGL windows
too).
6. Added cosmetic changes, if no SDL_RESIZABLE flag defined, disable resize
handlers in window border and maximize button at caption.
7. Fixed my bug with invalid arguments count passed to PtCreateWidget call.
8. Fixed some palette problems.
9. Updated README.QNX file.

And I changed testgl.c test application:

10. Added in testgl.c application support for SDL_NOFRAME flag and
option -noframe.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  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@252
    20
    slouken@libsdl.org
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@19
    30
#define DISABLE_X11
slouken@19
    31
slouken@0
    32
#include <Ph.h>
slouken@0
    33
#include <stdio.h>
slouken@0
    34
#include <setjmp.h>
slouken@0
    35
#include <photon/PkKeyDef.h>
slouken@0
    36
#include <sys/time.h>
slouken@0
    37
slouken@0
    38
#include "SDL.h"
slouken@0
    39
#include "SDL_syswm.h"
slouken@0
    40
#include "SDL_sysevents.h"
slouken@0
    41
#include "SDL_sysvideo.h"
slouken@0
    42
#include "SDL_events_c.h"
slouken@0
    43
#include "SDL_ph_video.h"
slouken@0
    44
#include "SDL_ph_modes_c.h"
slouken@0
    45
#include "SDL_ph_image_c.h"
slouken@0
    46
#include "SDL_ph_events_c.h"
slouken@0
    47
slouken@0
    48
slouken@0
    49
/* The translation tables from a photon keysym to a SDL keysym */
slouken@0
    50
static SDLKey ODD_keymap[256];
slouken@0
    51
static SDLKey MISC_keymap[0xFF + 1];
slouken@0
    52
SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
slouken@0
    53
slouken@0
    54
/* Check to see if this is a repeated key.
slouken@0
    55
   (idea shamelessly lifted from GII -- thanks guys! :)
slouken@0
    56
 */
slouken@0
    57
slouken@283
    58
#if 0
slouken@0
    59
static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
slouken@0
    60
{
slouken@266
    61
//	PhEvent_t* peekevent;
slouken@0
    62
	PhKeyEvent_t* keyEvent;
slouken@0
    63
	int repeated;
slouken@0
    64
slouken@0
    65
	repeated = 0;
slouken@0
    66
	switch (PhEventPeek( peekevent, EVENT_SIZE ))
slouken@0
    67
	{
slouken@0
    68
		case Ph_EVENT_MSG: {
slouken@0
    69
			if(peekevent->type == Ph_EV_KEY)
slouken@0
    70
			{
slouken@0
    71
				keyEvent = PhGetData( peekevent );
slouken@0
    72
				if ( !(Pk_KF_Key_Down & keyEvent->key_flags) &&
slouken@0
    73
					(keyEvent->key_cap == keyevent->key_cap) &&
slouken@0
    74
					(peekevent->timestamp == event->timestamp)	
slouken@0
    75
				) {
slouken@0
    76
					repeated = 1;
slouken@320
    77
					 /* PhEventNext( peekevent, EVENT_SIZE ); */
slouken@0
    78
				}				
slouken@0
    79
			}
slouken@0
    80
		}
slouken@0
    81
		break;
slouken@0
    82
slouken@0
    83
		case -1: {
slouken@0
    84
			perror( "PhEventPeek failed" );
slouken@0
    85
		}
slouken@0
    86
		break;
slouken@0
    87
slouken@320
    88
		default: /* no events pending */
slouken@0
    89
	}
slouken@0
    90
	return(repeated);
slouken@0
    91
}
slouken@283
    92
#endif
slouken@0
    93
slouken@283
    94
static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
slouken@283
    95
{
slouken@320
    96
/*	PhPointerEvent_t *pointer = PhGetData( winEvent ); */
slouken@283
    97
	PhRect_t *rect = PhGetRects( winEvent );
slouken@266
    98
slouken@283
    99
	int centre_x, centre_y;
slouken@320
   100
	int dx, dy;
slouken@320
   101
        short abs_x, abs_y;
slouken@0
   102
	int posted;
slouken@0
   103
slouken@283
   104
	centre_x = SDL_VideoSurface->w / 2;
slouken@283
   105
	centre_y = SDL_VideoSurface->h / 2;
slouken@0
   106
slouken@283
   107
	dx = rect->ul.x - centre_x;
slouken@283
   108
	dy = rect->ul.y - centre_y;
slouken@283
   109
slouken@283
   110
	posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
slouken@283
   111
slouken@283
   112
	/* Move mouse cursor to middle of the window */
slouken@283
   113
	PtGetAbsPosition( window, &abs_x, &abs_y );
slouken@283
   114
	PhMoveCursorAbs( PhInputGroup(NULL),
slouken@283
   115
			abs_x + centre_x,
slouken@283
   116
			abs_y + centre_y );
slouken@283
   117
slouken@0
   118
	return(posted);
slouken@0
   119
}
slouken@0
   120
slouken@220
   121
/* Control which motion flags the window has set, a flags value of -1 sets
slouken@220
   122
 * MOTION_BUTTON and MOTION_NOBUTTON */
slouken@266
   123
slouken@220
   124
static void set_motion_sensitivity(_THIS, unsigned int flags)
slouken@220
   125
{
slouken@220
   126
	int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
slouken@220
   127
	PhRegion_t region;
slouken@220
   128
slouken@220
   129
	if( window )
slouken@220
   130
	{
slouken@220
   131
		rid = PtWidgetRid( window );
slouken@220
   132
		if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
slouken@220
   133
		{
slouken@220
   134
			region.events_sense = ( region.events_sense & ~fields ) |
slouken@220
   135
				( flags & fields );
slouken@220
   136
			PhRegionChange( Ph_REGION_EV_SENSE, 0, &region,
slouken@220
   137
					NULL, NULL );
slouken@220
   138
		}
slouken@220
   139
	}
slouken@220
   140
}
slouken@220
   141
slouken@220
   142
/* Convert the photon button state value to an SDL value */
slouken@220
   143
static Uint8 ph2sdl_mousebutton( unsigned short button_state )
slouken@220
   144
{
slouken@220
   145
	Uint8 mouse_button = 0;
slouken@220
   146
slouken@220
   147
	if( button_state & Ph_BUTTON_SELECT )
slouken@220
   148
			mouse_button |= SDL_BUTTON_LEFT;
slouken@220
   149
	if( button_state & Ph_BUTTON_MENU )
slouken@220
   150
			mouse_button |= SDL_BUTTON_RIGHT;
slouken@220
   151
	if( button_state & Ph_BUTTON_ADJUST )
slouken@220
   152
			mouse_button |= SDL_BUTTON_MIDDLE;
slouken@220
   153
slouken@220
   154
	return( mouse_button );
slouken@220
   155
}
slouken@220
   156
slouken@0
   157
static int ph_DispatchEvent(_THIS)
slouken@0
   158
{
slouken@320
   159
    int posted;
slouken@320
   160
    PhRect_t* rect;
slouken@320
   161
    PhPointerEvent_t* pointerEvent;
slouken@320
   162
    PhKeyEvent_t* keyEvent;
slouken@320
   163
    PhWindowEvent_t* winEvent;
slouken@320
   164
    int i, buttons;
slouken@320
   165
    SDL_Rect sdlrects[50]; 
slouken@0
   166
	
slouken@320
   167
    posted = 0;
slouken@0
   168
	
slouken@320
   169
    switch (event->type)
slouken@320
   170
    {
slouken@320
   171
        case Ph_EV_BOUNDARY:
slouken@320
   172
        {
slouken@320
   173
            if (event->subtype == Ph_EV_PTR_ENTER)
slouken@320
   174
            {
slouken@320
   175
                posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@320
   176
            }
slouken@320
   177
            else if (event->subtype ==Ph_EV_PTR_LEAVE)
slouken@320
   178
            {
slouken@320
   179
                posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
slouken@320
   180
            }
slouken@320
   181
        }
slouken@320
   182
        break;
slouken@320
   183
slouken@320
   184
        case Ph_EV_PTR_MOTION_BUTTON:
slouken@320
   185
        case Ph_EV_PTR_MOTION_NOBUTTON:
slouken@320
   186
        {
slouken@320
   187
            if (SDL_VideoSurface)
slouken@320
   188
            {
slouken@320
   189
                pointerEvent = PhGetData(event);
slouken@320
   190
                rect = PhGetRects(event);
slouken@320
   191
slouken@320
   192
                if (mouse_relative)
slouken@320
   193
                {
slouken@320
   194
                    posted = ph_WarpedMotion(this, event);
slouken@320
   195
                }
slouken@320
   196
                else
slouken@320
   197
                {
slouken@320
   198
                    posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
slouken@320
   199
                }
slouken@320
   200
            }
slouken@320
   201
        }
slouken@320
   202
        break;
slouken@320
   203
slouken@320
   204
        case Ph_EV_BUT_PRESS:
slouken@320
   205
        {
slouken@320
   206
            pointerEvent = PhGetData( event );
slouken@320
   207
            buttons = ph2sdl_mousebutton( pointerEvent->buttons );
slouken@320
   208
            if (buttons != 0)
slouken@320
   209
            {
slouken@320
   210
                posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
slouken@320
   211
            }
slouken@320
   212
        }
slouken@320
   213
        break;
slouken@320
   214
slouken@320
   215
        case Ph_EV_BUT_RELEASE:
slouken@320
   216
        {
slouken@320
   217
            pointerEvent = PhGetData(event);
slouken@320
   218
            buttons = ph2sdl_mousebutton(pointerEvent->buttons);
slouken@320
   219
            if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0)
slouken@320
   220
            {
slouken@320
   221
                posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
slouken@320
   222
            }
slouken@320
   223
            else if(event->subtype == Ph_EV_RELEASE_PHANTOM)
slouken@320
   224
            {
slouken@320
   225
                /* If the mouse is outside the window,
slouken@320
   226
                 * only a phantom release event is sent, so
slouken@320
   227
                 * check if the window doesn't have mouse focus.
slouken@320
   228
                 * Not perfect, maybe checking the mouse button
slouken@320
   229
                 * state for Ph_EV_BOUNDARY events would be
slouken@320
   230
                 * better. */
slouken@320
   231
                if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0)
slouken@0
   232
		{
slouken@320
   233
                    posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
slouken@320
   234
                }
slouken@320
   235
            }
slouken@320
   236
        }
slouken@320
   237
        break;
slouken@0
   238
slouken@320
   239
        case Ph_EV_WM:
slouken@320
   240
        {
slouken@320
   241
            winEvent = PhGetData(event);
slouken@0
   242
slouken@320
   243
            /* losing focus */
slouken@320
   244
            if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
slouken@320
   245
            {
slouken@320
   246
                set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
slouken@320
   247
                posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
slouken@0
   248
slouken@320
   249
                /* Queue leaving fullscreen mode */
slouken@320
   250
                switch_waiting = 0x01;
slouken@320
   251
                switch_time = SDL_GetTicks() + 200;
slouken@320
   252
            }
slouken@320
   253
            /* gaining focus */
slouken@320
   254
            else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
slouken@320
   255
            {
slouken@320
   256
                set_motion_sensitivity(this, -1);
slouken@320
   257
                posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
slouken@320
   258
            }
slouken@320
   259
            /* request to quit */
slouken@320
   260
            else if (winEvent->event_f==Ph_WM_CLOSE)
slouken@320
   261
            {
slouken@320
   262
                posted = SDL_PrivateQuit();
slouken@320
   263
            }
slouken@320
   264
            /* request to resize */
slouken@320
   265
            else if (winEvent->event_f==Ph_WM_RESIZE)
slouken@320
   266
            {
slouken@320
   267
                SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
slouken@320
   268
            }
slouken@320
   269
            /* request to maximize */
slouken@320
   270
            else if (winEvent->event_f==Ph_WM_MAX)
slouken@320
   271
            {
slouken@320
   272
                /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */
slouken@320
   273
            }
slouken@320
   274
        }
slouken@320
   275
        break;
slouken@0
   276
slouken@320
   277
        /* window has been resized, moved or removed */
slouken@320
   278
        case Ph_EV_EXPOSE:
slouken@320
   279
        {
slouken@320
   280
            if (SDL_VideoSurface)
slouken@320
   281
            {
slouken@320
   282
                rect = PhGetRects(event);
slouken@0
   283
slouken@320
   284
                for(i=0;i<event->num_rects;i++)
slouken@320
   285
                {
slouken@320
   286
                    sdlrects[i].x = rect[i].ul.x;
slouken@320
   287
                    sdlrects[i].y = rect[i].ul.y;
slouken@320
   288
                    sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
slouken@320
   289
                    sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
slouken@320
   290
                }
slouken@0
   291
slouken@320
   292
                this->UpdateRects(this, event->num_rects, sdlrects);
slouken@320
   293
            }
slouken@320
   294
        }
slouken@320
   295
	break;
slouken@0
   296
slouken@320
   297
        case Ph_EV_KEY:
slouken@320
   298
        {
slouken@320
   299
            SDL_keysym keysym;
slouken@283
   300
slouken@320
   301
            posted = 0;
slouken@0
   302
slouken@320
   303
            keyEvent = PhGetData( event );
slouken@220
   304
slouken@320
   305
            if (Pk_KF_Key_Down & keyEvent->key_flags)
slouken@320
   306
            {
slouken@320
   307
                posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
slouken@320
   308
            }
slouken@320
   309
            else /* must be key release */
slouken@320
   310
            {
slouken@320
   311
                 /* Ignore repeated key release events */
slouken@320
   312
                 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */
slouken@0
   313
slouken@320
   314
                posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
slouken@320
   315
            }
slouken@320
   316
        }
slouken@320
   317
        break;
slouken@320
   318
    }
slouken@0
   319
slouken@320
   320
    return(posted);
slouken@0
   321
}
slouken@0
   322
slouken@0
   323
/* perform a blocking read if no events available */
slouken@0
   324
int ph_Pending(_THIS)
slouken@0
   325
{
slouken@0
   326
	/* Flush the display connection and look to see if events are queued */
slouken@0
   327
	PgFlush();
slouken@0
   328
slouken@0
   329
     while( 1 )
slouken@0
   330
      {   //note this is a non-blocking call
slouken@0
   331
          switch( PhEventPeek( event, EVENT_SIZE ) )
slouken@0
   332
           {
slouken@0
   333
              case Ph_EVENT_MSG:
slouken@0
   334
                 
slouken@0
   335
                 return 1;
slouken@0
   336
                 break;
slouken@0
   337
              case -1:
slouken@0
   338
                 perror( "PhEventNext failed" );
slouken@0
   339
                 break;
slouken@0
   340
              default:
slouken@0
   341
             	  
slouken@0
   342
                return 0;
slouken@0
   343
       }
slouken@0
   344
   }
slouken@0
   345
slouken@0
   346
	/* Oh well, nothing is ready .. */
slouken@0
   347
	return(0);
slouken@0
   348
}
slouken@0
   349
slouken@0
   350
/*
slouken@0
   351
SAMPLE EVENT PUMP
slouken@0
   352
=================
slouken@0
   353
static void update( int block ){
slouken@0
   354
slouken@0
   355
    int ch,fl;
slouken@0
   356
    PhKeyEvent_t *key;
slouken@0
   357
slouken@0
   358
    for( ;; ){
slouken@0
   359
slouken@0
   360
        if( block ){
slouken@0
   361
            do{
slouken@0
   362
                fl=PhEventNext( event,EVENT_SIZE );
slouken@0
   363
            }while( fl!=Ph_EVENT_MSG );
slouken@0
   364
            block=0;
slouken@0
   365
        }else{
slouken@0
   366
            do{
slouken@0
   367
                fl=PhEventPeek( event,EVENT_SIZE );
slouken@0
   368
                if( !fl ) return;
slouken@0
   369
            }while( fl!=Ph_EVENT_MSG );
slouken@0
   370
        }
slouken@0
   371
slouken@0
   372
        switch( event->type ){
slouken@0
   373
        case Ph_EV_KEY:
slouken@0
   374
            key=PhGetData( event );
slouken@0
   375
            ch=key->key_cap;    // & 127;
slouken@0
   376
            fl=key->key_flags;
slouken@0
   377
            if( ch<32 || ch>127 ) break;
slouken@0
   378
            if( fl & Pk_KF_Key_Down ){
slouken@0
   379
                if( !(fl & Pk_KF_Key_Repeat) ){
slouken@0
   380
                    if( queput-queget<QUE_SIZE ) keyque[ queput++ & QUE_MASK ]=ch;
slouken@0
   381
                    keyMatrix[ch]=1;
slouken@0
   382
                }
slouken@0
   383
            }else{
slouken@0
   384
                keyMatrix[ch]=0;
slouken@0
   385
            }
slouken@0
   386
            break;
slouken@0
   387
        default:
slouken@0
   388
            PtEventHandler( event );
slouken@0
   389
        }
slouken@0
   390
    }
slouken@0
   391
}
slouken@0
   392
*/
slouken@0
   393
slouken@0
   394
void ph_PumpEvents(_THIS)
slouken@0
   395
{
slouken@0
   396
	int pending;
slouken@0
   397
slouken@0
   398
	/* Keep processing pending events */
slouken@0
   399
	pending = 0;
slouken@0
   400
	while ( ph_Pending(this) ) {
slouken@0
   401
		ph_DispatchEvent(this);
slouken@0
   402
		++pending;
slouken@0
   403
	}
slouken@0
   404
	if ( switch_waiting ) {
slouken@0
   405
		Uint32 now;
slouken@0
   406
slouken@0
   407
		now  = SDL_GetTicks();
slouken@283
   408
#if 0
slouken@0
   409
		if ( pending || !SDL_VideoSurface ) {
slouken@0
   410
			/* Try again later... */
slouken@0
   411
			if ( switch_waiting & SDL_FULLSCREEN ) {
slouken@0
   412
				switch_time = now + 1500;
slouken@0
   413
			} else {
slouken@0
   414
				switch_time = now + 200;
slouken@0
   415
			}
slouken@0
   416
		} else if ( now >= switch_time ) {
slouken@0
   417
			Uint32 go_fullscreen;
slouken@0
   418
slouken@0
   419
			go_fullscreen = switch_waiting & SDL_FULLSCREEN;
slouken@0
   420
			switch_waiting = 0;
slouken@0
   421
			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
slouken@0
   422
				if ( go_fullscreen ) {
slouken@0
   423
					ph_EnterFullScreen(this);
slouken@0
   424
				} else {
slouken@0
   425
					ph_LeaveFullScreen(this);
slouken@0
   426
				}
slouken@0
   427
			}
slouken@0
   428
			/* Handle focus in/out when grabbed */
slouken@0
   429
/*
slouken@0
   430
			if ( go_fullscreen ) {
slouken@0
   431
				ph_GrabInputNoLock(this, this->input_grab);
slouken@0
   432
			} else {
slouken@0
   433
				ph_GrabInputNoLock(this, SDL_GRAB_OFF);
slouken@0
   434
			}
slouken@0
   435
*/
slouken@0
   436
		}
slouken@283
   437
#endif
slouken@0
   438
	}
slouken@0
   439
}
slouken@0
   440
slouken@0
   441
void ph_InitKeymap(void)
slouken@0
   442
{
slouken@0
   443
	int i;
slouken@0
   444
slouken@0
   445
	/* Odd keys used in international keyboards */
slouken@0
   446
	for ( i=0; i<SDL_TABLESIZE(ODD_keymap); ++i )
slouken@0
   447
		ODD_keymap[i] = SDLK_UNKNOWN;
slouken@0
   448
slouken@0
   449
	/* Map the miscellaneous keys */
slouken@0
   450
	for ( i=0; i<SDL_TABLESIZE(MISC_keymap); ++i )
slouken@0
   451
		MISC_keymap[i] = SDLK_UNKNOWN;
slouken@0
   452
slouken@0
   453
	MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
slouken@0
   454
	MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
slouken@0
   455
	MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
slouken@0
   456
	MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
slouken@0
   457
	MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
slouken@0
   458
	MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
slouken@0
   459
	MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
slouken@0
   460
slouken@0
   461
	MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
slouken@0
   462
	MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
slouken@0
   463
	MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
slouken@0
   464
	MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
slouken@0
   465
	MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
slouken@0
   466
	MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
slouken@0
   467
	MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
slouken@0
   468
	MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
slouken@0
   469
	MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
slouken@0
   470
	MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
slouken@0
   471
slouken@0
   472
	MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
slouken@0
   473
	MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
slouken@0
   474
	MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
slouken@0
   475
	MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
slouken@0
   476
	MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
slouken@0
   477
	MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
slouken@0
   478
	MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
slouken@0
   479
slouken@0
   480
	MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
slouken@0
   481
	MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
slouken@0
   482
	MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
slouken@0
   483
	MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
slouken@0
   484
	MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
slouken@0
   485
	MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
slouken@0
   486
	MISC_keymap[Pk_End&0xFF] = SDLK_END;
slouken@0
   487
	MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
slouken@0
   488
	MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
slouken@0
   489
slouken@0
   490
	MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
slouken@0
   491
	MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
slouken@0
   492
	MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
slouken@0
   493
	MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
slouken@0
   494
	MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
slouken@0
   495
	MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
slouken@0
   496
	MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
slouken@0
   497
	MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
slouken@0
   498
	MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
slouken@0
   499
	MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
slouken@0
   500
	MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
slouken@0
   501
	MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
slouken@0
   502
	MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
slouken@0
   503
	MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
slouken@0
   504
	MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
slouken@0
   505
slouken@0
   506
	MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
slouken@0
   507
	MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
slouken@0
   508
	MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
slouken@0
   509
	MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
slouken@0
   510
	MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
slouken@0
   511
	MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
slouken@0
   512
	MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
slouken@0
   513
	MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
slouken@0
   514
	MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
slouken@0
   515
	MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
slouken@0
   516
	MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
slouken@0
   517
	MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */
slouken@0
   518
	MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows */
slouken@0
   519
	MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
slouken@0
   520
slouken@0
   521
	MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
slouken@0
   522
	MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
slouken@0
   523
//	MISC_keymap[Pk_Sys_Req] = SDLK_SYSREQ;
slouken@0
   524
	MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
slouken@0
   525
	MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
slouken@0
   526
	MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
slouken@0
   527
}
slouken@0
   528
slouken@0
   529
static unsigned long cap;
slouken@0
   530
slouken@0
   531
SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
slouken@0
   532
{
slouken@0
   533
/*	
slouken@0
   534
	'sym' is set to the value of the key with modifiers applied to it. 
slouken@0
   535
	This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
slouken@0
   536
	We will assume it is valid.
slouken@0
   537
*/
slouken@283
   538
	/* FIXME: This needs to check whether the cap & scancode is valid */
slouken@0
   539
	cap = key->key_cap;
slouken@220
   540
	switch (cap>>8) {
slouken@0
   541
            case 0x00:  /* Latin 1 */
slouken@0
   542
            case 0x01:  /* Latin 2 */
slouken@0
   543
            case 0x02:  /* Latin 3 */
slouken@0
   544
            case 0x03:  /* Latin 4 */
slouken@0
   545
            case 0x04:  /* Katakana */
slouken@0
   546
            case 0x05:  /* Arabic */
slouken@0
   547
            case 0x06:  /* Cyrillic */
slouken@0
   548
            case 0x07:  /* Greek */
slouken@0
   549
            case 0x08:  /* Technical */
slouken@0
   550
            case 0x0A:  /* Publishing */
slouken@0
   551
            case 0x0C:  /* Hebrew */
slouken@0
   552
            case 0x0D:  /* Thai */
slouken@0
   553
                keysym->sym = (SDLKey)(cap&0xFF);
slouken@0
   554
                /* Map capital letter syms to lowercase */
slouken@0
   555
                if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
slouken@0
   556
                    keysym->sym += ('a'-'A');
slouken@0
   557
                break;
slouken@0
   558
//            case 0xFE:
slouken@0
   559
//                keysym->sym = ODD_keymap[sym&0xFF];
slouken@0
   560
//                break;
slouken@0
   561
            case 0xF0:
slouken@0
   562
                keysym->sym = MISC_keymap[cap&0xFF];
slouken@0
   563
                break;
slouken@0
   564
            default:
slouken@283
   565
/*                fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
slouken@283
   566
		keysym->sym = SDLK_UNKNOWN;                
slouken@0
   567
                break;
slouken@220
   568
	}
slouken@220
   569
	keysym->scancode = key->key_scan;
slouken@283
   570
	keysym->unicode = 0;
slouken@283
   571
	if( SDL_TranslateUNICODE )
slouken@283
   572
	{
slouken@283
   573
		char utf8[MB_CUR_MAX];
slouken@283
   574
		int utf8len;
slouken@283
   575
		wchar_t unicode;
slouken@283
   576
slouken@283
   577
		utf8len = PhKeyToMb( utf8, key );
slouken@283
   578
		if( utf8len > 0 )
slouken@283
   579
		{
slouken@283
   580
			utf8len = mbtowc( &unicode, utf8, utf8len );
slouken@283
   581
			if( utf8len > 0)
slouken@283
   582
				keysym->unicode = unicode;
slouken@283
   583
		}
slouken@283
   584
	}
slouken@283
   585
slouken@0
   586
	return (keysym);
slouken@0
   587
}
slouken@0
   588
slouken@0
   589
void ph_InitOSKeymap(_THIS)
slouken@0
   590
{
slouken@0
   591
	ph_InitKeymap();
slouken@0
   592
}
slouken@0
   593