comparison src/video/photon/SDL_ph_events.c @ 283:3d8b6b9f1e18

Date: Mon, 18 Feb 2002 16:46:59 +1200 From: Julian Kinraid <jkinraid@clear.net.nz> Subject: Patches for photon port of SDL Hi, A couple more patches for photon and the nto audio. Adds mouse grabbing support, fixed cursor images, unicode keyboard events (though no unicode data on kye release, is that a problem?), hopefully fixing some audio lag problems, and a few other fixes. Thanks, Julian Kinraid
author Sam Lantinga <slouken@libsdl.org>
date Wed, 20 Feb 2002 01:05:51 +0000
parents c6abdda2f666
children f6ffac90895c
comparison
equal deleted inserted replaced
282:b42d80e73896 283:3d8b6b9f1e18
53 53
54 /* Check to see if this is a repeated key. 54 /* Check to see if this is a repeated key.
55 (idea shamelessly lifted from GII -- thanks guys! :) 55 (idea shamelessly lifted from GII -- thanks guys! :)
56 */ 56 */
57 57
58 /* 58 #if 0
59 static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent) 59 static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
60 { 60 {
61 // PhEvent_t* peekevent; 61 // PhEvent_t* peekevent;
62 PhKeyEvent_t* keyEvent; 62 PhKeyEvent_t* keyEvent;
63 int repeated; 63 int repeated;
87 87
88 default: // no events pending 88 default: // no events pending
89 } 89 }
90 return(repeated); 90 return(repeated);
91 } 91 }
92 92 #endif
93 */ 93
94 94 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
95 /* Note: The X server buffers and accumulates mouse motion events, so 95 {
96 the motion event generated by the warp may not appear exactly as we 96 PhPointerEvent_t *pointer = PhGetData( winEvent );
97 expect it to. We work around this (and improve performance) by only 97 PhRect_t *rect = PhGetRects( winEvent );
98 warping the pointer when it reaches the edge, and then wait for it. 98
99 */ 99 int centre_x, centre_y;
100 /* 100 int dx, dy, abs_x, abs_y;
101 #define MOUSE_FUDGE_FACTOR 8
102
103 static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
104 {
105 int w, h, i;
106 int deltax, deltay;
107 int posted; 101 int posted;
108 102
109 w = SDL_VideoSurface->w; 103 centre_x = SDL_VideoSurface->w / 2;
110 h = SDL_VideoSurface->h; 104 centre_y = SDL_VideoSurface->h / 2;
111 deltax = xevent->xmotion.x - mouse_last.x; 105
112 deltay = xevent->xmotion.y - mouse_last.y; 106 dx = rect->ul.x - centre_x;
113 #ifdef DEBUG_MOTION 107 dy = rect->ul.y - centre_y;
114 printf("Warped mouse motion: %d,%d\n", deltax, deltay); 108
115 #endif 109 posted = SDL_PrivateMouseMotion( 0, 1, dx, dy );
116 mouse_last.x = xevent->xmotion.x; 110
117 mouse_last.y = xevent->xmotion.y; 111 /* Move mouse cursor to middle of the window */
118 posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay); 112 PtGetAbsPosition( window, &abs_x, &abs_y );
119 113 PhMoveCursorAbs( PhInputGroup(NULL),
120 if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) || 114 abs_x + centre_x,
121 (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) || 115 abs_y + centre_y );
122 (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) || 116
123 (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
124 // Get the events that have accumulated
125 /* while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
126 deltax = xevent->xmotion.x - mouse_last.x;
127 deltay = xevent->xmotion.y - mouse_last.y;
128 #ifdef DEBUG_MOTION
129 printf("Extra mouse motion: %d,%d\n", deltax, deltay);
130 #endif
131 mouse_last.x = xevent->xmotion.x;
132 mouse_last.y = xevent->xmotion.y;
133 posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
134 }
135 mouse_last.x = w/2;
136 mouse_last.y = h/2;
137 XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
138 mouse_last.x, mouse_last.y);
139 for ( i=0; i<10; ++i ) {
140 XMaskEvent(SDL_Display, PointerMotionMask, xevent);
141 if ( (xevent->xmotion.x >
142 (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
143 (xevent->xmotion.x <
144 (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
145 (xevent->xmotion.y >
146 (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
147 (xevent->xmotion.y <
148 (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
149 break;
150 }
151 #ifdef DEBUG_XEVENTS
152 printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
153 #endif
154 }
155 #ifdef DEBUG_XEVENTS
156 if ( i == 10 ) {
157 printf("Warning: didn't detect mouse warp motion\n");
158 }
159 #endif
160 }
161 return(posted); 117 return(posted);
162 } 118 }
163 */
164 119
165 /* Control which motion flags the window has set, a flags value of -1 sets 120 /* Control which motion flags the window has set, a flags value of -1 sets
166 * MOTION_BUTTON and MOTION_NOBUTTON */ 121 * MOTION_BUTTON and MOTION_NOBUTTON */
167 122
168 static void set_motion_sensitivity(_THIS, unsigned int flags) 123 static void set_motion_sensitivity(_THIS, unsigned int flags)
224 case Ph_EV_PTR_MOTION_NOBUTTON: 179 case Ph_EV_PTR_MOTION_NOBUTTON:
225 { 180 {
226 if ( SDL_VideoSurface ) { 181 if ( SDL_VideoSurface ) {
227 pointerEvent = PhGetData( event ); 182 pointerEvent = PhGetData( event );
228 rect = PhGetRects( event ); 183 rect = PhGetRects( event );
229 posted = SDL_PrivateMouseMotion(0, 0, 184 if( mouse_relative )
230 rect->ul.x, rect->ul.y); 185 {
186 posted = ph_WarpedMotion(this, event);
187 }
188 else
189 posted = SDL_PrivateMouseMotion(0, 0,
190 rect->ul.x, rect->ul.y);
231 } 191 }
232 } 192 }
233 break; 193 break;
234 194
235 case Ph_EV_BUT_PRESS: 195 case Ph_EV_BUT_PRESS:
289 else if ((winEvent->event_f==Ph_WM_FOCUS)&& 249 else if ((winEvent->event_f==Ph_WM_FOCUS)&&
290 (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) 250 (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
291 { 251 {
292 set_motion_sensitivity(this, -1); 252 set_motion_sensitivity(this, -1);
293 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 253 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
294 254 #if 0
295 /* Queue entry into fullscreen mode */ 255 /* Queue entry into fullscreen mode */
296 switch_waiting = 0x01 | SDL_FULLSCREEN; 256 switch_waiting = 0x01 | SDL_FULLSCREEN;
297 switch_time = SDL_GetTicks() + 1500; 257 switch_time = SDL_GetTicks() + 1500;
258 #endif
298 } 259 }
299 260
300 /* request to quit */ 261 /* request to quit */
301 else if (winEvent->event_f==Ph_WM_CLOSE) 262 else if (winEvent->event_f==Ph_WM_CLOSE)
302 { 263 {
303 posted = SDL_PrivateQuit(); 264 posted = SDL_PrivateQuit();
265 }
266 else if (winEvent->event_f==Ph_WM_RESIZE)
267 {
268 PhDim_t *size;
269
270 PtGetResource( window, Pt_ARG_DIM, &size, 0 );
271 SDL_PrivateResize(size->w,size->h);
304 } 272 }
305 } 273 }
306 break; 274 break;
307 275
308 /* window has been resized, moved or removed */ 276 /* window has been resized, moved or removed */
443 } 411 }
444 if ( switch_waiting ) { 412 if ( switch_waiting ) {
445 Uint32 now; 413 Uint32 now;
446 414
447 now = SDL_GetTicks(); 415 now = SDL_GetTicks();
416 #if 0
448 if ( pending || !SDL_VideoSurface ) { 417 if ( pending || !SDL_VideoSurface ) {
449 /* Try again later... */ 418 /* Try again later... */
450 if ( switch_waiting & SDL_FULLSCREEN ) { 419 if ( switch_waiting & SDL_FULLSCREEN ) {
451 switch_time = now + 1500; 420 switch_time = now + 1500;
452 } else { 421 } else {
471 } else { 440 } else {
472 ph_GrabInputNoLock(this, SDL_GRAB_OFF); 441 ph_GrabInputNoLock(this, SDL_GRAB_OFF);
473 } 442 }
474 */ 443 */
475 } 444 }
445 #endif
476 } 446 }
477 } 447 }
478 448
479 void ph_InitKeymap(void) 449 void ph_InitKeymap(void)
480 { 450 {
571 /* 541 /*
572 'sym' is set to the value of the key with modifiers applied to it. 542 'sym' is set to the value of the key with modifiers applied to it.
573 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags. 543 This member is valid only if Pk_KF_Sym_Valid is set in the key_flags.
574 We will assume it is valid. 544 We will assume it is valid.
575 */ 545 */
546 /* FIXME: This needs to check whether the cap & scancode is valid */
576 cap = key->key_cap; 547 cap = key->key_cap;
577 switch (cap>>8) { 548 switch (cap>>8) {
578 case 0x00: /* Latin 1 */ 549 case 0x00: /* Latin 1 */
579 case 0x01: /* Latin 2 */ 550 case 0x01: /* Latin 2 */
580 case 0x02: /* Latin 3 */ 551 case 0x02: /* Latin 3 */
597 // break; 568 // break;
598 case 0xF0: 569 case 0xF0:
599 keysym->sym = MISC_keymap[cap&0xFF]; 570 keysym->sym = MISC_keymap[cap&0xFF];
600 break; 571 break;
601 default: 572 default:
602 fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); 573 /* fprintf(stderr,"Photon: Unknown key_cap, cap = 0x%.4x\n", (unsigned int)cap); */
574 keysym->sym = SDLK_UNKNOWN;
603 break; 575 break;
604 } 576 }
605 keysym->scancode = key->key_scan; 577 keysym->scancode = key->key_scan;
578 keysym->unicode = 0;
579 if( SDL_TranslateUNICODE )
580 {
581 char utf8[MB_CUR_MAX];
582 int utf8len;
583 wchar_t unicode;
584
585 utf8len = PhKeyToMb( utf8, key );
586 if( utf8len > 0 )
587 {
588 utf8len = mbtowc( &unicode, utf8, utf8len );
589 if( utf8len > 0)
590 keysym->unicode = unicode;
591 }
592 }
593
606 return (keysym); 594 return (keysym);
607 } 595 }
608 596
609 void ph_InitOSKeymap(_THIS) 597 void ph_InitOSKeymap(_THIS)
610 { 598 {