Skip to content

Commit 644ee91

Browse files
committed
Expose joypad vendor_id and product_id in Windows
1 parent 03e6fbb commit 644ee91

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

platform/windows/joypad_windows.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {
200200
joy->di_joy->EnumObjects(objectsCallback, this, 0);
201201
joy->joy_axis.sort();
202202

203+
Dictionary joypad_info;
204+
joypad_info["vendor_id"] = (int64_t)LOWORD(guid.Data1);
205+
joypad_info["product_id"] = (int64_t)HIWORD(guid.Data1);
206+
203207
joy->guid = instance->guidInstance;
204-
input->joy_connection_changed(num, true, instance->tszProductName, uid);
208+
input->joy_connection_changed(num, true, instance->tszProductName, uid, joypad_info);
205209
joy->attached = true;
206210
joy->id = num;
207211
attached_joypads[num] = true;
@@ -322,6 +326,13 @@ void JoypadWindows::probe_joypads() {
322326
attached_joypads[id] = true;
323327
Dictionary joypad_info;
324328
joypad_info["xinput_index"] = (int)i;
329+
if (XInputGetCapabilitiesEx) {
330+
xinput_capabilities_ex xcapex;
331+
if (XInputGetCapabilitiesEx(1, i, 0, &xcapex) == ERROR_SUCCESS) {
332+
joypad_info["product_id"] = (int64_t)xcapex.productId;
333+
joypad_info["vendor_id"] = (int64_t)xcapex.vendorId;
334+
}
335+
}
325336
input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__", joypad_info);
326337
}
327338
} else if (x_joypads[i].attached) {
@@ -536,7 +547,9 @@ void JoypadWindows::load_xinput() {
536547
xinput_set_state = &_xinput_set_state;
537548
bool legacy_xinput = false;
538549
xinput_dll = LoadLibrary("XInput1_4.dll");
539-
if (!xinput_dll) {
550+
if (xinput_dll) {
551+
XInputGetCapabilitiesEx = (_XInputGetCapabilitiesEx)GetProcAddress((HMODULE)xinput_dll, (char *)108);
552+
} else {
540553
xinput_dll = LoadLibrary("XInput1_3.dll");
541554
if (!xinput_dll) {
542555
xinput_dll = LoadLibrary("XInput9_1_0.dll");

platform/windows/joypad_windows.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,19 @@ class JoypadWindows {
104104
uint64_t ff_end_timestamp = 0;
105105
};
106106

107+
struct xinput_capabilities_ex {
108+
XINPUT_CAPABILITIES Capabilities;
109+
WORD vendorId;
110+
WORD productId;
111+
WORD revisionId;
112+
DWORD a4; // unknown
113+
};
114+
107115
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE *pState);
108116
typedef DWORD(WINAPI *XInputSetState_t)(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration);
117+
typedef DWORD(_stdcall *_XInputGetCapabilitiesEx)(DWORD a1, DWORD dwUserIndex, DWORD dwFlags, xinput_capabilities_ex *pCapabilities);
118+
119+
_XInputGetCapabilitiesEx XInputGetCapabilitiesEx = nullptr;
109120

110121
HWND *hWnd = nullptr;
111122
HANDLE xinput_dll;

0 commit comments

Comments
 (0)