Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Alfred Reynolds - add scanning of XInput for controller connectedness…
Browse files Browse the repository at this point in the history
… so we can detect when the wireless controller turns on and off, the usb side doesn't change when the controller goes away
  • Loading branch information
slouken committed Nov 27, 2012
1 parent fc01489 commit 0361c9a
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/joystick/windows/SDL_dxjoystick.c
Expand Up @@ -528,6 +528,9 @@ SDL_JoystickThread(void *_data)
HWND messageWindow = 0;
HDEVNOTIFY hNotify = 0;
DEV_BROADCAST_DEVICEINTERFACE dbh;
SDL_bool bOpenedXInputDevices[4];

SDL_memset( bOpenedXInputDevices, 0x0, sizeof(bOpenedXInputDevices) );

result = WIN_CoInitialize();

Expand Down Expand Up @@ -557,6 +560,9 @@ SDL_JoystickThread(void *_data)
while ( s_bJoystickThreadQuit == SDL_FALSE )
{
MSG messages;
Uint8 userId;
int nCurrentOpenedXInputDevices = 0;
int nNewOpenedXInputDevices = 0;
SDL_CondWaitTimeout( s_condJoystickThread, s_mutexJoyStickEnum, 300 );

while ( s_bJoystickThreadQuit == SDL_FALSE && PeekMessage(&messages, messageWindow, 0, 0, PM_NOREMOVE) )
Expand All @@ -567,7 +573,29 @@ SDL_JoystickThread(void *_data)
}
}

if ( s_pKnownJoystickGUIDs && s_bWindowsDeviceChanged )
// scan for any change in XInput devices
for ( userId = 0; userId < 4; userId++ )
{
XINPUT_CAPABILITIES capabilities;
DWORD result;

if ( bOpenedXInputDevices[userId] == SDL_TRUE )
nCurrentOpenedXInputDevices++;

result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
if ( result == ERROR_SUCCESS )
{
bOpenedXInputDevices[userId] = SDL_TRUE;
nNewOpenedXInputDevices++;
}
else
{
bOpenedXInputDevices[userId] = SDL_FALSE;
}
}


if ( s_pKnownJoystickGUIDs && ( s_bWindowsDeviceChanged || nNewOpenedXInputDevices != nCurrentOpenedXInputDevices ) )
{
SDL_Delay( 300 ); // wait for direct input to find out about this device

Expand Down

0 comments on commit 0361c9a

Please sign in to comment.