plat/linux_pad.rs (Linux)#
Source: lib/plat/linux_pad.rs
linux_pad -- (G7a part 2) game pads on Linux: evdev (the shared part and the parser: pad.rs)
start() -> bool an inotify watch on /dev/input, then every event node looked at
stop() every pad goes, the nodes and the watch are closed
poll(now, focused, full) -> next read what the pads' nodes have (EvdevPad::feed, pad_update),
every 250 ms what inotify reported (new nodes, nodes whose rights
changed: udev sets them after the node appears); a node that says
ENODEV or ends is a pad that went
evdev_test_attach(..) (tests) a pad whose node is a pipe the test writes into
evdev_test_rescan_due() (tests) whether the next poll looks at the folder again
A node is a pad when evdev_is_pad says so of its bitmaps (EVIOCGBIT): keys with BTN_SOUTH,
absolute axes with ABS_X and ABS_Y. udev's uaccess rule gives the user of the seat its game
controllers (ID_INPUT_JOYSTICK), never keyboards or mice: what cannot be opened is no pad of
ours, and is not opened again until inotify reports it anew. Nodes are opened read-only and
without blocking; their events are read whenever the pads are polled (4 ms), not from the window
loop's poll(). Inside a Flatpak /dev/input exists only with --device=input (Flatpak 1.15.6 and
newer; the manifest's `gamepad` line gives it, tools/pkg_linux.py); without it no pad is found.
Older Flatpak refuses to build with it and ignores it in an installed app (no /dev/input).
struct EvdevTestNode(usize)(test aid, plattest --test pad) the writing end of a pipe whose reading end is a pad's node (evdev_test_attach): what is written reaches the pad when the pads are polled; dropping it is the pad's unplugging
impl EvdevTestNode
fn write(&self, data: &[u8]) -> boolinput_event records (EVDEV_EVENT_SIZE bytes each) into the node -> all writtenfn evdev_test_rescan_due() -> bool(test aid) whether the next poll looks at /dev/input againfn evdev_test_attach(name: &str, vendor: u16, keys: &[u8], abs: &[AbsInfo]) -> Option<(usize, EvdevTestNode)>(test aid) a pad with these keys and axes (EvdevPad::new) whose node is a pipe of the test's: it connects at once -> (its slot, the pipe's writing end); None: not watching, no slot free or no pipe