Module: wine Branch: master Commit: 5417c3bfa4e667902835117dc78b9ea629e7bc3e URL: https://source.winehq.org/git/wine.git/?a=commit;h=5417c3bfa4e667902835117dc...
Author: Andrew Eikum aeikum@codeweavers.com Date: Tue Oct 22 15:00:34 2019 -0500
xinput: Consolidate new device setup.
Signed-off-by: Andrew Eikum aeikum@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/xinput1_3/hid.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/dlls/xinput1_3/hid.c b/dlls/xinput1_3/hid.c index 477d5304ca..5baf3b2b53 100644 --- a/dlls/xinput1_3/hid.c +++ b/dlls/xinput1_3/hid.c @@ -171,19 +171,34 @@ static BOOL VerifyGamepad(PHIDP_PREPARSED_DATA ppd, XINPUT_CAPABILITIES *xinput_ return TRUE; }
-static void build_private(struct hid_platform_private *private, PHIDP_PREPARSED_DATA ppd, HIDP_CAPS *caps, HANDLE device, WCHAR *path) +static BOOL init_controller(xinput_controller *controller, PHIDP_PREPARSED_DATA ppd, HIDP_CAPS *caps, HANDLE device, WCHAR *device_path) { size_t size; + struct hid_platform_private *private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct hid_platform_private)); + + if (!VerifyGamepad(ppd, &controller->caps, private, caps)) + { + HeapFree(GetProcessHeap(), 0, private); + return FALSE; + } + + TRACE("Found gamepad %s\n", debugstr_w(device_path)); + private->ppd = ppd; private->device = device; private->report_length = caps->InputReportByteLength + 1; private->current_report = 0; private->reports[0] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, private->report_length); private->reports[1] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, private->report_length); - size = (lstrlenW(path) + 1) * sizeof(WCHAR); + size = (lstrlenW(device_path) + 1) * sizeof(WCHAR); private->device_path = HeapAlloc(GetProcessHeap(), 0, size); - memcpy(private->device_path, path, size); + memcpy(private->device_path, device_path, size); private->enabled = TRUE; + + controller->platform_private = private; + controller->connected = TRUE; + + return TRUE; }
void HID_find_gamepads(xinput_controller *devices) @@ -263,19 +278,10 @@ void HID_find_gamepads(xinput_controller *devices) Caps.Usage == HID_USAGE_GENERIC_JOYSTICK || Caps.Usage == 0x8 /* Multi-axis Controller */)) { - struct hid_platform_private *private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct hid_platform_private)); - if (VerifyGamepad(ppd, &devices[open_device_idx].caps, private, &Caps)) - { - TRACE("Found gamepad %i %s\n", open_device_idx, debugstr_w(data->DevicePath)); - build_private(private, ppd, &Caps, device, data->DevicePath); - devices[open_device_idx].platform_private = private; - devices[open_device_idx].connected = TRUE; - } - else + if(!init_controller(&devices[open_device_idx], ppd, &Caps, device, data->DevicePath)) { CloseHandle(device); HidD_FreePreparsedData(ppd); - HeapFree(GetProcessHeap(), 0, private); } } else