Fixed bug #849 some more: SDL-1.2
authorSam Lantinga
Fri, 11 Dec 2009 15:24:53 +0000
branchSDL-1.2
changeset 439107b330419439
parent 4390 725e506f6243
child 4392 2b8c1aea633b
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.
src/video/wincommon/SDL_sysevents.c
src/video/windx5/SDL_dx5events.c
     1.1 --- a/src/video/wincommon/SDL_sysevents.c	Fri Dec 11 15:14:13 2009 +0000
     1.2 +++ b/src/video/wincommon/SDL_sysevents.c	Fri Dec 11 15:24:53 2009 +0000
     1.3 @@ -316,10 +316,10 @@
     1.4  			if ( active ) {
     1.5  				/* Gain the following states */
     1.6  				appstate = SDL_APPACTIVE|SDL_APPINPUTFOCUS;
     1.7 -				if ( this->input_grab != SDL_GRAB_OFF ) {
     1.8 -					WIN_GrabInput(this, SDL_GRAB_ON);
     1.9 -				}
    1.10 -				if ( !(SDL_GetAppState()&SDL_APPINPUTFOCUS) ) {
    1.11 +				if ( !(SDL_GetAppState() & SDL_APPINPUTFOCUS) ) {
    1.12 +					if ( this->input_grab != SDL_GRAB_OFF ) {
    1.13 +						WIN_GrabInput(this, SDL_GRAB_ON);
    1.14 +					}
    1.15  					if ( ! DDRAW_FULLSCREEN() ) {
    1.16  						DIB_SwapGamma(this);
    1.17  					}
    1.18 @@ -344,14 +344,16 @@
    1.19  				if ( minimized ) {
    1.20  					appstate |= SDL_APPACTIVE;
    1.21  				}
    1.22 -				if ( this->input_grab != SDL_GRAB_OFF ) {
    1.23 -					WIN_GrabInput(this, SDL_GRAB_OFF);
    1.24 -				}
    1.25 +
    1.26  				if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
    1.27 +					if ( this->input_grab != SDL_GRAB_OFF ) {
    1.28 +						WIN_GrabInput(this, SDL_GRAB_OFF);
    1.29 +					}
    1.30  					if ( ! DDRAW_FULLSCREEN() ) {
    1.31  						DIB_SwapGamma(this);
    1.32  					}
    1.33  					if ( WINDIB_FULLSCREEN() ) {
    1.34 +						appstate |= SDL_APPMOUSEFOCUS;
    1.35  						SDL_RestoreDesktopMode();
    1.36  #if defined(_WIN32_WCE)
    1.37  						LoadAygshell();
    1.38 @@ -372,8 +374,7 @@
    1.39  		case WM_MOUSEMOVE: {
    1.40  
    1.41  #ifdef WM_MOUSELEAVE
    1.42 -			/* No need to handle SDL_APPMOUSEFOCUS when fullscreen */
    1.43 -			if ( SDL_VideoSurface && !FULLSCREEN() ) {
    1.44 +			if ( SDL_VideoSurface ) {
    1.45  				/* mouse has entered the window */
    1.46  
    1.47  				if ( !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    1.48 @@ -398,11 +399,8 @@
    1.49  #ifdef WM_MOUSELEAVE
    1.50  		case WM_MOUSELEAVE: {
    1.51  
    1.52 -			/* No need to handle SDL_APPMOUSEFOCUS when fullscreen */
    1.53 -			if ( SDL_VideoSurface && !FULLSCREEN() ) {
    1.54 +			if ( SDL_VideoSurface ) {
    1.55  				/* mouse has left the window */
    1.56 -				/* or */
    1.57 -				/* Elvis has left the building! */
    1.58  				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
    1.59  			}
    1.60  		}
     2.1 --- a/src/video/windx5/SDL_dx5events.c	Fri Dec 11 15:14:13 2009 +0000
     2.2 +++ b/src/video/windx5/SDL_dx5events.c	Fri Dec 11 15:24:53 2009 +0000
     2.3 @@ -149,8 +149,8 @@
     2.4  #else
     2.5  		&c_dfDIMouse,
     2.6  #endif
     2.7 -		(DISCL_FOREGROUND|DISCL_NONEXCLUSIVE),
     2.8 -		(DISCL_FOREGROUND|DISCL_NONEXCLUSIVE), handle_mouse },
     2.9 +		(DISCL_BACKGROUND|DISCL_NONEXCLUSIVE),
    2.10 +		(DISCL_BACKGROUND|DISCL_NONEXCLUSIVE), handle_mouse },
    2.11  	{ NULL, NULL, NULL, 0, 0, NULL }
    2.12  };
    2.13  	
    2.14 @@ -297,8 +297,7 @@
    2.15  {
    2.16  	extern int mouse_relative;
    2.17  
    2.18 -	if ( (SDL_GetAppState() & (SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS)) ==
    2.19 -		(SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS) ) {
    2.20 +	if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
    2.21  		posted = SDL_PrivateMouseMotion(
    2.22  			0, relative, x, y);
    2.23  
    2.24 @@ -355,10 +354,6 @@
    2.25  			ClientToScreen(SDL_Window, &center);
    2.26  			SetCursorPos(center.x, center.y);
    2.27  		}
    2.28 -	} else {
    2.29 -		/* No window or mouse focus, control is lost */
    2.30 -		mouse_lost = 1;
    2.31 -		ClipCursor(NULL);
    2.32  	}
    2.33  }
    2.34  
    2.35 @@ -375,6 +370,12 @@
    2.36  		return;
    2.37  	}
    2.38  
    2.39 +	/* If mouse focus has been lost, make sure we release the cursor. */
    2.40 +	if ( !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    2.41 +		mouse_lost = 1;
    2.42 +		ClipCursor(NULL);
    2.43 +	}
    2.44 +
    2.45  	/* If the mouse was lost, regain some sense of mouse state */
    2.46  	if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    2.47  		POINT mouse_pos;
    2.48 @@ -667,7 +668,7 @@
    2.49  	}
    2.50  
    2.51  	/* Pump the DirectInput flow */
    2.52 -	if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
    2.53 +	if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
    2.54  		for ( i=0; i<MAX_INPUTS; ++i ) {
    2.55  			if ( SDL_DIdev[i] != NULL ) {
    2.56  				result = IDirectInputDevice2_Poll(SDL_DIdev[i]);