MCPcopy Create free account
hub / github.com/emberian/evdev / get_device

Function get_device

tests/common/mod.rs:27–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25}
26
27pub fn get_device() -> std::io::Result<(PathBuf, VirtualDevice)> {
28 let mut keys: AttributeSet<KeyCode> = AttributeSet::new();
29 for code in 1..59 {
30 let key = KeyCode::new(code);
31 let name = format!("{:?}", key);
32 if name.starts_with("KEY_") {
33 keys.insert(key);
34 }
35 }
36
37 let mut sw: AttributeSet<SwitchCode> = AttributeSet::new();
38
39 sw.insert(SwitchCode::SW_LID);
40 sw.insert(SwitchCode::SW_TABLET_MODE);
41
42 let mut device = VirtualDevice::builder()?
43 .input_id(InputId::new(BusType::BUS_USB, 0x1234, 0x5678, 0x111))
44 .name("test device")
45 .with_keys(&keys)?
46 .with_switches(&sw)?
47 .build()?;
48
49 // Fetch name.
50 let d: Vec<std::path::PathBuf> = device
51 .enumerate_dev_nodes_blocking()?
52 .map(|p| p.unwrap())
53 .collect();
54
55 thread::sleep(Duration::from_millis(100)); // To avoid permission denied.
56
57 Ok((d.first().unwrap().clone(), device))
58}
59
60pub fn final_dot_state(start_state: i32, events: impl Iterator<Item = InputEvent>) -> i32 {
61 events.fold(start_state, |state, ev| {

Callers 1

get_test_deviceFunction · 0.85

Calls 8

insertMethod · 0.80
buildMethod · 0.80
with_switchesMethod · 0.80
with_keysMethod · 0.80
nameMethod · 0.45
input_idMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…