src/joystick/windows/SDL_xinputjoystick.c
changeset 12090 c3209fca27b2
parent 12088 399cc39583cc
child 12096 5b4b8242d21e
equal deleted inserted replaced
12089:d544367b1ef0 12090:c3209fca27b2
   268 #endif
   268 #endif
   269 
   269 
   270     WINDOWS_AddJoystickDevice(pNewJoystick);
   270     WINDOWS_AddJoystickDevice(pNewJoystick);
   271 }
   271 }
   272 
   272 
       
   273 static void
       
   274 DelXInputDevice(Uint8 userid)
       
   275 {
       
   276     if (s_arrXInputDevicePath[userid]) {
       
   277         SDL_free(s_arrXInputDevicePath[userid]);
       
   278         s_arrXInputDevicePath[userid] = NULL;
       
   279     }
       
   280 }
       
   281 
   273 void
   282 void
   274 SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
   283 SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
   275 {
   284 {
   276     int iuserid;
   285     int iuserid;
   277 
   286 
   283     for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
   292     for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
   284         const Uint8 userid = (Uint8)iuserid;
   293         const Uint8 userid = (Uint8)iuserid;
   285         XINPUT_CAPABILITIES capabilities;
   294         XINPUT_CAPABILITIES capabilities;
   286         if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
   295         if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
   287             AddXInputDevice(userid, capabilities.SubType, pContext);
   296             AddXInputDevice(userid, capabilities.SubType, pContext);
       
   297         } else {
       
   298             DelXInputDevice(userid);
   288         }
   299         }
   289     }
   300     }
   290 }
   301 }
   291 
   302 
   292 int
   303 int
   454     if (!XINPUTGETSTATE)
   465     if (!XINPUTGETSTATE)
   455         return;
   466         return;
   456 
   467 
   457     result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
   468     result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
   458     if (result == ERROR_DEVICE_NOT_CONNECTED) {
   469     if (result == ERROR_DEVICE_NOT_CONNECTED) {
   459         Uint8 userid = joystick->hwdata->userid;
       
   460 
       
   461         joystick->hwdata->send_remove_event = SDL_TRUE;
       
   462         joystick->hwdata->removed = SDL_TRUE;
       
   463         if (s_arrXInputDevicePath[userid]) {
       
   464             SDL_free(s_arrXInputDevicePath[userid]);
       
   465             s_arrXInputDevicePath[userid] = NULL;
       
   466         }
       
   467         return;
   470         return;
   468     }
   471     }
   469 
   472 
   470     SDL_zero(XBatteryInformation);
   473     SDL_zero(XBatteryInformation);
   471     if (XINPUTGETBATTERYINFORMATION) {
   474     if (XINPUTGETBATTERYINFORMATION) {