From 670e089276684dc53c6920289ddca2fa56945724 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 22 May 2026 18:49:51 +1000 Subject: [PATCH] Windows: Cache unsupported HID device paths during HID controller polling --- Windows/Hid/HidInputDevice.cpp | 10 ++++++++-- Windows/Hid/HidInputDevice.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Windows/Hid/HidInputDevice.cpp b/Windows/Hid/HidInputDevice.cpp index 7632acf4f5..b0a994b44b 100644 --- a/Windows/Hid/HidInputDevice.cpp +++ b/Windows/Hid/HidInputDevice.cpp @@ -81,7 +81,7 @@ static const HIDControllerInfo *GetGamepadInfo(const HIDD_ATTRIBUTES &attr) { return nullptr; } -static HANDLE OpenFirstHIDController(HIDControllerType *subType, int *reportSize, int *outReportSize, const HIDControllerInfo **outInfo) { +static HANDLE OpenFirstHIDController(std::unordered_set &ignoreHidDevicePaths, HIDControllerType *subType, int *reportSize, int *outReportSize, const HIDControllerInfo **outInfo) { GUID hidGuid; HidD_GetHidGuid(&hidGuid); @@ -104,6 +104,11 @@ static HANDLE OpenFirstHIDController(HIDControllerType *subType, int *reportSize continue; } + std::wstring hidDevicePath = detailData->DevicePath; + if (ignoreHidDevicePaths.find(hidDevicePath) != ignoreHidDevicePaths.end()) { + continue; + } + HANDLE handle = CreateFile(detailData->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (handle == INVALID_HANDLE_VALUE) { @@ -120,6 +125,7 @@ static HANDLE OpenFirstHIDController(HIDControllerType *subType, int *reportSize *outInfo = info; if (!info) { CloseHandle(handle); + ignoreHidDevicePaths.insert(hidDevicePath); continue; } @@ -223,7 +229,7 @@ int HidInputDevice::UpdateState() { if (pollCount_ == 0) { pollCount_ = POLL_FREQ; const HIDControllerInfo *info{}; - HANDLE newController = OpenFirstHIDController(&subType_, &inReportSize_, &outReportSize_, &info); + HANDLE newController = OpenFirstHIDController(ignoreHidDevicePaths_, &subType_, &inReportSize_, &outReportSize_, &info); if (newController) { controller_ = newController; if (info) { diff --git a/Windows/Hid/HidInputDevice.h b/Windows/Hid/HidInputDevice.h index a24d8a8adb..fcbcc5143c 100644 --- a/Windows/Hid/HidInputDevice.h +++ b/Windows/Hid/HidInputDevice.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "Common/CommonTypes.h" #include "Common/Input/InputState.h" @@ -63,6 +64,7 @@ private: HIDControllerType subType_{}; HANDLE controller_; std::string name_; + std::unordered_set ignoreHidDevicePaths_; int pad_ = 0; int pollCount_ = 0; int inReportSize_ = 0;