src/haptic/windows/SDL_syshaptic.c
changeset 8688 1543a7183f88
parent 8634 a60eaa04d3fb
equal deleted inserted replaced
8687:1d2ca48523a7 8688:1543a7183f88
   319 
   319 
   320 int
   320 int
   321 XInputHaptic_MaybeAddDevice(const DWORD dwUserid)
   321 XInputHaptic_MaybeAddDevice(const DWORD dwUserid)
   322 {
   322 {
   323     const Uint8 userid = (Uint8) dwUserid;
   323     const Uint8 userid = (Uint8) dwUserid;
   324     XINPUT_CAPABILITIES caps;
       
   325     const SDL_bool bIs14OrLater = (SDL_XInputVersion >= ((1<<16)|4));
       
   326     SDL_hapticlist_item *item;
   324     SDL_hapticlist_item *item;
       
   325     XINPUT_VIBRATION state;
   327 
   326 
   328     if ((!loaded_xinput) || (dwUserid >= SDL_XINPUT_MAX_DEVICES)) {
   327     if ((!loaded_xinput) || (dwUserid >= SDL_XINPUT_MAX_DEVICES)) {
   329         return -1;
   328         return -1;
   330     }
   329     }
   331 
   330 
   334         if ((item->bXInputHaptic) && (item->userid == userid)) {
   333         if ((item->bXInputHaptic) && (item->userid == userid)) {
   335             return -1;  /* Already added */
   334             return -1;  /* Already added */
   336         }
   335         }
   337     }
   336     }
   338 
   337 
   339     if (XINPUTGETCAPABILITIES(dwUserid, XINPUT_FLAG_GAMEPAD, &caps) != ERROR_SUCCESS) {
   338     SDL_zero(state);
   340         return -1;  /* maybe controller isn't plugged in. */
   339     if (XINPUTSETSTATE(dwUserid, &state) != ERROR_SUCCESS) {
   341     }
       
   342 
       
   343     /* XInput < 1.4 is probably only for original XBox360 controllers,
       
   344         which don't offer the flag, and always have force feedback */
       
   345     if ( (bIs14OrLater) && ((caps.Flags & XINPUT_CAPS_FFB_SUPPORTED) == 0) ) {
       
   346         return -1;  /* no force feedback on this device. */
   340         return -1;  /* no force feedback on this device. */
   347     }
   341     }
   348 
   342 
   349     item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
   343     item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
   350     if (item == NULL) {
   344     if (item == NULL) {