Commit d3bca134 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

winebus.sys: Ignore SDL events for devices which aren't started.

parent 764f91e5
...@@ -137,6 +137,7 @@ struct sdl_device ...@@ -137,6 +137,7 @@ struct sdl_device
SDL_Joystick *sdl_joystick; SDL_Joystick *sdl_joystick;
SDL_GameController *sdl_controller; SDL_GameController *sdl_controller;
SDL_JoystickID id; SDL_JoystickID id;
BOOL started;
DWORD effect_support; DWORD effect_support;
SDL_Haptic *sdl_haptic; SDL_Haptic *sdl_haptic;
...@@ -439,8 +440,17 @@ static void sdl_device_destroy(struct unix_device *iface) ...@@ -439,8 +440,17 @@ static void sdl_device_destroy(struct unix_device *iface)
static NTSTATUS sdl_device_start(struct unix_device *iface) static NTSTATUS sdl_device_start(struct unix_device *iface)
{ {
struct sdl_device *impl = impl_from_unix_device(iface); struct sdl_device *impl = impl_from_unix_device(iface);
if (impl->sdl_controller) return build_controller_report_descriptor(iface); NTSTATUS status;
return build_joystick_report_descriptor(iface);
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) static void sdl_device_stop(struct unix_device *iface)
...@@ -452,6 +462,7 @@ 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); if (impl->sdl_haptic) pSDL_HapticClose(impl->sdl_haptic);
pthread_mutex_lock(&sdl_cs); pthread_mutex_lock(&sdl_cs);
impl->started = FALSE;
list_remove(&impl->unix_device.entry); list_remove(&impl->unix_device.entry);
pthread_mutex_unlock(&sdl_cs); pthread_mutex_unlock(&sdl_cs);
} }
...@@ -1009,13 +1020,14 @@ static void process_device_event(SDL_Event *event) ...@@ -1009,13 +1020,14 @@ static void process_device_event(SDL_Event *event)
id = ((SDL_JoyDeviceEvent *)event)->which; id = ((SDL_JoyDeviceEvent *)event)->which;
impl = find_device_from_id(id); impl = find_device_from_id(id);
if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device); 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) else if (event->type == SDL_JOYAXISMOTION && options.split_controllers)
{ {
id = event->jaxis.which; id = event->jaxis.which;
impl = find_device_from_id_and_axis(id, event->jaxis.axis); 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 else
{ {
event->jaxis.axis -= impl->axis_offset; event->jaxis.axis -= impl->axis_offset;
...@@ -1026,15 +1038,17 @@ static void process_device_event(SDL_Event *event) ...@@ -1026,15 +1038,17 @@ static void process_device_event(SDL_Event *event)
{ {
id = ((SDL_JoyButtonEvent *)event)->which; id = ((SDL_JoyButtonEvent *)event)->which;
impl = find_device_from_id(id); impl = find_device_from_id(id);
if (impl) set_report_from_joystick_event(impl, event); if (!impl) WARN("Failed to find device with id %d\n", id);
else 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) else if (event->type >= SDL_CONTROLLERAXISMOTION && event->type <= SDL_CONTROLLERBUTTONUP)
{ {
id = ((SDL_ControllerButtonEvent *)event)->which; id = ((SDL_ControllerButtonEvent *)event)->which;
impl = find_device_from_id(id); impl = find_device_from_id(id);
if (impl) set_report_from_controller_event(impl, event); if (!impl) WARN("Failed to find device with id %d\n", id);
else 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); pthread_mutex_unlock(&sdl_cs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment