Skip to content

Commit a02920b

Browse files
committed
device: detect XInput devices on start-up
This is needed to handle cases where XInput is being emulated, such as when running via Steam with the Steam Controller active. Steam's shim does not send out WM_INPUT_DEVICE_CHANGE events.
1 parent 2bde2ba commit a02920b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

panda/src/device/winInputDeviceManager.cxx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,47 @@ WinInputDeviceManager() :
8282
device_cat.warning()
8383
<< "Failed to register raw input devices.\n";
8484
}
85+
86+
// Do we have any XInput devices plugged in now?
87+
int num_xinput = 0;
88+
HANDLE xinput_handle;
89+
RAWINPUTDEVICELIST devices[64];
90+
UINT num_devices = 64;
91+
num_devices = GetRawInputDeviceList(devices, &num_devices, sizeof(RAWINPUTDEVICELIST));
92+
if (num_devices == (UINT)-1) {
93+
return;
94+
}
95+
for (UINT i = 0; i < num_devices; ++i) {
96+
if (devices[i].dwType != RIM_TYPEHID) {
97+
continue;
98+
}
99+
HANDLE handle = devices[i].hDevice;
100+
UINT size;
101+
if (GetRawInputDeviceInfoA(handle, RIDI_DEVICENAME, nullptr, &size) != 0) {
102+
continue;
103+
}
104+
105+
char *path = (char *)alloca(size);
106+
if (path == nullptr ||
107+
GetRawInputDeviceInfoA(handle, RIDI_DEVICENAME, (void *)path, &size) < 0) {
108+
continue;
109+
}
110+
111+
if (strstr(path, "&IG_") != nullptr) {
112+
xinput_handle = handle;
113+
++num_xinput;
114+
}
115+
}
116+
if (num_xinput == 1) {
117+
// There's only one XInput device, so we know which one it is.
118+
on_input_device_arrival(xinput_handle);
119+
} else if (num_xinput > 0) {
120+
// Just poll all the XInput devices.
121+
_xinput_device0.detect(this);
122+
_xinput_device1.detect(this);
123+
_xinput_device2.detect(this);
124+
_xinput_device3.detect(this);
125+
}
85126
}
86127

87128
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy