src/video/photon/SDL_ph_events.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 20 Jan 2003 01:38:37 +0000
changeset 571 8e3ce997621c
parent 320 66f815c147ed
child 663 8bedd6d61642
permissions -rw-r--r--
Date: Thu, 16 Jan 2003 13:48:31 +0200
From: "Mike Gorchak"
Subject: All QNX patches

whole patches concerning QNX. Almost all code has been rewritten by Julian
and me. Added initial support for hw overlays in QNX and many many others
fixes.

P.S. This patches has been reviewed by Dave Rempel from QSSL and included in
SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1
version of QNX, which will be available soon.
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
static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
slouken@283
    59
{
slouken@571
    60
    PhRect_t *rect = PhGetRects( winEvent );
slouken@266
    61
slouken@571
    62
    int centre_x, centre_y;
slouken@571
    63
    int dx, dy;
slouken@571
    64
    short abs_x, abs_y;
slouken@571
    65
    int posted;
slouken@0
    66
slouken@571
    67
    centre_x = SDL_VideoSurface->w / 2;
slouken@571
    68
    centre_y = SDL_VideoSurface->h / 2;
slouken@0
    69
slouken@571
    70
    dx = rect->ul.x - centre_x;
slouken@571
    71
    dy = rect->ul.y - centre_y;
slouken@283
    72
slouken@571
    73
    posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
slouken@283
    74
slouken@571
    75
    /* Move mouse cursor to middle of the window */
slouken@571
    76
    PtGetAbsPosition( window, &abs_x, &abs_y );
slouken@571
    77
    PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
slouken@283
    78
slouken@571
    79
    return (posted);
slouken@0
    80
}
slouken@0
    81
slouken@220
    82
/* Control which motion flags the window has set, a flags value of -1 sets
slouken@220
    83
 * MOTION_BUTTON and MOTION_NOBUTTON */
slouken@266
    84
slouken@220
    85
static void set_motion_sensitivity(_THIS, unsigned int flags)
slouken@220
    86
{
slouken@571
    87
    int rid;
slouken@571
    88
    int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
slouken@571
    89
    PhRegion_t region;
slouken@220
    90
slouken@571
    91
    if( window )
slouken@571
    92
    {
slouken@571
    93
        rid = PtWidgetRid( window );
slouken@571
    94
        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
slouken@571
    95
        {
slouken@571
    96
            region.events_sense=(region.events_sense & ~fields)|(flags & fields);
slouken@571
    97
            PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
slouken@571
    98
        }
slouken@571
    99
    }
slouken@220
   100
}
slouken@220
   101
slouken@220
   102
/* Convert the photon button state value to an SDL value */
slouken@571
   103
static Uint8 ph2sdl_mousebutton(unsigned short button_state)
slouken@220
   104
{
slouken@571
   105
    Uint8 mouse_button = 0;
slouken@220
   106
slouken@571
   107
    if (button_state & Ph_BUTTON_SELECT)
slouken@571
   108
        mouse_button |= SDL_BUTTON_LEFT;
slouken@571
   109
    if (button_state & Ph_BUTTON_MENU)
slouken@571
   110
        mouse_button |= SDL_BUTTON_RIGHT;
slouken@571
   111
    if (button_state & Ph_BUTTON_ADJUST)
slouken@571
   112
        mouse_button |= SDL_BUTTON_MIDDLE;
slouken@220
   113
slouken@571
   114
    return (mouse_button);
slouken@220
   115
}
slouken@220
   116
slouken@0
   117
