Skip to content

Latest commit

 

History

History
590 lines (513 loc) · 18.8 KB

SDL_ph_events.c

File metadata and controls

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