Fixed SDL_HapticOpenFromJoystick() with DirectInput devices.

This commit is contained in:
Ryan C. Gordon 2014-03-17 19:11:18 -04:00
parent cf3ff16e94
commit 7eaf899796
2 changed files with 39 additions and 30 deletions

View File

@ -658,38 +658,47 @@ SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic,
haptic->hwdata->device = device8; haptic->hwdata->device = device8;
haptic->hwdata->is_joystick = is_joystick; haptic->hwdata->is_joystick = is_joystick;
/* Grab it exclusively to use force feedback stuff. */ /* !!! FIXME: opening a haptic device here first will make an attempt to
ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, !!! FIXME: SDL_JoystickOpen() that same device fail later, since we
SDL_HelperWindow, !!! FIXME: have it open in exclusive mode. But this will allow
DISCL_EXCLUSIVE | !!! FIXME: SDL_JoystickOpen() followed by SDL_HapticOpenFromJoystick()
DISCL_BACKGROUND); !!! FIXME: to work, and that's probably the common case. Still,
if (FAILED(ret)) { !!! FIXME: ideally, We need to unify the opening code. */
DI_SetError("Setting cooperative level to exclusive", ret);
goto acquire_err;
}
/* Set data format. */ if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device, /* Grab it exclusively to use force feedback stuff. */
&c_dfDIJoystick2); ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
if (FAILED(ret)) { SDL_HelperWindow,
DI_SetError("Setting data format", ret); DISCL_EXCLUSIVE |
goto acquire_err; DISCL_BACKGROUND);
} if (FAILED(ret)) {
DI_SetError("Setting cooperative level to exclusive", ret);
goto acquire_err;
}
/* Get number of axes. */ /* Set data format. */
ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device, ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
DI_DeviceObjectCallback, &c_dfDIJoystick2);
haptic, DIDFT_AXIS); if (FAILED(ret)) {
if (FAILED(ret)) { DI_SetError("Setting data format", ret);
DI_SetError("Getting device axes", ret); goto acquire_err;
goto acquire_err; }
}
/* Acquire the device. */ /* Get number of axes. */
ret = IDirectInputDevice8_Acquire(haptic->hwdata->device); ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
if (FAILED(ret)) { DI_DeviceObjectCallback,
DI_SetError("Acquiring DirectInput device", ret); haptic, DIDFT_AXIS);
goto acquire_err; if (FAILED(ret)) {
DI_SetError("Getting device axes", ret);
goto acquire_err;
}
/* Acquire the device. */
ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
if (FAILED(ret)) {
DI_SetError("Acquiring DirectInput device", ret);
goto acquire_err;
}
} }
/* Reset all actuators - just in case. */ /* Reset all actuators - just in case. */

View File

@ -1025,7 +1025,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
result = result =
IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata-> IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata->
InputDevice, SDL_HelperWindow, InputDevice, SDL_HelperWindow,
DISCL_NONEXCLUSIVE | DISCL_EXCLUSIVE |
DISCL_BACKGROUND); DISCL_BACKGROUND);
if (FAILED(result)) { if (FAILED(result)) {
return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result); return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);