comparison src/video/windx5/SDL_dx5events.c @ 4391:07b330419439 SDL-1.2

Fixed bug #849 some more: Tim Angus 2009-11-26 14:41:04 PST Fix to the cursor not being responsive when the app doesn't have SDL_APPINPUTFOCUS The problems with the directx driver are similar to the ones I introduced in the windib driver with r4478. Basically if the application did not have focus, the mouse position is not updated. It's not really that the mouse cursor was invisible, it's that it is stuck underneath another window where you can't see it. This behaviour predates my r4478 changes and is the reason I unwittingly broke the windib driver as I had been replicating the way the directx driver deals with focus. Prior to r4478 the directx driver could not be used in windowed mode, so the broken focusing would not have actually been observable. Anyway, the attached patch makes the directx driver behaves like the windib driver in terms of focus. Time for 1.2.15? ;) I've added an additional change of moving the calls to WIN_GrabInput that are made on WM_ACTIVATE messages so that they only occur when the state is SDL_APPINPUTFOCUS. When a fullscreen application is minimised using alt-tab, it still receives WM_ACTIVATE messages when other applications are selected. If WIN_GrabInput is called when the SDL application doesn't have input focus, bad things happen; it shouldn't be being called at all. I've also added a line to make sure that SDL_APPMOUSEFOCUS state is dropped when the application is minimised following an alt-tab.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Dec 2009 15:24:53 +0000
parents 6800e2560310
children 9afe12fb4c41
comparison
equal deleted inserted replaced
4390:725e506f6243 4391:07b330419439
147 #if DIRECTINPUT_VERSION >= 0x700 147 #if DIRECTINPUT_VERSION >= 0x700
148 &c_dfDIMouse2, 148 &c_dfDIMouse2,
149 #else 149 #else
150 &c_dfDIMouse, 150 &c_dfDIMouse,
151 #endif 151 #endif
152 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), 152 (DISCL_BACKGROUND|DISCL_NONEXCLUSIVE),
153 (DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_mouse }, 153 (DISCL_BACKGROUND|DISCL_NONEXCLUSIVE), handle_mouse },
154 { NULL, NULL, NULL, 0, 0, NULL } 154 { NULL, NULL, NULL, 0, 0, NULL }
155 }; 155 };
156 156
157 static int DX5_DInputInit(_THIS) 157 static int DX5_DInputInit(_THIS)
158 { 158 {
295 295
296 static void post_mouse_motion(int relative, Sint16 x, Sint16 y) 296 static void post_mouse_motion(int relative, Sint16 x, Sint16 y)
297 { 297 {
298 extern int mouse_relative; 298 extern int mouse_relative;
299 299
300 if ( (SDL_GetAppState() & (SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)) == 300 if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
301 (SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS) ) {
302 posted = SDL_PrivateMouseMotion( 301 posted = SDL_PrivateMouseMotion(
303 0, relative, x, y); 302 0, relative, x, y);
304 303
305 if ( !mouse_relative ) { 304 if ( !mouse_relative ) {
306 /* As DirectInput reads raw device coordinates, it has no notion of 305 /* As DirectInput reads raw device coordinates, it has no notion of
353 center.x = (SDL_VideoSurface->w/2); 352 center.x = (SDL_VideoSurface->w/2);
354 center.y = (SDL_VideoSurface->h/2); 353 center.y = (SDL_VideoSurface->h/2);
355 ClientToScreen(SDL_Window, &center); 354 ClientToScreen(SDL_Window, &center);
356 SetCursorPos(center.x, center.y); 355 SetCursorPos(center.x, center.y);
357 } 356 }
358 } else {
359 /* No window or mouse focus, control is lost */
360 mouse_lost = 1;
361 ClipCursor(NULL);
362 } 357 }
363 } 358 }
364 359
365 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf) 360 static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf)
366 { 361 {
371 DWORD timestamp = 0; 366 DWORD timestamp = 0;
372 367
373 /* Sanity check. Mailing list reports this being NULL unexpectedly. */ 368 /* Sanity check. Mailing list reports this being NULL unexpectedly. */
374 if (SDL_PublicSurface == NULL) { 369 if (SDL_PublicSurface == NULL) {
375 return; 370 return;
371 }
372
373 /* If mouse focus has been lost, make sure we release the cursor. */
374 if ( !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
375 mouse_lost = 1;
376 ClipCursor(NULL);
376 } 377 }
377 378
378 /* If the mouse was lost, regain some sense of mouse state */ 379 /* If the mouse was lost, regain some sense of mouse state */
379 if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { 380 if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
380 POINT mouse_pos; 381 POINT mouse_pos;
665 if ( posted ) { 666 if ( posted ) {
666 return(1); 667 return(1);
667 } 668 }
668 669
669 /* Pump the DirectInput flow */ 670 /* Pump the DirectInput flow */
670 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 671 if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
671 for ( i=0; i<MAX_INPUTS; ++i ) { 672 for ( i=0; i<MAX_INPUTS; ++i ) {
672 if ( SDL_DIdev[i] != NULL ) { 673 if ( SDL_DIdev[i] != NULL ) {
673 result = IDirectInputDevice2_Poll(SDL_DIdev[i]); 674 result = IDirectInputDevice2_Poll(SDL_DIdev[i]);
674 if ( (result == DIERR_INPUTLOST) || 675 if ( (result == DIERR_INPUTLOST) ||
675 (result == DIERR_NOTACQUIRED) ) { 676 (result == DIERR_NOTACQUIRED) ) {