Fixed SDL_HapticOpenFromJoystick() with DirectInput devices.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 17 Mar 2014 19:11:18 -0400
changeset 86294c01875a4620
parent 8628 b558f99d48f0
child 8630 e217ed463f25
Fixed SDL_HapticOpenFromJoystick() with DirectInput devices.
src/haptic/windows/SDL_syshaptic.c
src/joystick/windows/SDL_dxjoystick.c
     1.1 --- a/src/haptic/windows/SDL_syshaptic.c	Sat Mar 15 19:31:20 2014 -0700
     1.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Mon Mar 17 19:11:18 2014 -0400
     1.3 @@ -658,38 +658,47 @@
     1.4      haptic->hwdata->device = device8;
     1.5      haptic->hwdata->is_joystick = is_joystick;
     1.6  
     1.7 -    /* Grab it exclusively to use force feedback stuff. */
     1.8 -    ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
     1.9 -                                                  SDL_HelperWindow,
    1.10 -                                                  DISCL_EXCLUSIVE |
    1.11 -                                                  DISCL_BACKGROUND);
    1.12 -    if (FAILED(ret)) {
    1.13 -        DI_SetError("Setting cooperative level to exclusive", ret);
    1.14 -        goto acquire_err;
    1.15 -    }
    1.16 +    /* !!! FIXME: opening a haptic device here first will make an attempt to
    1.17 +       !!! FIXME:  SDL_JoystickOpen() that same device fail later, since we
    1.18 +       !!! FIXME:  have it open in exclusive mode. But this will allow
    1.19 +       !!! FIXME:  SDL_JoystickOpen() followed by SDL_HapticOpenFromJoystick()
    1.20 +       !!! FIXME:  to work, and that's probably the common case. Still,
    1.21 +       !!! FIXME:  ideally, We need to unify the opening code. */
    1.22  
    1.23 -    /* Set data format. */
    1.24 -    ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
    1.25 -                                            &c_dfDIJoystick2);
    1.26 -    if (FAILED(ret)) {
    1.27 -        DI_SetError("Setting data format", ret);
    1.28 -        goto acquire_err;
    1.29 -    }
    1.30 +    if (!is_joystick) {  /* if is_joystick, we already set this up elsewhere. */
    1.31 +        /* Grab it exclusively to use force feedback stuff. */
    1.32 +        ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
    1.33 +                                                      SDL_HelperWindow,
    1.34 +                                                      DISCL_EXCLUSIVE |
    1.35 +                                                      DISCL_BACKGROUND);
    1.36 +        if (FAILED(ret)) {
    1.37 +            DI_SetError("Setting cooperative level to exclusive", ret);
    1.38 +            goto acquire_err;
    1.39 +        }
    1.40  
    1.41 -    /* Get number of axes. */
    1.42 -    ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
    1.43 -                                          DI_DeviceObjectCallback,
    1.44 -                                          haptic, DIDFT_AXIS);
    1.45 -    if (FAILED(ret)) {
    1.46 -        DI_SetError("Getting device axes", ret);
    1.47 -        goto acquire_err;
    1.48 -    }
    1.49 +        /* Set data format. */
    1.50 +        ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
    1.51 +                                                &c_dfDIJoystick2);
    1.52 +        if (FAILED(ret)) {
    1.53 +            DI_SetError("Setting data format", ret);
    1.54 +            goto acquire_err;
    1.55 +        }
    1.56  
    1.57 -    /* Acquire the device. */
    1.58 -    ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
    1.59 -    if (FAILED(ret)) {
    1.60 -        DI_SetError("Acquiring DirectInput device", ret);
    1.61 -        goto acquire_err;
    1.62 +        /* Get number of axes. */
    1.63 +        ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
    1.64 +                                              DI_DeviceObjectCallback,
    1.65 +                                              haptic, DIDFT_AXIS);
    1.66 +        if (FAILED(ret)) {
    1.67 +            DI_SetError("Getting device axes", ret);
    1.68 +            goto acquire_err;
    1.69 +        }
    1.70 +
    1.71 +        /* Acquire the device. */
    1.72 +        ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
    1.73 +        if (FAILED(ret)) {
    1.74 +            DI_SetError("Acquiring DirectInput device", ret);
    1.75 +            goto acquire_err;
    1.76 +        }
    1.77      }
    1.78  
    1.79      /* Reset all actuators - just in case. */
     2.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Sat Mar 15 19:31:20 2014 -0700
     2.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Mar 17 19:11:18 2014 -0400
     2.3 @@ -1025,7 +1025,7 @@
     2.4          result =
     2.5              IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata->
     2.6                                                      InputDevice, SDL_HelperWindow,
     2.7 -                                                    DISCL_NONEXCLUSIVE |
     2.8 +                                                    DISCL_EXCLUSIVE |
     2.9                                                      DISCL_BACKGROUND);
    2.10          if (FAILED(result)) {
    2.11              return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);