static int ph_DispatchEvent(_THIS)
slouken@0
   118
{
slouken@320
   119
    int posted;
slouken@320
   120
    PhRect_t* rect;
slouken@320
   121
    PhPointerEvent_t* pointerEvent;
slouken@320
   122
    PhKeyEvent_t* keyEvent;
slouken@320
   123
    PhWindowEvent_t* winEvent;
slouken@320
   124
    int i, buttons;
slouken@320
   125
    SDL_Rect sdlrects[50]; 
slouken@0
   126
	
slouken@320
   127
    posted = 0;
slouken@0
   128
	
slouken@320
   129
    switch (event->type)
slouken@320
   130
    {
slouken@320
   131
        case Ph_EV_BOUNDARY:
slouken@320
   132
        {
slouken@320
   133
            if (event->subtype == Ph_EV_PTR_ENTER)
slouken@320
   134
            {
slouken@320
   135
                posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@320
   136
            }
slouken@320
   137
            else if (event->subtype ==Ph_EV_PTR_LEAVE)
slouken@320
   138
            {
slouken@320
   139
                posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
slouken@320
   140
            }
slouken@320
   141
        }
slouken@320
   142
        break;
slouken@320
   143
slouken@320
   144
        case Ph_EV_PTR_MOTION_BUTTON:
slouken@320
   145
        case Ph_EV_PTR_MOTION_NOBUTTON:
slouken@320
   146
        {
slouken@320
   147
            if (SDL_VideoSurface)
slouken@320
   148
            {
slouken@320
   149
                pointerEvent = PhGetData(event);
slouken@320
   150
                rect = PhGetRects(event);
slouken@320
   151
slouken@320
   152
                if (mouse_relative)
slouken@320
   153
                {
slouken@320
   154
                    posted = ph_WarpedMotion(this, event);
slouken@320
   155
                }
slouken@320
   156
                else
slouken@320
   157
                {
slouken@320
   158
                    posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
slouken@320
   159
                }
slouken@320
   160
            }
slouken@320
   161
        }
slouken@320
   162
        break;
slouken@320
   163
slouken@320
   164
        case Ph_EV_BUT_PRESS:
slouken@320
   165
        {
slouken@320
   166
            pointerEvent = PhGetData( event );
slouken@320
   167
            buttons = ph2sdl_mousebutton( pointerEvent->buttons );
slouken@320
   168
            if (buttons != 0)
slouken@320
   169
            {
slouken@320
   170
                posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
slouken@320
   171
            }
slouken@320
   172
        }
slouken@320
   173
        break;
slouken@320
   174
slouken@320
   175
        case Ph_EV_BUT_RELEASE:
slouken@320
   176
        {
slouken@320
   177
            pointerEvent = PhGetData(event);
slouken@320
   178
            buttons = ph2sdl_mousebutton(pointerEvent->buttons);
slouken@320
   179
            if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0)
slouken@320
   180
            {
slouken@320
   181
                posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
slouken@320
   182
            }
slouken@320
   183
            else if(event->subtype == Ph_EV_RELEASE_PHANTOM)
slouken@320
   184
            {
slouken@320
   185
                /* If the mouse is outside the window,
slouken@320
   186
                 * only a phantom release event is sent, so
slouken@320
   187
                 * check if the window doesn't have mouse focus.
slouken@320
   188
                 * Not perfect, maybe checking the mouse button
slouken@320
   189
                 * state for Ph_EV_BOUNDARY events would be
slouken@320
   190
                 * better. */
slouken@320
   191
                if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0)
slouken@0
   192
		{
slouken@320
   193
                    posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
slouken@320
   194
                }
slouken@320
   195
            }
slouken@320
   196
        }
slouken@320
   197
        break;
slouken@0
   198
slouken@320
   199
        case Ph_EV_WM:
slouken@320
   200
        {
slouken@320
   201
            winEvent = PhGetData(event);
slouken@0
   202
slouken@320
   203
            /* losing focus */
slouken@320
   204
            if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
slouken@320
   205
            {
slouken@320
   206
                set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
slouken@320
   207
                posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
slouken@320
   208
            }
slouken@320
   209
            /* gaining focus */
slouken@320
   210
            else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
slouken@320
   211
            {
slouken@320
   212
                set_motion_sensitivity(this, -1);
slouken@320
   213
                posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
slouken@320
   214
            }
slouken@320
   215
            /* request to quit */
slouken@320
   216
            else if (winEvent->event_f==Ph_WM_CLOSE)
slouken@320
   217
            {
slouken@320
   218
                posted = SDL_PrivateQuit();
slouken@320
   219
            }
slouken@320
   220
            /* request to resize */
slouken@320
   221
            else if (winEvent->event_f==Ph_WM_RESIZE)
slouken@320
   222
            {
slouken@320
   223
                SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
slouken@320
   224
            }
slouken@320
   225
            /* request to maximize */
slouken@320
   226
            else if (winEvent->event_f==Ph_WM_MAX)
slouken@320
   227
            {
slouken@320
   228
                /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */
slouken@320
   229
            }
slouken@320
   230
        }
slouken@320
   231
        break;
slouken@0
   232
slouken@320
   233
        /* window has been resized, moved or removed */
slouken@320
   234
        case Ph_EV_EXPOSE:
