Alfred Reynolds - add scanning of XInput for controller connectedness so we can detect when the wireless controller turns on and off, the usb side doesn't change when the controller goes away
authorSam Lantinga
Tue, 27 Nov 2012 09:19:09 -0800
changeset 6710e650705e2c1d
parent 6709 3b43d3a9b7d5
child 6711 e6355923901d
Alfred Reynolds - add scanning of XInput for controller connectedness so we can detect when the wireless controller turns on and off, the usb side doesn't change when the controller goes away
src/joystick/windows/SDL_dxjoystick.c
     1.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Tue Nov 27 01:09:18 2012 -0800
     1.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Tue Nov 27 09:19:09 2012 -0800
     1.3 @@ -528,6 +528,9 @@
     1.4  	HWND messageWindow = 0;
     1.5  	HDEVNOTIFY hNotify = 0;
     1.6  	DEV_BROADCAST_DEVICEINTERFACE dbh;
     1.7 +	SDL_bool bOpenedXInputDevices[4];
     1.8 +
     1.9 +	SDL_memset( bOpenedXInputDevices, 0x0, sizeof(bOpenedXInputDevices) );
    1.10  
    1.11  	result = WIN_CoInitialize();
    1.12  
    1.13 @@ -557,6 +560,9 @@
    1.14  	while ( s_bJoystickThreadQuit == SDL_FALSE )
    1.15  	{
    1.16  		MSG messages;
    1.17 +		Uint8 userId;
    1.18 +		int nCurrentOpenedXInputDevices = 0;
    1.19 +		int nNewOpenedXInputDevices = 0;
    1.20  		SDL_CondWaitTimeout( s_condJoystickThread, s_mutexJoyStickEnum, 300 );
    1.21  
    1.22  		while ( s_bJoystickThreadQuit == SDL_FALSE && PeekMessage(&messages, messageWindow, 0, 0, PM_NOREMOVE) )
    1.23 @@ -567,7 +573,29 @@
    1.24  			}
    1.25  		}
    1.26  
    1.27 -		if ( s_pKnownJoystickGUIDs && s_bWindowsDeviceChanged )
    1.28 +		// scan for any change in XInput devices
    1.29 +		for ( userId = 0; userId < 4; userId++ )
    1.30 +		{
    1.31 +			XINPUT_CAPABILITIES	capabilities;
    1.32 +			DWORD result;
    1.33 +
    1.34 +			if ( bOpenedXInputDevices[userId] == SDL_TRUE )
    1.35 +				nCurrentOpenedXInputDevices++;
    1.36 +
    1.37 +			result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
    1.38 +			if ( result == ERROR_SUCCESS )
    1.39 +			{
    1.40 +				bOpenedXInputDevices[userId] = SDL_TRUE;
    1.41 +				nNewOpenedXInputDevices++;
    1.42 +			}
    1.43 +			else
    1.44 +			{
    1.45 +				bOpenedXInputDevices[userId] = SDL_FALSE;
    1.46 +			}
    1.47 +		}
    1.48 +
    1.49 +
    1.50 +		if ( s_pKnownJoystickGUIDs && ( s_bWindowsDeviceChanged || nNewOpenedXInputDevices != nCurrentOpenedXInputDevices ) )
    1.51  		{
    1.52  			SDL_Delay( 300 ); // wait for direct input to find out about this device
    1.53