Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
623 lines (547 loc) · 20.9 KB

SDL_ph_events.c

File metadata and controls

623 lines (547 loc) · 20.9 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
27
28
29
/* Handle the event stream, converting photon events into SDL events */
#include <stdio.h>
#include <setjmp.h>
#include <sys/time.h>
Aug 4, 2003
Aug 4, 2003
30
31
32
#include <Ph.h>
#include <photon/PkKeyDef.h>
Apr 26, 2001
Apr 26, 2001
33
34
#include "SDL.h"
#include "SDL_syswm.h"
Feb 16, 2006
Feb 16, 2006
35
36
37
#include "../SDL_sysvideo.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
Apr 26, 2001
Apr 26, 2001
38
39
40
41
#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
42
43
#include "SDL_phyuv_c.h"
Apr 26, 2001
Apr 26, 2001
44
45
46
/* The translation tables from a photon keysym to a SDL keysym */
static SDLKey ODD_keymap[256];
static SDLKey MISC_keymap[0xFF + 1];
Jul 10, 2006
Jul 10, 2006
47
SDL_keysym *ph_TranslateKey(PhKeyEvent_t * key, SDL_keysym * keysym);
Apr 26, 2001
Apr 26, 2001
48
49
/* Check to see if this is a repeated key.
Feb 14, 2004
Feb 14, 2004
50
(idea shamelessly lifted from GII -- thanks guys! :) */
Jul 10, 2006
Jul 10, 2006
51
52
static int
ph_WarpedMotion(_THIS, PhEvent_t * winEvent)
Apr 26, 2001
Apr 26, 2001
53
{
Jul 10, 2006
Jul 10, 2006
54
PhRect_t *rect = PhGetRects(winEvent);
Feb 20, 2002
Feb 20, 2002
55
Jan 20, 2003
Jan 20, 2003
56
57
58
59
int centre_x, centre_y;
int dx, dy;
short abs_x, abs_y;
int posted;
Apr 26, 2001
Apr 26, 2001
60
Jan 20, 2003
Jan 20, 2003
61
62
centre_x = SDL_VideoSurface->w / 2;
centre_y = SDL_VideoSurface->h / 2;
Feb 20, 2002
Feb 20, 2002
63
Jan 20, 2003
Jan 20, 2003
64
65
dx = rect->ul.x - centre_x;
dy = rect->ul.y - centre_y;
Feb 20, 2002
Feb 20, 2002
66
Jul 10, 2006
Jul 10, 2006
67
posted = SDL_PrivateMouseMotion(0, 1, dx, dy);
Feb 20, 2002
Feb 20, 2002
68
Jan 20, 2003
Jan 20, 2003
69
/* Move mouse cursor to middle of the window */
Jul 10, 2006
Jul 10, 2006
70
PtGetAbsPosition(window, &abs_x, &abs_y);
Jan 20, 2003
Jan 20, 2003
71
PhMoveCursorAbs(PhInputGroup(NULL), abs_x + centre_x, abs_y + centre_y);
Feb 20, 2002
Feb 20, 2002
72
Jan 20, 2003
Jan 20, 2003
73
return (posted);
Apr 26, 2001
Apr 26, 2001
74
75
}
Nov 1, 2001
Nov 1, 2001
76
77
/* 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
78
Jul 10, 2006
Jul 10, 2006
79
80
static void
set_motion_sensitivity(_THIS, unsigned int flags)
Nov 1, 2001
Nov 1, 2001
81
{
Jan 20, 2003
Jan 20, 2003
82
83
84
int rid;
int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
PhRegion_t region;
Nov 1, 2001
Nov 1, 2001
85
Jul 10, 2006
Jul 10, 2006
86
if (window) {
Aug 4, 2003
Aug 4, 2003
87
rid = PtWidgetRid(window);
Jul 10, 2006
Jul 10, 2006
88
89
90
if (rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0) {
region.events_sense =
(region.events_sense & ~fields) | (flags & fields);
Jan 20, 2003
Jan 20, 2003
91
92
93
PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
}
}
Nov 1, 2001
Nov 1, 2001
94
95
96
}
/* Convert the photon button state value to an SDL value */
Jul 10, 2006
Jul 10, 2006
97
98
static Uint8
ph2sdl_mousebutton(unsigned short button_state)
Nov 1, 2001
Nov 1, 2001
99
{
Jan 20, 2003
Jan 20, 2003
100
Uint8 mouse_button = 0;
Nov 1, 2001
Nov 1, 2001
101
Jan 20, 2003
Jan 20, 2003
102
103
104
105
106
107
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
108
Jan 20, 2003
Jan 20, 2003
109
return (mouse_button);
Nov 1, 2001
Nov 1, 2001
110
111
}
Jul 10, 2006
Jul 10, 2006
112
113
static int
ph_DispatchEvent(_THIS)
Apr 26, 2001
Apr 26, 2001
114
{
Mar 28, 2002
Mar 28, 2002
115
int posted;
Jul 10, 2006
Jul 10, 2006
116
117
118
119
PhRect_t *rect;
PhPointerEvent_t *pointerEvent;
PhKeyEvent_t *keyEvent;
PhWindowEvent_t *winEvent;
Mar 28, 2002
Mar 28, 2002
120
int i, buttons;
Feb 14, 2004
Feb 14, 2004
121
SDL_Rect sdlrects[PH_SDL_MAX_RECTS];
Jul 10, 2006
Jul 10, 2006
122
Mar 28, 2002
Mar 28, 2002
123
posted = 0;
Jul 10, 2006
Jul 10, 2006
124
125
126
switch (phevent->type) {
case Ph_EV_BOUNDARY:
Mar 28, 2002
Mar 28, 2002
127
{
Jul 10, 2006
Jul 10, 2006
128
if (phevent->subtype == Ph_EV_PTR_ENTER) {
Mar 28, 2002
Mar 28, 2002
129
posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
Jul 10, 2006
Jul 10, 2006
130
131
} else if (phevent->subtype == Ph_EV_PTR_LEAVE) {
posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
Mar 28, 2002
Mar 28, 2002
132
133
134
135
}
}
break;
Jul 10, 2006
Jul 10, 2006
136
137
case Ph_EV_PTR_MOTION_BUTTON:
case Ph_EV_PTR_MOTION_NOBUTTON:
Mar 28, 2002
Mar 28, 2002
138
{
Jul 10, 2006
Jul 10, 2006
139
if (SDL_VideoSurface) {
Mar 8, 2006
Mar 8, 2006
140
141
pointerEvent = PhGetData(phevent);
rect = PhGetRects(phevent);
Mar 28, 2002
Mar 28, 2002
142
Jul 10, 2006
Jul 10, 2006
143
if (mouse_relative) {
Mar 8, 2006
Mar 8, 2006
144
posted = ph_WarpedMotion(this, phevent);
Jul 10, 2006
Jul 10, 2006
145
146
147
} else {
posted =
SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
Mar 28, 2002
Mar 28, 2002
148
149
150
151
152
}
}
}
break;
Jul 10, 2006
Jul 10, 2006
153
case Ph_EV_BUT_PRESS:
Mar 28, 2002
Mar 28, 2002
154
{
Mar 8, 2006
Mar 8, 2006
155
156
pointerEvent = PhGetData(phevent);
buttons = ph2sdl_mousebutton(pointerEvent->buttons);
Jul 10, 2006
Jul 10, 2006
157
if (buttons != 0) {
Mar 28, 2002
Mar 28, 2002
158
159
160
161
162
posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
}
}
break;
Jul 10, 2006
Jul 10, 2006
163
case Ph_EV_BUT_RELEASE:
Mar 28, 2002
Mar 28, 2002
164
{
Mar 8, 2006
Mar 8, 2006
165
pointerEvent = PhGetData(phevent);
Mar 28, 2002
Mar 28, 2002
166
buttons = ph2sdl_mousebutton(pointerEvent->buttons);
Jul 10, 2006
Jul 10, 2006
167
if (phevent->subtype == Ph_EV_RELEASE_REAL && buttons != 0) {
Mar 28, 2002
Mar 28, 2002
168
posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
Jul 10, 2006
Jul 10, 2006
169
} else if (phevent->subtype == Ph_EV_RELEASE_PHANTOM) {
Mar 28, 2002
Mar 28, 2002
170
171
172
173
174
175
/* 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. */
Jul 10, 2006
Jul 10, 2006
176
177
178
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) {
posted =
SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
Mar 28, 2002
Mar 28, 2002
179
180
181
182
183
}
}
}
break;
Jul 10, 2006
Jul 10, 2006
184
case Ph_EV_WM:
Mar 28, 2002
Mar 28, 2002
185
{
Mar 8, 2006
Mar 8, 2006
186
winEvent = PhGetData(phevent);
Mar 28, 2002
Mar 28, 2002
187
188
/* losing focus */
Jul 10, 2006
Jul 10, 2006
189
190
if ((winEvent->event_f == Ph_WM_FOCUS)
&& (winEvent->event_state == Ph_WM_EVSTATE_FOCUSLOST)) {
Mar 28, 2002
Mar 28, 2002
191
set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
Jul 10, 2006
Jul 10, 2006
192
posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
Mar 28, 2002
Mar 28, 2002
193
194
}
/* gaining focus */
Jul 10, 2006
Jul 10, 2006
195
196
else if ((winEvent->event_f == Ph_WM_FOCUS)
&& (winEvent->event_state == Ph_WM_EVSTATE_FOCUS)) {
Mar 28, 2002
Mar 28, 2002
197
198
199
set_motion_sensitivity(this, -1);
posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
}
Feb 14, 2004
Feb 14, 2004
200
/* request quit */
Jul 10, 2006
Jul 10, 2006
201
else if (winEvent->event_f == Ph_WM_CLOSE) {
Mar 28, 2002
Mar 28, 2002
202
203
posted = SDL_PrivateQuit();
}
Feb 14, 2004
Feb 14, 2004
204
/* request hide/unhide */
Jul 10, 2006
Jul 10, 2006
205
206
207
208
209
210
211
212
213
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;
Aug 4, 2003
Aug 4, 2003
214
215
}
}
Mar 28, 2002
Mar 28, 2002
216
/* request to resize */
Jul 10, 2006
Jul 10, 2006
217
218
219
220
221
222
223
224
else if (winEvent->event_f == Ph_WM_RESIZE) {
currently_maximized = 0;
#if (_NTO_VERSION < 630)
SDL_PrivateResize(winEvent->size.w + 1, winEvent->size.h + 1);
#else
/* QNX 6.3.0 have this bug fixed */
SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
#endif /* _NTO_VERSION */
Mar 28, 2002
Mar 28, 2002
225
}
Aug 4, 2003
Aug 4, 2003
226
/* request to move */
Jul 10, 2006
Jul 10, 2006
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
else if (winEvent->event_f == Ph_WM_MOVE) {
if (current_overlay != NULL) {
int lockedstate = current_overlay->hwdata->locked;
int chromastate = current_overlay->hwdata->ischromakey;
int error;
SDL_Rect src, dst;
current_overlay->hwdata->locked = 1;
src.x = 0;
src.y = 0;
src.w = current_overlay->w;
src.y = current_overlay->h;
dst.x = current_overlay->hwdata->CurrentViewPort.pos.x;
dst.y = current_overlay->hwdata->CurrentViewPort.pos.y;
dst.w = current_overlay->hwdata->CurrentViewPort.size.w;
dst.h = current_overlay->hwdata->CurrentViewPort.size.h;
current_overlay->hwdata->ischromakey = 0;
error =
ph_DisplayYUVOverlay(this, current_overlay,
&src, &dst);
if (!error) {
current_overlay->hwdata->ischromakey = chromastate;
current_overlay->hwdata->locked = lockedstate;
}
Aug 4, 2003
Aug 4, 2003
251
252
}
}
Dec 10, 2003
Dec 10, 2003
253
/* maximize request */
Jul 10, 2006
Jul 10, 2006
254
else if (winEvent->event_f == Ph_WM_MAX) {
Aug 4, 2003
Aug 4, 2003
255
/* window already moved and resized here */
Jul 10, 2006
Jul 10, 2006
256
currently_maximized = 1;
Aug 4, 2003
Aug 4, 2003
257
}
Dec 10, 2003
Dec 10, 2003
258
/* restore request */
Jul 10, 2006
Jul 10, 2006
259
else if (winEvent->event_f == Ph_WM_RESTORE) {
Dec 10, 2003
Dec 10, 2003
260
/* window already moved and resized here */
Jul 10, 2006
Jul 10, 2006
261
currently_maximized = 0;
Mar 28, 2002
Mar 28, 2002
262
263
264
265
266
}
}
break;
/* window has been resized, moved or removed */
Jul 10, 2006
Jul 10, 2006
267
case Ph_EV_EXPOSE:
Mar 28, 2002
Mar 28, 2002
268
{
Jul 10, 2006
Jul 10, 2006
269
if (phevent->num_rects != 0) {
Feb 14, 2004
Feb 14, 2004
270
271
int numrects;
Jul 10, 2006
Jul 10, 2006
272
if (SDL_VideoSurface) {
Mar 8, 2006
Mar 8, 2006
273
rect = PhGetRects(phevent);
Jul 10, 2006
Jul 10, 2006
274
275
276
if (phevent->num_rects > PH_SDL_MAX_RECTS) {
/* sorry, buffers underrun, we'll update only first PH_SDL_MAX_RECTS rects */
numrects = PH_SDL_MAX_RECTS;
Feb 14, 2004
Feb 14, 2004
277
}
Aug 4, 2003
Aug 4, 2003
278
Jul 10, 2006
Jul 10, 2006
279
for (i = 0; i < phevent->num_rects; i++) {
Aug 4, 2003
Aug 4, 2003
280
281
282
283
284
285
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;
}
Mar 8, 2006
Mar 8, 2006
286
this->UpdateRects(this, phevent->num_rects, sdlrects);
Aug 4, 2003
Aug 4, 2003
287
Jul 10, 2006
Jul 10, 2006
288
289
if (current_overlay != NULL) {
int lockedstate = current_overlay->hwdata->locked;
Dec 10, 2003
Dec 10, 2003
290
int error;
Apr 17, 2006
Apr 17, 2006
291
SDL_Rect src, dst;
Aug 4, 2003
Aug 4, 2003
292
Jul 10, 2006
Jul 10, 2006
293
current_overlay->hwdata->locked = 1;
Apr 17, 2006
Apr 17, 2006
294
295
296
297
src.x = 0;
src.y = 0;
src.w = current_overlay->w;
src.y = current_overlay->h;
Jul 10, 2006
Jul 10, 2006
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
dst.x =
current_overlay->hwdata->CurrentViewPort.pos.x;
dst.y =
current_overlay->hwdata->CurrentViewPort.pos.y;
dst.w =
current_overlay->hwdata->CurrentViewPort.size.w;
dst.h =
current_overlay->hwdata->CurrentViewPort.size.h;
current_overlay->hwdata->forcedredraw = 1;
error =
ph_DisplayYUVOverlay(this,
current_overlay, &src, &dst);
if (!error) {
current_overlay->hwdata->forcedredraw = 0;
current_overlay->hwdata->locked = lockedstate;
Dec 10, 2003
Dec 10, 2003
313
}
Aug 4, 2003
Aug 4, 2003
314
}
Mar 28, 2002
Mar 28, 2002
315
316
317
}
}
}
Jul 10, 2006
Jul 10, 2006
318
break;
Mar 28, 2002
Mar 28, 2002
319
Jul 10, 2006
Jul 10, 2006
320
case Ph_EV_KEY:
Mar 28, 2002
Mar 28, 2002
321
322
323
324
325
{
SDL_keysym keysym;
posted = 0;
Mar 8, 2006
Mar 8, 2006
326
keyEvent = PhGetData(phevent);
Mar 28, 2002
Mar 28, 2002
327
Jul 10, 2006
Jul 10, 2006
328
if (Pk_KF_Key_Down & keyEvent->key_flags) {
Aug 4, 2003
Aug 4, 2003
329
/* split the wheel events from real key events */
Jul 10, 2006
Jul 10, 2006
330
331
332
333
334
335
336
337
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;
Aug 4, 2003
Aug 4, 2003
338
}
Jul 10, 2006
Jul 10, 2006
339
340
341
342
343
344
345
346
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;
Aug 4, 2003
Aug 4, 2003
347
}
Jul 10, 2006
Jul 10, 2006
348
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
/* split the wheel events from real key events */
Jul 10, 2006
Jul 10, 2006
354
355
356
357
358
359
360
361
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;
Aug 4, 2003
Aug 4, 2003
362
}
Jul 10, 2006
Jul 10, 2006
363
364
365
366
367
368
369
370
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;
Aug 4, 2003
Aug 4, 2003
371
}
Jul 10, 2006
Jul 10, 2006
372
373
374
posted =
SDL_PrivateKeyboard(SDL_RELEASED,
ph_TranslateKey(keyEvent, &keysym));
Mar 28, 2002
Mar 28, 2002
375
376
377
}
}
break;
Jul 10, 2006
Jul 10, 2006
378
379
case Ph_EV_INFO:
Dec 10, 2003
Dec 10, 2003
380
{
Jul 10, 2006
Jul 10, 2006
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
if (phevent->subtype == Ph_OFFSCREEN_INVALID) {
unsigned long *EvInfoData;
EvInfoData = (unsigned long *) PhGetData(phevent);
switch (*EvInfoData) {
case Pg_VIDEO_MODE_SWITCHED:
{
}
break;
case Pg_ENTERED_DIRECT:
{
}
break;
case Pg_EXITED_DIRECT:
{
}
break;
case Pg_DRIVER_STARTED:
{
}
break;
}
}
Dec 10, 2003
Dec 10, 2003
405
406
}
break;
Mar 28, 2002
Mar 28, 2002
407
408
}
Jul 10, 2006
Jul 10, 2006
409
return (posted);
Apr 26, 2001
Apr 26, 2001
410
411
412
}
/* perform a blocking read if no events available */
Jul 10, 2006
Jul 10, 2006
413
414
int
ph_Pending(_THIS)
Apr 26, 2001
Apr 26, 2001
415
{
Jan 20, 2003
Jan 20, 2003
416
417
418
/* Flush the display connection and look to see if events are queued */
PgFlush();
Jul 10, 2006
Jul 10, 2006
419
420
421
422
423
424
425
426
427
while (1) {
switch (PhEventPeek(phevent, EVENT_SIZE)) {
case Ph_EVENT_MSG:
return 1;
case -1:
SDL_SetError("ph_Pending(): PhEventNext failed.\n");
return 0;
default:
return 0;
Apr 26, 2001
Apr 26, 2001
428
429
}
}
Jan 20, 2003
Jan 20, 2003
430
431
/* Oh well, nothing is ready .. */
Jul 10, 2006
Jul 10, 2006
432
return (0);
Apr 26, 2001
Apr 26, 2001
433
434
}
Jul 10, 2006
Jul 10, 2006
435
436
void
ph_PumpEvents(_THIS)
Apr 26, 2001
Apr 26, 2001
437
{
Jan 20, 2003
Jan 20, 2003
438
439
440
/* Flush the display connection and look to see if events are queued */
PgFlush();
Jul 10, 2006
Jul 10, 2006
441
while (ph_Pending(this)) {
Mar 8, 2006
Mar 8, 2006
442
PtEventHandler(phevent);
Jan 20, 2003
Jan 20, 2003
443
444
ph_DispatchEvent(this);
}
Apr 26, 2001
Apr 26, 2001
445
446
}
Jul 10, 2006
Jul 10, 2006
447
448
void
ph_InitKeymap(void)
Apr 26, 2001
Apr 26, 2001
449
{
Jan 20, 2003
Jan 20, 2003
450
451
452
int i;
/* Odd keys used in international keyboards */
Jul 10, 2006
Jul 10, 2006
453
for (i = 0; i < SDL_arraysize(ODD_keymap); ++i) {
Jan 20, 2003
Jan 20, 2003
454
ODD_keymap[i] = SDLK_UNKNOWN;
Aug 4, 2003
Aug 4, 2003
455
}
Jan 20, 2003
Jan 20, 2003
456
457
/* Map the miscellaneous keys */
Jul 10, 2006
Jul 10, 2006
458
for (i = 0; i < SDL_arraysize(MISC_keymap); ++i) {
Jan 20, 2003
Jan 20, 2003
459
MISC_keymap[i] = SDLK_UNKNOWN;
Aug 4, 2003
Aug 4, 2003
460
}
Jan 20, 2003
Jan 20, 2003
461
Jul 10, 2006
Jul 10, 2006
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
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;
MISC_keymap[Pk_Super_L & 0xFF] = SDLK_LSUPER;
MISC_keymap[Pk_Super_R & 0xFF] = SDLK_RSUPER;
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;
MISC_keymap[Pk_Menu & 0xFF] = SDLK_MENU; /* Windows "Menu" key */
MISC_keymap[Pk_Hyper_R & 0xFF] = SDLK_RSUPER; /* Right "Windows" */
Aug 4, 2003
Aug 4, 2003
536
537
/* Left "Windows" key, but it can't be catched by application */
Jul 10, 2006
Jul 10, 2006
538
MISC_keymap[Pk_Hyper_L & 0xFF] = SDLK_LSUPER;
Apr 26, 2001
Apr 26, 2001
539
540
541
542
}
static unsigned long cap;
Jul 10, 2006
Jul 10, 2006
543
544
SDL_keysym *
ph_TranslateKey(PhKeyEvent_t * key, SDL_keysym * keysym)
Apr 26, 2001
Apr 26, 2001
545
{
Jan 20, 2003
Jan 20, 2003
546
547
548
549
550
551
552
/* '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
553
Jul 10, 2006
Jul 10, 2006
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
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;
Jan 20, 2003
Jan 20, 2003
578
579
580
581
582
}
keysym->scancode = key->key_scan;
keysym->unicode = 0;
Jul 10, 2006
Jul 10, 2006
583
if (SDL_TranslateUNICODE) {
Jan 20, 2003
Jan 20, 2003
584
585
586
587
char utf8[MB_CUR_MAX];
int utf8len;
wchar_t unicode;
Jul 10, 2006
Jul 10, 2006
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
switch (keysym->scancode) {
/* Esc key */
case 0x01:
keysym->unicode = 27;
break;
/* BackSpace key */
case 0x0E:
keysym->unicode = 127;
break;
/* Enter key */
case 0x1C:
keysym->unicode = 10;
break;
default:
utf8len = PhKeyToMb(utf8, key);
if (utf8len > 0) {
utf8len = mbtowc(&unicode, utf8, utf8len);
if (utf8len > 0) {
keysym->unicode = unicode;
}
}
break;
Jan 20, 2003
Jan 20, 2003
610
}
Aug 4, 2003
Aug 4, 2003
611
Jan 20, 2003
Jan 20, 2003
612
613
614
}
return (keysym);
Apr 26, 2001
Apr 26, 2001
615
616
}
Jul 10, 2006
Jul 10, 2006
617
618
void
ph_InitOSKeymap(_THIS)
Apr 26, 2001
Apr 26, 2001
619
{
Jan 20, 2003
Jan 20, 2003
620
ph_InitKeymap();
Apr 26, 2001
Apr 26, 2001
621
}
Jul 10, 2006
Jul 10, 2006
622
623
/* vi: set ts=4 sw=4 expandtab: */