From 318f0e60aa23fba6bc759319c8d2e694f4b6e23a Mon Sep 17 00:00:00 2001 From: AethanFoot Date: Sun, 10 Mar 2024 13:42:47 +0000 Subject: [PATCH] small clean up, for some reason virtual device doesn't work on laptop/fedora --- lefthk-core/src/evdev.rs | 15 +++----------- lefthk-core/src/worker/mod.rs | 39 +++++------------------------------ 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/lefthk-core/src/evdev.rs b/lefthk-core/src/evdev.rs index de2d75c..1f58d70 100644 --- a/lefthk-core/src/evdev.rs +++ b/lefthk-core/src/evdev.rs @@ -8,7 +8,7 @@ use crate::errors::{self, LeftError}; #[derive(Debug)] pub enum Task { - KeyboardEvent((PathBuf, InputEvent)), + KeyboardEvent(InputEvent), KeyboardAdded(PathBuf), KeyboardRemoved(PathBuf), } @@ -43,7 +43,7 @@ impl Default for EvDev { let builder = errors::exit!(VirtualDeviceBuilder::new()); - let mut device = builder + let device = builder .name("LeftHK Virtual Keyboard") .input_id(InputId::new(BusType::BUS_I8042, 1, 1, 1)) .with_keys(&keys) @@ -52,10 +52,6 @@ impl Default for EvDev { .unwrap() .build() .unwrap(); - println!("Device: {:?}", device.get_syspath()); - - let devnode = device.enumerate_dev_nodes_blocking().unwrap().next(); - println!("Devnode: {:?}", devnode); let (task_transmitter, task_receiver) = mpsc::channel(128); @@ -97,19 +93,14 @@ impl EvDev { let transmitter = self.task_transmitter.clone(); let mut stream = errors::r#return!(device.into_event_stream()); - let p = path.clone(); tokio::task::spawn(async move { while !guard.is_closed() { match stream.next_event().await { Ok(event) => { - transmitter - .send(Task::KeyboardEvent((p.clone(), event))) - .await - .unwrap(); + transmitter.send(Task::KeyboardEvent(event)).await.unwrap(); } Err(err) => { tracing::warn!("Evdev device stream failed with {:?}", err); - // poll_fn(|cx| guard.poll_closed(cx)).await; break; } } diff --git a/lefthk-core/src/worker/mod.rs b/lefthk-core/src/worker/mod.rs index 98bfc17..e6e330e 100644 --- a/lefthk-core/src/worker/mod.rs +++ b/lefthk-core/src/worker/mod.rs @@ -1,14 +1,12 @@ pub mod context; -use std::path::PathBuf; - use crate::child::Children; use crate::config::{command, Keybind}; use crate::errors::{self, LeftError}; use crate::evdev::{EvDev, Task}; use crate::ipc::Pipe; use crate::keysym_lookup::{self, is_modifier, MOD_MASK}; -use evdev::{EventType, InputEvent, InputEventKind, Key}; +use evdev::{InputEvent, InputEventKind, Key}; use xdg::BaseDirectories; #[derive(Clone, Copy, Debug)] @@ -83,8 +81,8 @@ impl Worker { } Some(task) = self.evdev.task_receiver.recv() => { match task { - Task::KeyboardEvent((path, event)) => { - self.handle_event(path, event); + Task::KeyboardEvent(event) => { + self.handle_event(event); } Task::KeyboardAdded(path) => { self.evdev.add_device(path); @@ -109,7 +107,7 @@ impl Worker { errors::exit!(Pipe::new(pipe_file).await) } - fn handle_event(&mut self, path: PathBuf, event: InputEvent) { + fn handle_event(&mut self, event: InputEvent) { let r#type = KeyEventType::from(event.value()); let mut eaten = false; match r#type { @@ -168,35 +166,8 @@ impl Worker { KeyEventType::Repeat | KeyEventType::Unknown => {} } if !eaten { - self.pass_event(path, event); - } - } - - fn pass_event(&mut self, _path: PathBuf, event: InputEvent) { - match self.evdev.device.emit(&[event]) { - Ok(_) => { - tracing::debug!("Successfully sent event: {:?}", event); - } - Err(err) => { - tracing::warn!("Failed to pass event: {:?}", err); - } + let _ = self.evdev.device.emit(&[event]); } - let code = Key::KEY_K.code(); - let down_event = InputEvent::new(EventType::KEY, code, 1); - self.evdev.device.emit(&[down_event]).unwrap(); - println!("Pressed."); - // sleep(Duration::from_secs(2)); - - // alternativeley we can create a InputEvent, which will be any variant of InputEvent - // depending on the type_ value - let up_event = InputEvent::new(EventType::KEY, code, 0); - self.evdev.device.emit(&[up_event]).unwrap(); - println!("Released."); - // sleep(Duration::from_secs(2)); - // match self.evdev.devices.get(&path) { - // Some(device) => errors::log!(device.write_event(event)), - // None => errors::log!(Err(LeftError::UInputNotFound)), - // } } fn check_for_keybind(&self) -> Option {