Windows: Cache unsupported HID device paths during HID controller polling

This commit is contained in:
Luke
2026-05-22 18:49:51 +10:00
parent f123c3ce0a
commit 670e089276
2 changed files with 10 additions and 2 deletions
+8 -2
View File
@@ -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<std::wstring> &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) {
+2
View File
@@ -5,6 +5,7 @@
#pragma once
#include <set>
#include <unordered_set>
#include "Common/CommonTypes.h"
#include "Common/Input/InputState.h"
@@ -63,6 +64,7 @@ private:
HIDControllerType subType_{};
HANDLE controller_;
std::string name_;
std::unordered_set<std::wstring> ignoreHidDevicePaths_;
int pad_ = 0;
int pollCount_ = 0;
int inReportSize_ = 0;