From b3faad66cf2973adc769e76b8022de26090d9756 Mon Sep 17 00:00:00 2001
From: Ivo Ivanov <logos128@gmail.com>
Date: Thu, 9 Dec 2021 14:44:12 +0100
Subject: [PATCH] winebus.sys: Use SDL_HAPTIC_INFINITY for the infinity
 durations in the SDL backend.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51922
Signed-off-by: Ivo Ivanov <logos128@gmail.com>
Signed-off-by: RĂ©mi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 dlls/winebus.sys/bus_sdl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c
index 76d90ab7912..37d75d0bc95 100644
--- a/dlls/winebus.sys/bus_sdl.c
+++ b/dlls/winebus.sys/bus_sdl.c
@@ -515,7 +515,7 @@ static NTSTATUS sdl_device_physical_effect_control(struct unix_device *iface, BY
         pSDL_HapticStopAll(impl->sdl_haptic);
         /* fallthrough */
     case PID_USAGE_OP_EFFECT_START:
-        pSDL_HapticRunEffect(impl->sdl_haptic, id, iterations);
+        pSDL_HapticRunEffect(impl->sdl_haptic, id, (iterations == 0xff ? SDL_HAPTIC_INFINITY : iterations));
         break;
     case PID_USAGE_OP_EFFECT_STOP:
         pSDL_HapticStopEffect(impl->sdl_haptic, id);
@@ -592,7 +592,7 @@ static NTSTATUS sdl_device_physical_effect_update(struct unix_device *iface, BYT
     case PID_USAGE_ET_TRIANGLE:
     case PID_USAGE_ET_SAWTOOTH_UP:
     case PID_USAGE_ET_SAWTOOTH_DOWN:
-        effect.periodic.length = params->duration;
+        effect.periodic.length = (params->duration == 0xffff ? SDL_HAPTIC_INFINITY : params->duration);
         effect.periodic.delay = params->start_delay;
         effect.periodic.button = params->trigger_button;
         effect.periodic.interval = params->trigger_repeat_interval;
@@ -613,7 +613,7 @@ static NTSTATUS sdl_device_physical_effect_update(struct unix_device *iface, BYT
     case PID_USAGE_ET_DAMPER:
     case PID_USAGE_ET_INERTIA:
     case PID_USAGE_ET_FRICTION:
-        effect.condition.length = params->duration;
+        effect.condition.length = (params->duration == 0xffff ? SDL_HAPTIC_INFINITY : params->duration);
         effect.condition.delay = params->start_delay;
         effect.condition.button = params->trigger_button;
         effect.condition.interval = params->trigger_repeat_interval;
@@ -641,7 +641,7 @@ static NTSTATUS sdl_device_physical_effect_update(struct unix_device *iface, BYT
         break;
 
     case PID_USAGE_ET_CONSTANT_FORCE:
-        effect.constant.length = params->duration;
+        effect.constant.length = (params->duration == 0xffff ? SDL_HAPTIC_INFINITY : params->duration);
         effect.constant.delay = params->start_delay;
         effect.constant.button = params->trigger_button;
         effect.constant.interval = params->trigger_repeat_interval;
@@ -655,6 +655,8 @@ static NTSTATUS sdl_device_physical_effect_update(struct unix_device *iface, BYT
         effect.constant.fade_level = params->envelope.fade_level;
         break;
 
+    /* According to the SDL documentation, ramp effect doesn't
+     * support SDL_HAPTIC_INFINITY. */
     case PID_USAGE_ET_RAMP:
         effect.ramp.length = params->duration;
         effect.ramp.delay = params->start_delay;