slouken@320
   235
        {
slouken@320
   236
            if (SDL_VideoSurface)
slouken@320
   237
            {
slouken@320
   238
                rect = PhGetRects(event);
slouken@0
   239
slouken@320
   240
                for(i=0;i<event->num_rects;i++)
slouken@320
   241
                {
slouken@320
   242
                    sdlrects[i].x = rect[i].ul.x;
slouken@320
   243
                    sdlrects[i].y = rect[i].ul.y;
slouken@320
   244
                    sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
slouken@320
   245
                    sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
slouken@320
   246
                }
slouken@0
   247
slouken@320
   248
                this->UpdateRects(this, event->num_rects, sdlrects);
slouken@320
   249
            }
slouken@320
   250
        }
slouken@320
   251
	break;
slouken@0
   252
slouken@320
   253
        case Ph_EV_KEY:
slouken@320
   254
        {
slouken@320
   255
            SDL_keysym keysym;
slouken@283
   256
slouken@320
   257
            posted = 0;
slouken@0
   258
slouken@320
   259
            keyEvent = PhGetData( event );
slouken@220
   260
slouken@320
   261
            if (Pk_KF_Key_Down & keyEvent->key_flags)
slouken@320
   262
            {
slouken@320
   263
                posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
slouken@320
   264
            }
slouken@320
   265
            else /* must be key release */
slouken@320
   266
            {
slouken@320
   267
                 /* Ignore repeated key release events */
slouken@320
   268
                 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */
slouken@0
   269
slouken@320
   270
                posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
slouken@320
   271
            }
slouken@320
   272
        }
slouken@320
   273
        break;
slouken@320
   274
    }
slouken@0
   275
slouken@320
   276
    return(posted);
slouken@0
   277
}
slouken@0
   278
slouken@0
   279
/* perform a blocking read if no events available */
slouken@0
   280
int ph_Pending(_THIS)
slouken@0
   281
{
slouken@571
   282
    /* Flush the display connection and look to see if events are queued */
slouken@571
   283
    PgFlush();
slouken@0
   284
slouken@571
   285
    while( 1 )
slouken@571
   286
    {   /* note this is a non-blocking call */
slouken@571
   287
        switch( PhEventPeek( event, EVENT_SIZE ) )
slouken@571
   288
        {
slouken@571
   289
            case Ph_EVENT_MSG:
slouken@0
   290
                 return 1;
slouken@0
   291
                 break;
slouken@571
   292
            case -1:
slouken@571
   293
                 perror("ph_Pending(): PhEventNext failed");
slouken@0
   294
                 break;
slouken@571
   295
            default:
slouken@571
   296
                 return 0;
slouken@0
   297
        }
slouken@0
   298
    }
slouken@571
   299
slouken@571
   300
    /* Oh well, nothing is ready .. */
slouken@571
   301
    return(0);
slouken@0
   302
}
slouken@0
   303
slouken@0
   304
void ph_PumpEvents(_THIS)
slouken@0
   305
{
slouken@571
   306
    /* Flush the display connection and look to see if events are queued */
slouken@571
   307
    PgFlush();
slouken@0
   308
slouken@571
   309
    while (ph_Pending(this))
slouken@571
   310
    {
slouken@571
   311
        ph_DispatchEvent(this);
slouken@571
   312
    }
slouken@0
   313
}
slouken@0
   314
slouken@0
   315
