Skip to content

Commit

Permalink
Expose joypad vendor_id and product_id in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubonnek committed May 3, 2024
1 parent 03e6fbb commit 644ee91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 15 additions & 2 deletions platform/windows/joypad_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {
joy->di_joy->EnumObjects(objectsCallback, this, 0);
joy->joy_axis.sort();

Dictionary joypad_info;
joypad_info["vendor_id"] = (int64_t)LOWORD(guid.Data1);
joypad_info["product_id"] = (int64_t)HIWORD(guid.Data1);

joy->guid = instance->guidInstance;
input->joy_connection_changed(num, true, instance->tszProductName, uid);
input->joy_connection_changed(num, true, instance->tszProductName, uid, joypad_info);
joy->attached = true;
joy->id = num;
attached_joypads[num] = true;
Expand Down Expand Up @@ -322,6 +326,13 @@ void JoypadWindows::probe_joypads() {
attached_joypads[id] = true;
Dictionary joypad_info;
joypad_info["xinput_index"] = (int)i;
if (XInputGetCapabilitiesEx) {
xinput_capabilities_ex xcapex;
if (XInputGetCapabilitiesEx(1, i, 0, &xcapex) == ERROR_SUCCESS) {
joypad_info["product_id"] = (int64_t)xcapex.productId;
joypad_info["vendor_id"] = (int64_t)xcapex.vendorId;
}
}
input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__", joypad_info);
}
} else if (x_joypads[i].attached) {
Expand Down Expand Up @@ -536,7 +547,9 @@ void JoypadWindows::load_xinput() {
xinput_set_state = &_xinput_set_state;
bool legacy_xinput = false;
xinput_dll = LoadLibrary("XInput1_4.dll");
if (!xinput_dll) {
if (xinput_dll) {
XInputGetCapabilitiesEx = (_XInputGetCapabilitiesEx)GetProcAddress((HMODULE)xinput_dll, (char *)108);
} else {
xinput_dll = LoadLibrary("XInput1_3.dll");
if (!xinput_dll) {
xinput_dll = LoadLibrary("XInput9_1_0.dll");
Expand Down
11 changes: 11 additions & 0 deletions platform/windows/joypad_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ class JoypadWindows {
uint64_t ff_end_timestamp = 0;
};

struct xinput_capabilities_ex {
XINPUT_CAPABILITIES Capabilities;
WORD vendorId;
WORD productId;
WORD revisionId;
DWORD a4; // unknown
};

typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE *pState);
typedef DWORD(WINAPI *XInputSetState_t)(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration);
typedef DWORD(_stdcall *_XInputGetCapabilitiesEx)(DWORD a1, DWORD dwUserIndex, DWORD dwFlags, xinput_capabilities_ex *pCapabilities);

_XInputGetCapabilitiesEx XInputGetCapabilitiesEx = nullptr;

HWND *hWnd = nullptr;
HANDLE xinput_dll;
Expand Down

0 comments on commit 644ee91

Please sign in to comment.