Fixed SDL_HapticOpenFromJoystick() with DirectInput devices.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 17 Mar 2014 19:11:18 -0400
changeset 8629 4c01875a4620
parent 8628 b558f99d48f0
child 8630 e217ed463f25
Fixed SDL_HapticOpenFromJoystick() with DirectInput devices.
src/haptic/windows/SDL_syshaptic.c
src/joystick/windows/SDL_dxjoystick.c
--- a/src/haptic/windows/SDL_syshaptic.c	Sat Mar 15 19:31:20 2014 -0700
+++ b/src/haptic/windows/SDL_syshaptic.c	Mon Mar 17 19:11:18 2014 -0400
@@ -658,38 +658,47 @@
     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. */
--- a/src/joystick/windows/SDL_dxjoystick.c	Sat Mar 15 19:31:20 2014 -0700
+++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Mar 17 19:11:18 2014 -0400
@@ -1025,7 +1025,7 @@
         result =
             IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata->
                                                     InputDevice, SDL_HelperWindow,
-                                                    DISCL_NONEXCLUSIVE |
+                                                    DISCL_EXCLUSIVE |
                                                     DISCL_BACKGROUND);
         if (FAILED(result)) {
             return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);