Fixed SDL_HapticOpenFromJoystick() with DirectInput devices.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c
index a4b5e42..1a59e1c 100644
--- a/src/haptic/windows/SDL_syshaptic.c
+++ b/src/haptic/windows/SDL_syshaptic.c
@@ -658,38 +658,47 @@ SDL_SYS_HapticOpenFromDevice8(SDL_Haptic * haptic,
haptic->hwdata->device = device8;
haptic->hwdata->is_joystick = is_joystick;
- /* Grab it exclusively to use force feedback stuff. */
- ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
- SDL_HelperWindow,
- DISCL_EXCLUSIVE |
- DISCL_BACKGROUND);
- if (FAILED(ret)) {
- DI_SetError("Setting cooperative level to exclusive", ret);
- goto acquire_err;
- }
+ /* !!! FIXME: opening a haptic device here first will make an attempt to
+ !!! FIXME: SDL_JoystickOpen() that same device fail later, since we
+ !!! FIXME: have it open in exclusive mode. But this will allow
+ !!! FIXME: SDL_JoystickOpen() followed by SDL_HapticOpenFromJoystick()
+ !!! FIXME: to work, and that's probably the common case. Still,
+ !!! FIXME: ideally, We need to unify the opening code. */
+
+ if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
+ /* Grab it exclusively to use force feedback stuff. */
+ ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
+ SDL_HelperWindow,
+ DISCL_EXCLUSIVE |
+ DISCL_BACKGROUND);
+ if (FAILED(ret)) {
+ DI_SetError("Setting cooperative level to exclusive", ret);
+ goto acquire_err;
+ }
- /* Set data format. */
- ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
- &c_dfDIJoystick2);
- if (FAILED(ret)) {
- DI_SetError("Setting data format", ret);
- goto acquire_err;
- }
+ /* Set data format. */
+ ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
+ &c_dfDIJoystick2);
+ if (FAILED(ret)) {
+ DI_SetError("Setting data format", ret);
+ goto acquire_err;
+ }
- /* Get number of axes. */
- ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
- DI_DeviceObjectCallback,
- haptic, DIDFT_AXIS);
- if (FAILED(ret)) {
- DI_SetError("Getting device axes", ret);
- goto acquire_err;
- }
+ /* Get number of axes. */
+ ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
+ DI_DeviceObjectCallback,
+ haptic, DIDFT_AXIS);
+ 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;
+ /* 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. */
diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c
index 3c00974..68291ff 100644
--- a/src/joystick/windows/SDL_dxjoystick.c
+++ b/src/joystick/windows/SDL_dxjoystick.c
@@ -1025,7 +1025,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
result =
IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata->
InputDevice, SDL_HelperWindow,
- DISCL_NONEXCLUSIVE |
+ DISCL_EXCLUSIVE |
DISCL_BACKGROUND);
if (FAILED(result)) {
return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);