Reset mouse state when changing video modes
authorSam Lantinga <slouken@libsdl.org>
Tue, 20 Aug 2002 06:01:20 +0000
changeset 460a888b3ae31ff
parent 459 2a778055dbba
child 461 1d36f593078a
Reset mouse state when changing video modes
src/events/SDL_events_c.h
src/events/SDL_mouse.c
src/video/SDL_video.c
src/video/windx5/SDL_dx5events.c
     1.1 --- a/src/events/SDL_events_c.h	Tue Aug 20 05:59:31 2002 +0000
     1.2 +++ b/src/events/SDL_events_c.h	Tue Aug 20 06:01:20 2002 +0000
     1.3 @@ -63,7 +63,7 @@
     1.4  extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message);
     1.5  
     1.6  /* Used by the activity event handler to remove mouse focus */
     1.7 -extern void SDL_MouseFocus(int focus);
     1.8 +extern void SDL_ResetMouse(void);
     1.9  
    1.10  /* Used by the activity event handler to remove keyboard focus */
    1.11  extern void SDL_ResetKeyboard(void);
     2.1 --- a/src/events/SDL_mouse.c	Tue Aug 20 05:59:31 2002 +0000
     2.2 +++ b/src/events/SDL_mouse.c	Tue Aug 20 06:01:20 2002 +0000
     2.3 @@ -59,6 +59,17 @@
     2.4  	return(0);
     2.5  }
     2.6  
     2.7 +/* We lost the mouse, so post button up messages for all pressed buttons */
     2.8 +void SDL_ResetMouse(void)
     2.9 +{
    2.10 +	int i;
    2.11 +	for ( i = 0; i < sizeof(SDL_ButtonState)*8; ++i ) {
    2.12 +		if ( SDL_ButtonState & SDL_BUTTON(i) ) {
    2.13 +			SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
    2.14 +		}
    2.15 +	}
    2.16 +}
    2.17 +
    2.18  Uint8 SDL_GetMouseState (int *x, int *y)
    2.19  {
    2.20  	if ( x )
     3.1 --- a/src/video/SDL_video.c	Tue Aug 20 05:59:31 2002 +0000
     3.2 +++ b/src/video/SDL_video.c	Tue Aug 20 06:01:20 2002 +0000
     3.3 @@ -607,6 +607,7 @@
     3.4  
     3.5  	/* Reset the keyboard here so event callbacks can run */
     3.6  	SDL_ResetKeyboard();
     3.7 +	SDL_ResetMouse();
     3.8  
     3.9  	/* Clean up any previous video mode */
    3.10  	if ( SDL_PublicSurface != NULL ) {
     4.1 --- a/src/video/windx5/SDL_dx5events.c	Tue Aug 20 05:59:31 2002 +0000
     4.2 +++ b/src/video/windx5/SDL_dx5events.c	Tue Aug 20 06:01:20 2002 +0000
     4.3 @@ -221,33 +221,6 @@
     4.4  	return(0);
     4.5  }
     4.6  
     4.7 -/* Change cooperative level based on whether or not we are fullscreen */
     4.8 -void DX5_DInputReset(_THIS, int fullscreen)
     4.9 -{
    4.10 -	DWORD level;
    4.11 -	int i;
    4.12 -	HRESULT result;
    4.13 -
    4.14 -	for ( i=0; i<MAX_INPUTS; ++i ) {
    4.15 -		if ( SDL_DIdev[i] != NULL ) {
    4.16 -			if ( fullscreen ) {
    4.17 -				level = inputs[i].raw_level;
    4.18 -			} else {
    4.19 -				level = inputs[i].win_level;
    4.20 -			}
    4.21 -			IDirectInputDevice2_Unacquire(SDL_DIdev[i]);
    4.22 -			result = IDirectInputDevice2_SetCooperativeLevel(
    4.23 -					SDL_DIdev[i], SDL_Window, level);
    4.24 -			IDirectInputDevice2_Acquire(SDL_DIdev[i]);
    4.25 -			if ( result != DI_OK ) {
    4.26 -				SetDIerror(
    4.27 -			"DirectInputDevice::SetCooperativeLevel", result);
    4.28 -			}
    4.29 -		}
    4.30 -	}
    4.31 -	mouse_lost = 1;
    4.32 -}
    4.33 -
    4.34  /* Clean up DirectInput */
    4.35  static void DX5_DInputQuit(_THIS)
    4.36  {
    4.37 @@ -396,10 +369,10 @@
    4.38  					yrel = 0;
    4.39  				}
    4.40  				if((int)ptrbuf[i].dwData > 0)
    4.41 -					button = 4;
    4.42 +					button = SDL_BUTTON_WHEELUP;
    4.43  				else
    4.44 -					button = 5;
    4.45 -					posted = SDL_PrivateMouseButton(
    4.46 +					button = SDL_BUTTON_WHEELDOWN;
    4.47 +				posted = SDL_PrivateMouseButton(
    4.48  						SDL_PRESSED, button, 0, 0);
    4.49  				posted |= SDL_PrivateMouseButton(
    4.50  						SDL_RELEASED, button, 0, 0);
    4.51 @@ -543,7 +516,7 @@
    4.52     1 if there was input, 0 if there was no input, or -1 if the application has
    4.53     posted a quit message.
    4.54  */
    4.55 -static int DX5_CheckInput(_THIS, int timeout)
    4.56 +static int DX5_CheckInput(_THIS, int timeout, BOOL processInput)
    4.57  {
    4.58  	MSG msg;
    4.59  	int      i;
    4.60 @@ -602,7 +575,7 @@
    4.61  							evtbuf, &numevents, 0);
    4.62  		}
    4.63  		/* Handle the events */
    4.64 -		if ( result == DI_OK ) {
    4.65 +		if ( result == DI_OK && processInput ) {
    4.66  			/* Note: This can post multiple events to event queue
    4.67  			 */
    4.68  			(*SDL_DIfun[event])((int)numevents, evtbuf);
    4.69 @@ -623,10 +596,40 @@
    4.70  	return(0);
    4.71  }
    4.72  
    4.73 +/* Change cooperative level based on whether or not we are fullscreen */
    4.74 +void DX5_DInputReset(_THIS, int fullscreen)
    4.75 +{
    4.76 +	DWORD level;
    4.77 +	int i;
    4.78 +	HRESULT result;
    4.79 +
    4.80 +	for ( i=0; i<MAX_INPUTS; ++i ) {
    4.81 +		if ( SDL_DIdev[i] != NULL ) {
    4.82 +			if ( fullscreen ) {
    4.83 +				level = inputs[i].raw_level;
    4.84 +			} else {
    4.85 +				level = inputs[i].win_level;
    4.86 +			}
    4.87 +			IDirectInputDevice2_Unacquire(SDL_DIdev[i]);
    4.88 +			result = IDirectInputDevice2_SetCooperativeLevel(
    4.89 +					SDL_DIdev[i], SDL_Window, level);
    4.90 +			IDirectInputDevice2_Acquire(SDL_DIdev[i]);
    4.91 +			if ( result != DI_OK ) {
    4.92 +				SetDIerror(
    4.93 +			"DirectInputDevice::SetCooperativeLevel", result);
    4.94 +			}
    4.95 +		}
    4.96 +	}
    4.97 +	mouse_lost = 1;
    4.98 +
    4.99 +	/* Flush pending input */
   4.100 +	DX5_CheckInput(this, 0, FALSE);
   4.101 +}
   4.102 +
   4.103  void DX5_PumpEvents(_THIS)
   4.104  {
   4.105  	/* Wait for messages and DirectInput */
   4.106 -	while ( DX5_CheckInput(this, 0) > 0 ) {
   4.107 +	while ( DX5_CheckInput(this, 0, TRUE) > 0 ) {
   4.108  		/* Loop and check again */;
   4.109  	}
   4.110  }