comparison src/video/photon/SDL_ph_events.c @ 663:8bedd6d61642

Date: Sat, 2 Aug 2003 16:22:51 +0300 From: "Mike Gorchak" Subject: New patches for QNX6 Here my patches for the SDL/QNX: QNXSDL.diff - diff to non-QNX related sources: - updated BUGS file, I think QNX6 is now will be officially supported - configure.in - added shared library support for QNX, and removed dependency between the ALSA and QNX6. - SDL_audio.c - added QNX NTO sound bootstrap insted of ALSA's. - SDL_sysaudio.h - the same. - SDL_nto_audio.c - the same. - SDL_video.c - right now, QNX doesn't offer any method to obtain pointers to the OpenGL functions by function name, so they must be hardcoded in library, otherwise OpenGL will not be supported. - testsprite.c - fixed: do not draw vertical red line if we are in non-double-buffered mode. sdlqnxph.tar.gz - archive of the ./src/video/photon/* . Too many changes in code to make diffs :) : + Added stub for support hide/unhide window event + Added full YUV overlays support. + Added window maximize support. + Added mouse wheel events. + Added support for some specific key codes in Unicode mode (like ESC). + Added more checks to the all memory allocation code. + Added SDL_DOUBLEBUF support in all fullscreen modes. + Added fallback to window mode, if desired fullscreen mode is not supported. + Added stub support for the GL_LoadLibrary and GL_GetProcAddress functions. + Added resizable window support without caption. ! Fixed bug in the Ph_EV_EXPOSE event handler, when rectangles to update is 0 and when width or height of the rectangle is 0. ! Fixed bug in the event handler code. Events has not been passed to the window widget handler. ! Fixed codes for Win keys (Super/Hyper/Menu). ! Fixed memory leak, when deallocation palette. ! Fixed palette emulation code bugs. ! Fixed fullscreen and hwsurface handling. ! Fixed CLOSE button bug. First event was passed to the handler, but second terminated the application. Now all events passed to the application correctly. - Removed all printfs in code, now SDL_SetError used instead of them. - Disabled ToggleFullScreen function. README.QNX - updated README.QNX file. Added much more issues.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 04 Aug 2003 00:52:42 +0000
parents 8e3ce997621c
children b14fdadd8311
comparison
equal deleted inserted replaced
662:66c02f83f5bf 663:8bedd6d61642
27 27
28 /* Handle the event stream, converting photon events into SDL events */ 28 /* Handle the event stream, converting photon events into SDL events */
29 29
30 #define DISABLE_X11 30 #define DISABLE_X11
31 31
32 #include <Ph.h>
33 #include <stdio.h> 32 #include <stdio.h>
34 #include <setjmp.h> 33 #include <setjmp.h>
34 #include <sys/time.h>
35
36 #include <Ph.h>
35 #include <photon/PkKeyDef.h> 37 #include <photon/PkKeyDef.h>
36 #include <sys/time.h>
37 38
38 #include "SDL.h" 39 #include "SDL.h"
39 #include "SDL_syswm.h" 40 #include "SDL_syswm.h"
40 #include "SDL_sysevents.h" 41 #include "SDL_sysevents.h"
41 #include "SDL_sysvideo.h" 42 #include "SDL_sysvideo.h"
42 #include "SDL_events_c.h" 43 #include "SDL_events_c.h"
43 #include "SDL_ph_video.h" 44 #include "SDL_ph_video.h"
44 #include "SDL_ph_modes_c.h" 45 #include "SDL_ph_modes_c.h"
45 #include "SDL_ph_image_c.h" 46 #include "SDL_ph_image_c.h"
46 #include "SDL_ph_events_c.h" 47 #include "SDL_ph_events_c.h"
48 #include "SDL_phyuv_c.h"
49
47 50
48 51
49 /* The translation tables from a photon keysym to a SDL keysym */ 52 /* The translation tables from a photon keysym to a SDL keysym */
50 static SDLKey ODD_keymap[256]; 53 static SDLKey ODD_keymap[256];
51 static SDLKey MISC_keymap[0xFF + 1]; 54 static SDLKey MISC_keymap[0xFF + 1];
88 int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON; 91 int fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
89 PhRegion_t region; 92 PhRegion_t region;
90 93
91 if( window ) 94 if( window )
92 { 95 {
93 rid = PtWidgetRid( window ); 96 rid = PtWidgetRid(window);
94 if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 ) 97 if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )
95 { 98 {
96 region.events_sense=(region.events_sense & ~fields)|(flags & fields); 99 region.events_sense=(region.events_sense & ~fields)|(flags & fields);
97 PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL); 100 PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
98 } 101 }
99 } 102 }
111 if (button_state & Ph_BUTTON_ADJUST) 114 if (button_state & Ph_BUTTON_ADJUST)
112 mouse_button |= SDL_BUTTON_MIDDLE; 115 mouse_button |= SDL_BUTTON_MIDDLE;
113 116
114 return (mouse_button); 117 return (mouse_button);
115 } 118 }
119
120 // void* PtAppCreateContext();
116 121
117 static int ph_DispatchEvent(_THIS) 122 static int ph_DispatchEvent(_THIS)
118 { 123 {
119 int posted; 124 int posted;
120 PhRect_t* rect; 125 PhRect_t* rect;
215 /* request to quit */ 220 /* request to quit */
216 else if (winEvent->event_f==Ph_WM_CLOSE) 221 else if (winEvent->event_f==Ph_WM_CLOSE)
217 { 222 {
218 posted = SDL_PrivateQuit(); 223 posted = SDL_PrivateQuit();
219 } 224 }
225 /* request to hide/unhide */
226 else if (winEvent->event_f==Ph_WM_HIDE)
227 {
228 if (currently_hided)
229 {
230 /* got unhide window event */
231 /* TODO: restore application's palette if in palette mode */
232 currently_hided=0;
233 }
234 else
235 {
236 /* got hide window event */
237 /* TODO: restore original palette if in palette mode */
238 currently_hided=1;
239 }
240 }
220 /* request to resize */ 241 /* request to resize */
221 else if (winEvent->event_f==Ph_WM_RESIZE) 242 else if (winEvent->event_f==Ph_WM_RESIZE)
222 { 243 {
223 SDL_PrivateResize(winEvent->size.w, winEvent->size.h); 244 SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
224 } 245 }
246 /* request to move */
247 else if (winEvent->event_f==Ph_WM_MOVE)
248 {
249 if (current_overlay!=NULL)
250 {
251 int lockedstate=current_overlay->hwdata->locked;
252 int chromastate=current_overlay->hwdata->ischromakey;
253 SDL_Rect target;
254
255 current_overlay->hwdata->locked=1;
256 target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
257 target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
258 target.w=current_overlay->hwdata->CurrentViewPort.size.w;
259 target.h=current_overlay->hwdata->CurrentViewPort.size.h;
260 current_overlay->hwdata->ischromakey=0;
261 ph_DisplayYUVOverlay(this, current_overlay, &target);
262 current_overlay->hwdata->ischromakey=chromastate;
263 current_overlay->hwdata->locked=lockedstate;
264 }
265 }
225 /* request to maximize */ 266 /* request to maximize */
226 else if (winEvent->event_f==Ph_WM_MAX) 267 else if (winEvent->event_f==Ph_WM_MAX)
227 { 268 {
228 /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */ 269 /* window already moved and resized here */
270 SDL_PrivateResize(winEvent->size.w-winEvent->pos.x, winEvent->size.h-winEvent->pos.y);
271 }
272 /* request to restore */
273 else if (winEvent->event_f==Ph_WM_RESTORE)
274 {
229 } 275 }
230 } 276 }
231 break; 277 break;
232 278
233 /* window has been resized, moved or removed */ 279 /* window has been resized, moved or removed */
234 case Ph_EV_EXPOSE: 280 case Ph_EV_EXPOSE:
235 { 281 {
236 if (SDL_VideoSurface) 282 if (event->num_rects!=0)
237 { 283 {
238 rect = PhGetRects(event); 284 if (SDL_VideoSurface)
239 285 {
240 for(i=0;i<event->num_rects;i++) 286 rect = PhGetRects(event);
241 { 287
242 sdlrects[i].x = rect[i].ul.x; 288 for(i=0;i<event->num_rects;i++)
243 sdlrects[i].y = rect[i].ul.y; 289 {
244 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; 290 sdlrects[i].x = rect[i].ul.x;
245 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; 291 sdlrects[i].y = rect[i].ul.y;
246 } 292 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
247 293 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
248 this->UpdateRects(this, event->num_rects, sdlrects); 294 }
295
296 this->UpdateRects(this, event->num_rects, sdlrects);
297
298 if (current_overlay!=NULL)
299 {
300 int lockedstate=current_overlay->hwdata->locked;
301 SDL_Rect target;
302
303 current_overlay->hwdata->locked=1;
304 target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
305 target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
306 target.w=current_overlay->hwdata->CurrentViewPort.size.w;
307 target.h=current_overlay->hwdata->CurrentViewPort.size.h;
308 current_overlay->hwdata->forcedredraw=1;
309 ph_DisplayYUVOverlay(this, current_overlay, &target);
310 current_overlay->hwdata->forcedredraw=0;
311 current_overlay->hwdata->locked=lockedstate;
312 }
313 }
249 } 314 }
250 } 315 }
251 break; 316 break;
252 317
253 case Ph_EV_KEY: 318 case Ph_EV_KEY:
258 323
259 keyEvent = PhGetData( event ); 324 keyEvent = PhGetData( event );
260 325
261 if (Pk_KF_Key_Down & keyEvent->key_flags) 326 if (Pk_KF_Key_Down & keyEvent->key_flags)
262 { 327 {
328 /* split the wheel events from real key events */
329 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
330 {
331 posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
332 break;
333 }
334 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
335 {
336 posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
337 break;
338 }
263 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym)); 339 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
264 } 340 }
265 else /* must be key release */ 341 else /* must be key release */
266 { 342 {
267 /* Ignore repeated key release events */ 343 /* split the wheel events from real key events */
268 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */ 344 if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
269 345 {
346 posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
347 break;
348 }
349 if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
350 {
351 posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
352 break;
353 }
270 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym)); 354 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
271 } 355 }
272 } 356 }
273 break; 357 break;
274 } 358 }
280 int ph_Pending(_THIS) 364 int ph_Pending(_THIS)
281 { 365 {
282 /* Flush the display connection and look to see if events are queued */ 366 /* Flush the display connection and look to see if events are queued */
283 PgFlush(); 367 PgFlush();
284 368
285 while( 1 ) 369 while (1)
286 { /* note this is a non-blocking call */ 370 {
287 switch( PhEventPeek( event, EVENT_SIZE ) ) 371 switch(PhEventPeek(event, EVENT_SIZE))
288 { 372 {
289 case Ph_EVENT_MSG: 373 case Ph_EVENT_MSG:
290 return 1; 374 return 1;
291 break; 375 break;
292 case -1: 376 case -1:
306 /* Flush the display connection and look to see if events are queued */ 390 /* Flush the display connection and look to see if events are queued */
307 PgFlush(); 391 PgFlush();
308 392
309 while (ph_Pending(this)) 393 while (ph_Pending(this))
310 { 394 {
395 PtEventHandler(event);
311 ph_DispatchEvent(this); 396 ph_DispatchEvent(this);
312 } 397 }
313 } 398 }
314 399
315 void ph_InitKeymap(void) 400 void ph_InitKeymap(void)
316 { 401 {
317 int i; 402 int i;
318 403
319 /* Odd keys used in international keyboards */ 404 /* Odd keys used in international keyboards */
320 for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i) 405 for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
406 {
321 ODD_keymap[i] = SDLK_UNKNOWN; 407 ODD_keymap[i] = SDLK_UNKNOWN;
408 }
322 409
323 /* Map the miscellaneous keys */ 410 /* Map the miscellaneous keys */
324 for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i) 411 for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
412 {
325 MISC_keymap[i] = SDLK_UNKNOWN; 413 MISC_keymap[i] = SDLK_UNKNOWN;
414 }
326 415
327 MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE; 416 MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
328 MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB; 417 MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
329 MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR; 418 MISC_keymap[Pk_Clear&0xFF] = SDLK_CLEAR;
330 MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN; 419 MISC_keymap[Pk_Return&0xFF] = SDLK_RETURN;
386 MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL; 475 MISC_keymap[Pk_Control_L&0xFF] = SDLK_LCTRL;
387 MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT; 476 MISC_keymap[Pk_Alt_R&0xFF] = SDLK_RALT;
388 MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT; 477 MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
389 MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA; 478 MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
390 MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA; 479 MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
391 MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER; /* Left "Windows" */ 480 MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;
392 MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER; /* Right "Windows" */ 481 MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;
393 MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */ 482 MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key */
394 483
395 MISC_keymap[Pk_Help&0xFF] = SDLK_HELP; 484 MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
396 MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT; 485 MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
397 MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK; 486 MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
398 MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU; 487 MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU; /* Windows "Menu" key */
399 MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU; /* Windows "Menu" key */ 488
489 MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER; /* Right "Windows" */
490
491 /* Left "Windows" key, but it can't be catched by application */
492 MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER;
400 } 493 }
401 494
402 static unsigned long cap; 495 static unsigned long cap;
403 496
404 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym) 497 SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym)
445 { 538 {
446 char utf8[MB_CUR_MAX]; 539 char utf8[MB_CUR_MAX];
447 int utf8len; 540 int utf8len;
448 wchar_t unicode; 541 wchar_t unicode;
449 542
450 utf8len = PhKeyToMb(utf8, key); 543 switch (keysym->scancode)
451 if (utf8len > 0) 544 {
452 { 545 case 0x01: keysym->unicode = 27;
453 utf8len = mbtowc(&unicode, utf8, utf8len); 546 break;
454 if (utf8len > 0) 547 default:
455 keysym->unicode = unicode; 548 utf8len = PhKeyToMb(utf8, key);
456 } 549 if (utf8len > 0)
550 {
551 utf8len = mbtowc(&unicode, utf8, utf8len);
552 if (utf8len > 0)
553 {
554 keysym->unicode = unicode;
555 }
556 }
557 break;
558 }
559
457 } 560 }
458 561
459 return (keysym); 562 return (keysym);
460 } 563 }
461 564