comparison src/video/photon/SDL_ph_events.c @ 1895:c121d94672cb

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