From: Rémi Bernon <rbernon@codeweavers.com> --- dlls/xinput1_3/main.c | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/dlls/xinput1_3/main.c b/dlls/xinput1_3/main.c index 1fbbf9cf3f8..7fbf0616b29 100644 --- a/dlls/xinput1_3/main.c +++ b/dlls/xinput1_3/main.c @@ -123,19 +123,6 @@ static HMODULE xinput_instance; static HANDLE start_event; static HANDLE update_event; -static BOOL find_opened_device(const WCHAR *device_path, int *free_slot) -{ - int i; - - *free_slot = XUSER_MAX_COUNT; - for (i = XUSER_MAX_COUNT; i > 0; i--) - { - if (!controllers[i - 1].device) *free_slot = i - 1; - else if (!wcsicmp(device_path, controllers[i - 1].device_path)) return TRUE; - } - return FALSE; -} - static void check_value_caps(struct xinput_controller *controller, USHORT usage, HIDP_VALUE_CAPS *caps) { switch (usage) @@ -447,17 +434,12 @@ static BOOL device_is_overridden(HANDLE device) return disable; } -static BOOL try_add_device(const WCHAR *device_path) +static BOOL open_device_at_index(const WCHAR *device_path, int index) { - SP_DEVICE_INTERFACE_DATA iface = {sizeof(iface)}; PHIDP_PREPARSED_DATA preparsed; HIDP_CAPS caps; NTSTATUS status; HANDLE device; - int i; - - if (find_opened_device(device_path, &i)) return TRUE; /* already opened */ - if (i == XUSER_MAX_COUNT) return FALSE; /* no more slots */ device = CreateFileW(device_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, NULL); @@ -475,16 +457,41 @@ static BOOL try_add_device(const WCHAR *device_path) WARN("ignoring HID device, unsupported usage %04x:%04x\n", caps.UsagePage, caps.Usage); else if (device_is_overridden(device)) WARN("ignoring HID device, overridden for dinput\n"); - else if (!controller_init(&controllers[i], preparsed, &caps, device, device_path)) + else if (!controller_init(&controllers[index], preparsed, &caps, device, device_path)) WARN("ignoring HID device, failed to initialize\n"); else + { + TRACE("opened device %s at index %u\n", debugstr_w(device_path), index); return TRUE; + } CloseHandle(device); HidD_FreePreparsedData(preparsed); return TRUE; } +static BOOL find_opened_device(const WCHAR *device_path, int *free_slot) +{ + int i; + + *free_slot = XUSER_MAX_COUNT; + for (i = XUSER_MAX_COUNT; i > 0; i--) + { + if (!controllers[i - 1].device) *free_slot = i - 1; + else if (!wcsicmp(device_path, controllers[i - 1].device_path)) return TRUE; + } + return FALSE; +} + +static BOOL try_add_device(const WCHAR *device_path) +{ + int i; + + if (find_opened_device(device_path, &i)) return TRUE; /* already opened */ + if (i == XUSER_MAX_COUNT) return FALSE; /* no more slots */ + return open_device_at_index(device_path, i); +} + static void try_remove_device(const WCHAR *device_path) { int i; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11139