From: Rémi Bernon rbernon@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53666 --- dlls/winebus.sys/bus_sdl.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 39432ce9f17..1af029bed65 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -137,6 +137,7 @@ struct sdl_device SDL_Joystick *sdl_joystick; SDL_GameController *sdl_controller; SDL_JoystickID id; + BOOL started;
DWORD effect_support; SDL_Haptic *sdl_haptic; @@ -439,8 +440,17 @@ static void sdl_device_destroy(struct unix_device *iface) static NTSTATUS sdl_device_start(struct unix_device *iface) { struct sdl_device *impl = impl_from_unix_device(iface); - if (impl->sdl_controller) return build_controller_report_descriptor(iface); - return build_joystick_report_descriptor(iface); + NTSTATUS status; + + pthread_mutex_lock(&sdl_cs); + + if (impl->sdl_controller) status = build_controller_report_descriptor(iface); + else status = build_joystick_report_descriptor(iface); + impl->started = !status; + + pthread_mutex_unlock(&sdl_cs); + + return status; }
static void sdl_device_stop(struct unix_device *iface) @@ -452,6 +462,7 @@ static void sdl_device_stop(struct unix_device *iface) if (impl->sdl_haptic) pSDL_HapticClose(impl->sdl_haptic);
pthread_mutex_lock(&sdl_cs); + impl->started = FALSE; list_remove(&impl->unix_device.entry); pthread_mutex_unlock(&sdl_cs); } @@ -1009,13 +1020,14 @@ static void process_device_event(SDL_Event *event) id = ((SDL_JoyDeviceEvent *)event)->which; impl = find_device_from_id(id); if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device); - else WARN("failed to find device with id %d\n", id); + else WARN("Failed to find device with id %d\n", id); } else if (event->type == SDL_JOYAXISMOTION && options.split_controllers) { id = event->jaxis.which; impl = find_device_from_id_and_axis(id, event->jaxis.axis); - if (!impl) WARN("failed to find device with id %d for axis %d\n", id, event->jaxis.axis); + if (!impl) WARN("Failed to find device with id %d for axis %d\n", id, event->jaxis.axis); + else if (!impl->started) WARN("Device %p with id %d is stopped, ignoring event %#x\n", impl, id, event->type); else { event->jaxis.axis -= impl->axis_offset; @@ -1026,15 +1038,17 @@ static void process_device_event(SDL_Event *event) { id = ((SDL_JoyButtonEvent *)event)->which; impl = find_device_from_id(id); - if (impl) set_report_from_joystick_event(impl, event); - else WARN("failed to find device with id %d\n", id); + if (!impl) WARN("Failed to find device with id %d\n", id); + else if (!impl->started) WARN("Device %p with id %d is stopped, ignoring event %#x\n", impl, id, event->type); + else set_report_from_joystick_event(impl, event); } else if (event->type >= SDL_CONTROLLERAXISMOTION && event->type <= SDL_CONTROLLERBUTTONUP) { id = ((SDL_ControllerButtonEvent *)event)->which; impl = find_device_from_id(id); - if (impl) set_report_from_controller_event(impl, event); - else WARN("failed to find device with id %d\n", id); + if (!impl) WARN("Failed to find device with id %d\n", id); + else if (!impl->started) WARN("Device %p with id %d is stopped, ignoring event %#x\n", impl, id, event->type); + else set_report_from_controller_event(impl, event); }
pthread_mutex_unlock(&sdl_cs);