Rémi Bernon : user32: Update keyboard / mouse rawinput device paths.

Alexandre Julliard julliard at winehq.org
Thu May 13 15:30:59 CDT 2021


Module: wine
Branch: master
Commit: 2735496872ff75e7018bff9e2bf7f91487359c01
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=2735496872ff75e7018bff9e2bf7f91487359c01

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Wed May 12 11:25:27 2021 +0200

user32: Update keyboard / mouse rawinput device paths.

Instead of just updating the info.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/rawinput.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/dlls/user32/rawinput.c b/dlls/user32/rawinput.c
index d95d29d7656..e4e7bad508f 100644
--- a/dlls/user32/rawinput.c
+++ b/dlls/user32/rawinput.c
@@ -98,7 +98,7 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
 {
     SP_DEVINFO_DATA device_data = {sizeof(device_data)};
     SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail;
-    struct device *device;
+    struct device *device = NULL;
     UINT32 handle;
     HANDLE file;
     DWORD i, size, type;
@@ -117,15 +117,6 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
         return NULL;
     }
 
-    for (i = 0; i < rawinput_devices_count; ++i)
-    {
-        if (rawinput_devices[i].handle == UlongToHandle(handle))
-        {
-            TRACE("Updating device %x / %s\n", handle, debugstr_w(rawinput_devices[i].detail->DevicePath));
-            return rawinput_devices + i;
-        }
-    }
-
     if (!(detail = malloc(size)))
     {
         ERR("Failed to allocate memory.\n");
@@ -134,8 +125,6 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
     detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
     SetupDiGetDeviceInterfaceDetailW(set, iface, detail, size, NULL, NULL);
 
-    TRACE("Found device %x / %s.\n", handle, debugstr_w(detail->DevicePath));
-
     file = CreateFileW(detail->DevicePath, GENERIC_READ | GENERIC_WRITE,
             FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
     if (file == INVALID_HANDLE_VALUE)
@@ -145,8 +134,24 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
         return NULL;
     }
 
-    if (!array_reserve((void **)&rawinput_devices, &rawinput_devices_max,
-            rawinput_devices_count + 1, sizeof(*rawinput_devices)))
+    for (i = 0; i < rawinput_devices_count && !device; ++i)
+        if (rawinput_devices[i].handle == UlongToHandle(handle))
+            device = rawinput_devices + i;
+
+    if (device)
+    {
+        TRACE("Updating device %x / %s.\n", handle, debugstr_w(detail->DevicePath));
+        HidD_FreePreparsedData(device->data);
+        CloseHandle(device->file);
+        free(device->detail);
+    }
+    else if (array_reserve((void **)&rawinput_devices, &rawinput_devices_max,
+                           rawinput_devices_count + 1, sizeof(*rawinput_devices)))
+    {
+        device = &rawinput_devices[rawinput_devices_count++];
+        TRACE("Adding device %x / %s.\n", handle, debugstr_w(detail->DevicePath));
+    }
+    else
     {
         ERR("Failed to allocate memory.\n");
         CloseHandle(file);
@@ -154,7 +159,6 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
         return NULL;
     }
 
-    device = &rawinput_devices[rawinput_devices_count++];
     device->detail = detail;
     device->file = file;
     device->handle = ULongToHandle(handle);
@@ -226,8 +230,6 @@ static void find_devices(void)
 
         device->info.dwType = RIM_TYPEMOUSE;
         device->info.u.mouse = mouse_info;
-        HidD_FreePreparsedData(device->data);
-        device->data = NULL;
     }
 
     SetupDiDestroyDeviceInfoList(set);
@@ -243,8 +245,6 @@ static void find_devices(void)
 
         device->info.dwType = RIM_TYPEKEYBOARD;
         device->info.u.keyboard = keyboard_info;
-        HidD_FreePreparsedData(device->data);
-        device->data = NULL;
     }
 
     SetupDiDestroyDeviceInfoList(set);




More information about the wine-cvs mailing list