Start rumbling once a raw input controller has been correlated Fixes https://github.com/libsdl-org/SDL/issues/5351
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
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 6a285c3..3f3482b 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -886,17 +886,18 @@ SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 h
result = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble);
}
- /* Save the rumble value regardless of success, so we don't spam the driver */
- joystick->low_frequency_rumble = low_frequency_rumble;
- joystick->high_frequency_rumble = high_frequency_rumble;
-
- if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
- joystick->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
- if (!joystick->rumble_expiration) {
- joystick->rumble_expiration = 1;
+ if (result == 0) {
+ joystick->low_frequency_rumble = low_frequency_rumble;
+ joystick->high_frequency_rumble = high_frequency_rumble;
+
+ if ((low_frequency_rumble || high_frequency_rumble) && duration_ms) {
+ joystick->rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
+ if (!joystick->rumble_expiration) {
+ joystick->rumble_expiration = 1;
+ }
+ } else {
+ joystick->rumble_expiration = 0;
}
- } else {
- joystick->rumble_expiration = 0;
}
SDL_UnlockJoysticks();
@@ -920,17 +921,18 @@ SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
result = joystick->driver->RumbleTriggers(joystick, left_rumble, right_rumble);
}
- /* Save the rumble value regardless of success, so we don't spam the driver */
- joystick->left_trigger_rumble = left_rumble;
- joystick->right_trigger_rumble = right_rumble;
+ if (result == 0) {
+ joystick->left_trigger_rumble = left_rumble;
+ joystick->right_trigger_rumble = right_rumble;
- if ((left_rumble || right_rumble) && duration_ms) {
- joystick->trigger_rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
- if (!joystick->trigger_rumble_expiration) {
- joystick->trigger_rumble_expiration = 1;
+ if ((left_rumble || right_rumble) && duration_ms) {
+ joystick->trigger_rumble_expiration = SDL_GetTicks() + SDL_min(duration_ms, SDL_MAX_RUMBLE_DURATION_MS);
+ if (!joystick->trigger_rumble_expiration) {
+ joystick->trigger_rumble_expiration = 1;
+ }
+ } else {
+ joystick->trigger_rumble_expiration = 0;
}
- } else {
- joystick->trigger_rumble_expiration = 0;
}
SDL_UnlockJoysticks();
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 1fe99a4..32b6378 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -1295,6 +1295,13 @@ RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uin
}
#endif /* SDL_JOYSTICK_RAWINPUT_XINPUT */
+ if (!rumbled) {
+#if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT)
+ return SDL_SetError("Controller isn't correlated yet, try hitting a button first");
+#else
+ return SDL_Unsupported();
+#endif
+ }
return 0;
}