Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose joypad vendor_id and product_id in Windows #91539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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