diff --git a/src/main.rs b/src/main.rs index b36f936..b119a45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,8 +35,7 @@ fn enumerate_keyboards() -> Vec { .collect() } -async fn find_target_keyboard(device_paths: &Vec) -> Option{ - +async fn find_target_keyboard(device_paths: &Vec) -> Option { let (tx, mut rx): (Sender, Receiver) = channel(1); let mut handles = vec![]; @@ -62,24 +61,19 @@ async fn find_target_keyboard(device_paths: &Vec) -> Option{ #[tokio::main(flavor = "local")] async fn main() { - - let devices_paths = enumerate_keyboards(); - + println!("Found the following devices"); for path in &devices_paths { - if let Ok(d) = Device::open(path){ + if let Ok(d) = Device::open(path) { println!("\t{} ({})", d.name().unwrap_or("null"), path.display()) } } - - let Some(kb) = find_target_keyboard(&devices_paths).await else { return; }; - let Ok(mut kb) = kb.into_event_stream() else { return; }; @@ -97,9 +91,8 @@ async fn main() { match kb.device_mut().ungrab() { Err(err) => println!("Failed to release device: {err}"), - _ => () + _ => (), }; println!("Device released"); - } diff --git a/src/virtual_gamepad.rs b/src/virtual_gamepad.rs index bd72af1..5df1492 100644 --- a/src/virtual_gamepad.rs +++ b/src/virtual_gamepad.rs @@ -1,12 +1,12 @@ use evdev::uinput::VirtualDevice; use evdev::{ - AbsInfo, AbsoluteAxisCode, AttributeSet, EventStream, EventType, InputEvent, KeyCode, UinputAbsSetup + AbsInfo, AbsoluteAxisCode, AttributeSet, EventStream, EventType, InputEvent, KeyCode, + UinputAbsSetup, }; use std::collections::HashMap; -#[derive(PartialEq, Debug)] -#[derive(Clone, Copy)] +#[derive(PartialEq, Debug, Clone, Copy)] #[repr(u8)] pub enum Direction { Up = 0, @@ -66,8 +66,6 @@ impl VirtualGamepad { dpad_bindings.insert(KeyCode::KEY_F.code(), Direction::Right); dpad_bindings.insert(KeyCode::KEY_W.code(), Direction::Left); - - let ui = VirtualDevice::builder() .unwrap() .name(&name) @@ -86,7 +84,6 @@ impl VirtualGamepad { .build() .unwrap(); - VirtualGamepad { ui, btn_bindings,