From 8389de757a1086efd759c6618948e20ab7516321 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 16 Feb 2026 10:02:16 -0800
Subject: [PATCH] Don't re-query HID device vendor and product
(cherry picked from commit a98e49409e2c6c4684934e15f682ee37b3a91ef8)
---
src/video/windows/SDL_windowsevents.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c
index d50a8af0ce1f1..cd11bc61a0d19 100644
--- a/src/video/windows/SDL_windowsevents.c
+++ b/src/video/windows/SDL_windowsevents.c
@@ -879,7 +879,7 @@ static bool HasDeviceID(Uint32 deviceID, const Uint32 *list, int count)
}
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
-static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instance, const char *default_name, bool hid_loaded)
+static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instance, Uint16 vendor, Uint16 product, const char *default_name, bool hid_loaded)
{
char *vendor_name = NULL;
char *product_name = NULL;
@@ -890,12 +890,6 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
vend[0] = 0;
prod[0] = 0;
-
- HIDD_ATTRIBUTES attr;
- attr.VendorID = 0;
- attr.ProductID = 0;
- attr.Size = sizeof(attr);
-
if (hid_loaded) {
char devName[MAX_PATH + 1];
UINT cap = sizeof(devName) - 1;
@@ -908,7 +902,6 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
// they can only be opened with a desired access of none instead of generic read.
HANDLE hFile = CreateFileA(devName, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
- SDL_HidD_GetAttributes(hFile, &attr);
SDL_HidD_GetManufacturerString(hFile, vend, sizeof(vend));
SDL_HidD_GetProductString(hFile, prod, sizeof(prod));
CloseHandle(hFile);
@@ -950,8 +943,8 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
}
prod[size] = 0;
- if (attr.VendorID || attr.ProductID) {
- SDL_asprintf(&product_name, "%S (0x%.4x/0x%.4x)", prod, attr.VendorID, attr.ProductID);
+ if (vendor || product) {
+ SDL_asprintf(&product_name, "%S (0x%.4x/0x%.4x)", prod, vendor, product);
} else {
product_name = WIN_StringToUTF8W(prod);
}
@@ -961,10 +954,10 @@ static char *GetDeviceName(HANDLE hDevice, HDEVINFO devinfo, const char *instanc
}
}
- if (!product_name && (attr.VendorID || attr.ProductID)) {
- SDL_asprintf(&product_name, "%s (0x%.4x/0x%.4x)", default_name, attr.VendorID, attr.ProductID);
+ if (!product_name && (vendor || product)) {
+ SDL_asprintf(&product_name, "%s (0x%.4x/0x%.4x)", default_name, vendor, product);
}
- name = SDL_CreateDeviceName(attr.VendorID, attr.ProductID, vendor_name, product_name, default_name);
+ name = SDL_CreateDeviceName(vendor, product, vendor_name, product_name, default_name);
SDL_free(vendor_name);
SDL_free(product_name);
@@ -1063,7 +1056,7 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, bool initial_check
SDL_KeyboardID keyboardID = (Uint32)(uintptr_t)raw_devices[i].hDevice;
AddDeviceID(keyboardID, &new_keyboards, &new_keyboard_count);
if (!HasDeviceID(keyboardID, old_keyboards, old_keyboard_count)) {
- name = GetDeviceName(raw_devices[i].hDevice, devinfo, instance, "Keyboard", hid_loaded);
+ name = GetDeviceName(raw_devices[i].hDevice, devinfo, instance, (Uint16)vendor, (Uint16)product, "Keyboard", hid_loaded);
SDL_AddKeyboard(keyboardID, name);
SDL_free(name);
}
@@ -1074,7 +1067,7 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, bool initial_check
SDL_MouseID mouseID = (Uint32)(uintptr_t)raw_devices[i].hDevice;
AddDeviceID(mouseID, &new_mice, &new_mouse_count);
if (!HasDeviceID(mouseID, old_mice, old_mouse_count)) {
- name = GetDeviceName(raw_devices[i].hDevice, devinfo, instance, "Mouse", hid_loaded);
+ name = GetDeviceName(raw_devices[i].hDevice, devinfo, instance, (Uint16)vendor, (Uint16)product, "Mouse", hid_loaded);
SDL_AddMouse(mouseID, name);
SDL_free(name);
}