void ph_InitKeymap(void)
slouken@0
   316
{
slouken@571
   317
    int i;
slouken@0
   318
slouken@571
   319
    /* Odd keys used in international keyboards */
slouken@571
   320
    for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
slouken@571
   321
        ODD_keymap[i] = SDLK_UNKNOWN;
slouken@0
   322
slouken@571
   323
    /* Map the miscellaneous keys */
slouken@571
   324
    for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
slouken@571
   325
        MISC_keymap[i] = SDLK_UNKNOWN;
slouken@0
   326
slouken@571
   327
    MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
slouken@571
   328
    MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
slouken@571
   329
    MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
slouken@571
   330
    MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
slouken@571
   331
    MISC_keymap[Pk_Pause&0xFF] = SDLK_PAUSE;
slouken@571
   332
    MISC_keymap[Pk_Escape&0xFF] = SDLK_ESCAPE;
slouken@571
   333
    MISC_keymap[Pk_Delete&0xFF] = SDLK_DELETE;
slouken@0
   334
slouken@571
   335
    MISC_keymap[Pk_KP_0&0xFF] = SDLK_KP0;
slouken@571
   336
    MISC_keymap[Pk_KP_1&0xFF] = SDLK_KP1;
slouken@571
   337
    MISC_keymap[Pk_KP_2&0xFF] = SDLK_KP2;
slouken@571
   338
    MISC_keymap[Pk_KP_3&0xFF] = SDLK_KP3;
slouken@571
   339
    MISC_keymap[Pk_KP_4&0xFF] = SDLK_KP4;
slouken@571
   340
    MISC_keymap[Pk_KP_5&0xFF] = SDLK_KP5;
slouken@571
   341
    MISC_keymap[Pk_KP_6&0xFF] = SDLK_KP6;
slouken@571
   342
    MISC_keymap[Pk_KP_7&0xFF] = SDLK_KP7;
slouken@571
   343
    MISC_keymap[Pk_KP_8&0xFF] = SDLK_KP8;
slouken@571
   344
    MISC_keymap[Pk_KP_9&0xFF] = SDLK_KP9;
slouken@0
   345
slouken@571
   346
    MISC_keymap[Pk_KP_Decimal&0xFF] = SDLK_KP_PERIOD;
slouken@571
   347
    MISC_keymap[Pk_KP_Divide&0xFF] = SDLK_KP_DIVIDE;
slouken@571
   348
    MISC_keymap[Pk_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;
slouken@571
   349
    MISC_keymap[Pk_KP_Subtract&0xFF] = SDLK_KP_MINUS;
slouken@571
   350
    MISC_keymap[Pk_KP_Add&0xFF] = SDLK_KP_PLUS;
slouken@571
   351
    MISC_keymap[Pk_KP_Enter&0xFF] = SDLK_KP_ENTER;
slouken@571
   352
    MISC_keymap[Pk_KP_Equal&0xFF] = SDLK_KP_EQUALS;
slouken@0
   353
slouken@571
   354
    MISC_keymap[Pk_Up&0xFF] = SDLK_UP;
slouken@571
   355
    MISC_keymap[Pk_Down&0xFF] = SDLK_DOWN;
slouken@571
   356
    MISC_keymap[Pk_Right&0xFF] = SDLK_RIGHT;
slouken@571
   357
    MISC_keymap[Pk_Left&0xFF] = SDLK_LEFT;
slouken@571
   358
    MISC_keymap[Pk_Insert&0xFF] = SDLK_INSERT;
slouken@571
   359
    MISC_keymap[Pk_Home&0xFF] = SDLK_HOME;
slouken@571
   360
    MISC_keymap[Pk_End&0xFF] = SDLK_END;
slouken@571
   361
    MISC_keymap[Pk_Pg_Up&0xFF] = SDLK_PAGEUP;
slouken@571
   362
    MISC_keymap[Pk_Pg_Down&0xFF] = SDLK_PAGEDOWN;
slouken@0
   363
slouken@571
   364
    MISC_keymap[Pk_F1&0xFF] = SDLK_F1;
slouken@571
   365
    MISC_keymap[Pk_F2&0xFF] = SDLK_F2;
slouken@571
   366
    MISC_keymap[Pk_F3&0xFF] = SDLK_F3;
slouken@571
   367
    MISC_keymap[Pk_F4&0xFF] = SDLK_F4;
slouken@571
   368
    MISC_keymap[Pk_F5&0xFF] = SDLK_F5;
slouken@571
   369
    MISC_keymap[Pk_F6&0xFF] = SDLK_F6;
slouken@571
   370
    MISC_keymap[Pk_F7&0xFF] = SDLK_F7;
slouken@571
   371
    MISC_keymap[Pk_F8&0xFF] = SDLK_F8;
slouken@571
   372
    MISC_keymap[Pk_F9&0xFF] = SDLK_F9;
slouken@571
   373
    MISC_keymap[Pk_F10&0xFF] = SDLK_F10;
slouken@571
   374
    MISC_keymap[Pk_F11&0xFF] = SDLK_F11;
slouken@571
   375
    MISC_keymap[Pk_F12&0xFF] = SDLK_F12;
slouken@571
   376
    MISC_keymap[Pk_F13&0xFF] = SDLK_F13;
slouken@571
   377
    MISC_keymap[Pk_F14&0xFF] = SDLK_F14;
slouken@571
   378
    MISC_keymap[Pk_F15&0xFF] = SDLK_F15;
slouken@0
   379
slouken@571
   380
    MISC_keymap[Pk_Num_Lock&0xFF] = SDLK_NUMLOCK;
slouken@571
   381
    MISC_keymap[Pk_Caps_Lock&0xFF] = SDLK_CAPSLOCK;
slouken@571
   382
    MISC_keymap[Pk_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
slouken@571
   383
    MISC_keymap[Pk_Shift_R&0xFF] = SDLK_RSHIFT;
slouken@571
   384
    MISC_keymap[Pk_Shift_L&0xFF] = SDLK_LSHIFT;
slouken@571
   385
    MISC_keymap[Pk_Control_R&0xFF] = SDLK_RCTRL;
slouken@571
   386
    MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
slouken@571
   387
    MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
slouken@571
   388
    MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
slouken@571
   389
    MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
slouken@571
   390
    MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
slouken@571
   391
    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
slouken@571
   392
    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
slouken@571
   393
    MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
slouken@0
   394
slouken@571
   395
    MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
slouken@571
   396
    MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
slouken@571
   397
    MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
slouken@571
   398
    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
slouken@571
   399
    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
slouken@0
   400
}
slouken@0
   401
slouken@0
   402
static unsigned long cap;
slouken@0
   403
slouken@0
   404
SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
slouken@0
   405
{
slouken@571
   406
    /* 'sym' is set to the value of the key with modifiers applied to it.
slouken@571
   407
       This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
slouken@571
   408
       We will assume it is valid. */
slouken@283
   409
slouken@571
   410
    /* FIXME: This needs to check whether the cap & scancode is valid */
slouken@283
   411
slouken@571
   412
    cap = key->key_cap;
slouken@571
   413
slouken@571
   414
    switch (cap>>8)
slouken@571
   415
    {
slouken@571
   416
        case 0x00:  /* Latin 1 */
slouken@571
   417
        case 0x01:  /* Latin 2 */
slouken@571
   418
        case 0x02:  /* Latin 3 */
slouken@571
   419
        case 0x03:  /* Latin 4 */
slouken@571
   420
        case 0x04:  /* Katakana */
slouken@571
   421
        case 0x05:  /* Arabic */
slouken@571
   422
        case 0x06:  /* Cyrillic */
slouken@571
   423
        case 0x07:  /* Greek */
slouken@571
   424
        case 0x08:  /* Technical */
slouken@571
   425
        case 0x0A:  /* Publishing */
slouken@571
   426
        case 0x0C:  /* Hebrew */
slouken@571
   427
        case 0x0D:  /* Thai */
slouken@571
   428
                   keysym->sym = (SDLKey)(cap&0xFF);
slouken@571
   429
                   /* Map capital letter syms to lowercase */
slouken@571
   430
                   if ((keysym->sym >= 'A')&&(keysym->sym <= 'Z'))
slouken@571
   431
                       keysym->sym += ('a'-'A');
slouken@571
   432
                   break;
slouken@571
   433
        case 0xF0:
slouken@571
   434
                   keysym->sym = MISC_keymap[cap&0xFF];
slouken@571
   435
                   break;
slouken@571
   436
        default:
slouken@571
   437
                   keysym->sym = SDLK_UNKNOWN;                
slouken@571
   438
                   break;
slouken@571
   439
    }
slouken@571
   440
slouken@571
   441
    keysym->scancode = key->key_scan;
slouken@571
   442
    keysym->unicode = 0;
slouken@571
   443
slouken@571
   444
    if (SDL_TranslateUNICODE)
slouken@571
   445
    {
slouken@571
   446
        char utf8[MB_CUR_MAX];
slouken@571
   447
        int utf8len;
slouken@571
   448
        wchar_t unicode;
slouken@571
   449
slouken@571
   450
        utf8len = PhKeyToMb(utf8, key);
slouken@571
   451
        if (utf8len > 0)
slouken@571
   452
        {
slouken@571
   453
            utf8len = mbtowc(&unicode, utf8, utf8len);
slouken@571
   454
            if (utf8len > 0)
slouken@571
   455
                keysym->unicode = unicode;
slouken@571
   456
        }
slouken@571
   457
    }
slouken@571
   458
slouken@571
   459
    return (keysym);
slouken@0
   460
}
slouken@0
   461
slouken@0
   462
void ph_InitOSKeymap(_THIS)
slouken@0
   463
{
slouken@571
   464
    ph_InitKeymap();
slouken@0
   465
}