add hint to allow disabling the use of Xinput.
authorEdward Rudd <urkle@outoforder.cc>
Tue, 05 Mar 2013 18:01:59 -0500
changeset 6965ab4bb4e99961
parent 6964 c8aa24f05042
child 6966 090df160f6e0
add hint to allow disabling the use of Xinput.
include/SDL_hints.h
src/joystick/windows/SDL_dxjoystick.c
     1.1 --- a/include/SDL_hints.h	Tue Mar 05 17:59:36 2013 -0500
     1.2 +++ b/include/SDL_hints.h	Tue Mar 05 18:01:59 2013 -0500
     1.3 @@ -197,6 +197,15 @@
     1.4  
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable that lets you disable the detection and use of Xinput gamepad devices
     1.8 + *
     1.9 + *  The variable can be set to the following values:
    1.10 + *    "0"       - Disable XInput timer (only uses direct input)
    1.11 + *    "1"       - Enable XInput timer (the default)
    1.12 + */
    1.13 +#define SD_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED"
    1.14 +
    1.15 +/**
    1.16   *  \brief  A variable that lets you manually hint extra gamecontroller db entries
    1.17   *
    1.18   *  The variable expected newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h
     2.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Tue Mar 05 17:59:36 2013 -0500
     2.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Tue Mar 05 18:01:59 2013 -0500
     2.3 @@ -73,6 +73,7 @@
     2.4  static SDL_Thread *s_threadJoystick = NULL;
     2.5  static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
     2.6  static HANDLE s_pXInputDLL = 0;
     2.7 +static SDL_bool s_bXInputEnabled = SDL_TRUE;
     2.8  
     2.9  extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
    2.10                                         LPDIRECTINPUT * ppDI,
    2.11 @@ -364,6 +365,11 @@
    2.12  	HRESULT                 hr;
    2.13  	DWORD bCleanupCOM;
    2.14  
    2.15 +    if (!s_bXInputEnabled)
    2.16 +    {
    2.17 +        return SDL_FALSE;
    2.18 +    }
    2.19 +
    2.20  	SDL_memset( pDevices, 0x0, sizeof(pDevices) );
    2.21  
    2.22  	// CoInit if needed
    2.23 @@ -569,7 +575,7 @@
    2.24  			}
    2.25  		}
    2.26  
    2.27 -		if ( XINPUTGETCAPABILITIES )
    2.28 +		if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
    2.29  		{
    2.30  			// scan for any change in XInput devices
    2.31  			for ( userId = 0; userId < 4; userId++ )
    2.32 @@ -627,6 +633,10 @@
    2.33  {
    2.34      HRESULT result;
    2.35      HINSTANCE instance;
    2.36 +	const char *env = SDL_GetHint(SD_HINT_XINPUT_ENABLED);
    2.37 +	if (env && !SDL_atoi(env)) {
    2.38 +		s_bXInputEnabled = SDL_FALSE;
    2.39 +	}
    2.40  
    2.41      result = WIN_CoInitialize();
    2.42      if (FAILED(result)) {
    2.43 @@ -666,23 +676,25 @@
    2.44  	s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time
    2.45  	SDL_SYS_JoystickDetect();
    2.46  
    2.47 -	// try to load XInput support if available
    2.48 -	s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );
    2.49 -	if ( !s_pXInputDLL )
    2.50 -		s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
    2.51 -	if ( s_pXInputDLL )
    2.52 -	{
    2.53 -		// 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think...
    2.54 -		PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
    2.55 -		PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
    2.56 -		PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
    2.57 -		if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities )
    2.58 +    if (s_bXInputEnabled) {
    2.59 +		// try to load XInput support if available
    2.60 +		s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );
    2.61 +		if ( !s_pXInputDLL )
    2.62 +			s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
    2.63 +		if ( s_pXInputDLL )
    2.64  		{
    2.65 -			SDL_SYS_JoystickQuit();
    2.66 -			SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError());
    2.67 -			return (-1);
    2.68 +			// 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think...
    2.69 +			PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
    2.70 +			PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
    2.71 +			PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
    2.72 +			if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities )
    2.73 +			{
    2.74 +				SDL_SYS_JoystickQuit();
    2.75 +				SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError());
    2.76 +				return (-1);
    2.77 +			}
    2.78  		}
    2.79 -	}
    2.80 +    }
    2.81  
    2.82  
    2.83  	if ( !s_threadJoystick )
    2.84 @@ -934,6 +946,7 @@
    2.85  
    2.86      /* allocate memory for system specific hardware data */
    2.87  	joystick->instance_id = joystickdevice->nInstanceID;
    2.88 +    joystick->closed = 0;
    2.89      joystick->hwdata =
    2.90          (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
    2.91      if (joystick->hwdata == NULL) {
    2.92 @@ -959,7 +972,7 @@
    2.93  				userId++;
    2.94  		}
    2.95  
    2.96 -		if ( XINPUTGETCAPABILITIES )
    2.97 +		if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
    2.98  		{
    2.99  			result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
   2.100  			if ( result == ERROR_SUCCESS )