Browse Source

Use the keyboard/mouse vendor if available

Fixes the 8BitDo Micro gamepad so it shows up as "8BitDo HID-compliant mouse" and "8BitDo HID Keyboard Device" in keyboard mode over USB.
Sam Lantinga 1 month ago
parent
commit
fdf72d1e45
1 changed files with 11 additions and 13 deletions
  1. 11 13
      src/video/windows/SDL_windowsevents.c

+ 11 - 13
src/video/windows/SDL_windowsevents.c

@@ -895,17 +895,7 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
         }
     }
 
-    if (prod[0]) {
-        char *vendor_name = WIN_StringToUTF8W(vend);
-        char *product_name = WIN_StringToUTF8W(prod);
-        if (product_name) {
-            name = SDL_CreateDeviceName(attr.VendorID, attr.ProductID, vendor_name, product_name);
-        }
-        SDL_free(vendor_name);
-        SDL_free(product_name);
-    }
-
-    if (!name) {
+    if (!prod[0]) {
         SP_DEVINFO_DATA data;
         SDL_zero(data);
         data.cbSize = sizeof(data);
@@ -932,13 +922,21 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
                         size = (SDL_arraysize(prod) - 1);
                     }
                     prod[size] = 0;
-
-                    name = WIN_StringToUTF8W(prod);
                 }
                 break;
             }
         }
     }
+
+    if (prod[0]) {
+        char *vendor_name = vend[0] ? WIN_StringToUTF8W(vend) : NULL;
+        char *product_name = WIN_StringToUTF8W(prod);
+        if (product_name) {
+            name = SDL_CreateDeviceName(attr.VendorID, attr.ProductID, vendor_name, product_name);
+        }
+        SDL_free(vendor_name);
+        SDL_free(product_name);
+    }
     return name;
 }