plat/win_pad.rs (Windows)#
Source: lib/plat/win_pad.rs
win_pad -- (G7a part 2) game pads on Windows: XInput (the shared part: pad.rs)
start() -> bool load XInput (xinput1_4.dll, else xinput9_1_0.dll, from System32),
look at all four slots
stop() every pad goes
poll(now, focused, full) -> next the connected slots' states (pad_update when their packet
number moved or the focus changed), one empty slot every 250 ms
(XInputGetState is slow on an empty one), all with full
xinput_test_feed(slot, rec) / xinput_test_end() (tests) XINPUT_STATE records instead of the
DLL's
XInput knows Xbox-compatible pads only (Xbox 360, One, Series and the pads that act as one; other
HID pads come later), at most four; the index of a pad is its XInput slot. XInputGetStateEx
(ordinal 100 of xinput1_4.dll) also reports the guide button (PAD_HOME); xinput9_1_0.dll has no
such ordinal, there XInputGetState without it. XInput reads the pads whoever has the focus: the
state is neutral while the app is not active (pad.rs).
fn xinput_test_feed(slot: usize, rec: Option<[u8; 16]>)(test aid, plattest --test pad) slotslotreports this XINPUT_STATE record (16 bytes: packet number, buttons, triggers, thumbs) from now on instead of the DLL's (None: not connected); the other slots of the first call are empty. The backend polls as it would the DLL (plat::pad_poll_test, or the window loop)fn xinput_test_end()(test aid) the DLL again (pad_watch(false) first: the slots' state is forgotten)