winebus.sys: Use the SDL joystick index as device id instead of instance id.

Some games are using the HID device id as the gamepad index for xinput
API. When hotplugging devices, SDL increases its instance id and it
doesn't match anymore with xinput gamepad numbers.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2019-09-20 10:31:41 +02:00 committed by Alexandre Julliard
parent 8db70e92a8
commit 3d2f43a1da
1 changed files with 15 additions and 11 deletions

View File

@ -744,17 +744,21 @@ static const platform_vtbl sdl_vtbl =
set_feature_report,
};
static int compare_joystick_id(DEVICE_OBJECT *device, void* context)
{
return impl_from_DEVICE_OBJECT(device)->id - PtrToUlong(context);
}
static BOOL set_report_from_event(SDL_Event *event)
{
DEVICE_OBJECT *device;
struct platform_private *private;
/* All the events coming in will have 'which' as a 3rd field */
SDL_JoystickID index = ((SDL_JoyButtonEvent*)event)->which;
device = bus_find_hid_device(&sdl_vtbl, ULongToPtr(index));
SDL_JoystickID id = ((SDL_JoyButtonEvent*)event)->which;
device = bus_enumerate_hid_devices(&sdl_vtbl, compare_joystick_id, ULongToPtr(id));
if (!device)
{
ERR("Failed to find device at index %i\n",index);
ERR("Failed to find device at index %i\n",id);
return FALSE;
}
private = impl_from_DEVICE_OBJECT(device);
@ -814,11 +818,11 @@ static BOOL set_mapped_report_from_event(SDL_Event *event)
DEVICE_OBJECT *device;
struct platform_private *private;
/* All the events coming in will have 'which' as a 3rd field */
int index = ((SDL_ControllerButtonEvent*)event)->which;
device = bus_find_hid_device(&sdl_vtbl, ULongToPtr(index));
SDL_JoystickID id = ((SDL_ControllerButtonEvent*)event)->which;
device = bus_enumerate_hid_devices(&sdl_vtbl, compare_joystick_id, ULongToPtr(id));
if (!device)
{
ERR("Failed to find device at index %i\n",index);
ERR("Failed to find device at index %i\n",id);
return FALSE;
}
private = impl_from_DEVICE_OBJECT(device);
@ -878,7 +882,7 @@ static BOOL set_mapped_report_from_event(SDL_Event *event)
return FALSE;
}
static void try_remove_device(SDL_JoystickID index)
static void try_remove_device(SDL_JoystickID id)
{
DEVICE_OBJECT *device = NULL;
struct platform_private *private;
@ -886,7 +890,7 @@ static void try_remove_device(SDL_JoystickID index)
SDL_GameController *sdl_controller;
SDL_Haptic *sdl_haptic;
device = bus_find_hid_device(&sdl_vtbl, ULongToPtr(index));
device = bus_enumerate_hid_devices(&sdl_vtbl, compare_joystick_id, ULongToPtr(id));
if (!device) return;
private = impl_from_DEVICE_OBJECT(device);
@ -905,7 +909,7 @@ static void try_remove_device(SDL_JoystickID index)
pSDL_HapticClose(sdl_haptic);
}
static void try_add_device(SDL_JoystickID index)
static void try_add_device(unsigned int index)
{
DWORD vid = 0, pid = 0, version = 0;
DEVICE_OBJECT *device = NULL;
@ -967,7 +971,7 @@ static void try_add_device(SDL_JoystickID index)
input = 0;
device = bus_create_hid_device(sdl_busidW, vid, pid,
input, version, id, serial, is_xbox_gamepad, &GUID_DEVCLASS_SDL,
input, version, index, serial, is_xbox_gamepad, &GUID_DEVCLASS_SDL,
&sdl_vtbl, sizeof(struct platform_private));
if (device)