From 14eb1a6eddf33466f6a644592dba3a363dff9c9f Mon Sep 17 00:00:00 2001 From: Sawyer McLane Date: Mon, 23 Sep 2024 13:21:20 -0600 Subject: [PATCH] Clean up more imports --- src/app.rs | 2 +- src/listener.rs | 34 ++++++++++++++++++---------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/app.rs b/src/app.rs index d362dd3..707e550 100644 --- a/src/app.rs +++ b/src/app.rs @@ -86,7 +86,7 @@ impl Default for MantleApp { let mgr = LifxManager::new().expect("Failed to create manager"); let screen_manager = ScreencapManager::new().expect("Failed to create screen manager"); let input_listener = InputListener::new(); - let listener_handle = Some(input_listener.spawn()); + let listener_handle = Some(input_listener.start()); Self { mgr, screen_manager, diff --git a/src/listener.rs b/src/listener.rs index 355ddc8..d7e5b47 100644 --- a/src/listener.rs +++ b/src/listener.rs @@ -1,8 +1,10 @@ use log::error; -use rdev::{listen, Event, EventType, Key}; +use rdev::{listen, Button, Event, EventType, Key}; use std::collections::HashSet; +use std::fmt::{Debug, Display, Formatter, Result}; +use std::hash::{Hash, Hasher}; use std::sync::{Arc, Mutex}; -use std::thread; +use std::thread::{spawn, JoinHandle}; use std::time::Instant; type BackgroundCallback = Box; @@ -14,7 +16,7 @@ pub struct MousePosition { pub y: i32, } -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, Eq, PartialEq)] pub struct KeyboardShortcut { pub keys: HashSet, } @@ -27,22 +29,22 @@ pub struct KeyboardShortcutCallback { pub callback_name: String, } -impl std::hash::Hash for KeyboardShortcut { - fn hash(&self, state: &mut H) { +impl Hash for KeyboardShortcut { + fn hash(&self, state: &mut H) { for key in &self.keys { key.hash(state); } } } -impl std::fmt::Debug for KeyboardShortcut { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl Debug for KeyboardShortcut { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "KeyboardShortcut({:?})", self.keys) } } -impl std::fmt::Display for KeyboardShortcut { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl Display for KeyboardShortcut { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { let keys: Vec = self.keys.iter().map(|k| format!("{:?}", k)).collect(); write!(f, "{}", keys.join(" + ")) } @@ -57,8 +59,8 @@ impl KeyboardShortcut { pub struct SharedInputState { last_mouse_position: Mutex>, last_click_time: Mutex>, - button_pressed: Mutex>, - last_button_pressed: Mutex>, + button_pressed: Mutex>, + last_button_pressed: Mutex>, keys_pressed: Mutex>, last_keys_pressed: Mutex>, callbacks: Mutex>, @@ -92,7 +94,7 @@ impl SharedInputState { } } - fn update_button_press(&self, button: rdev::Button) { + fn update_button_press(&self, button: Button) { if let Err(e) = self.button_pressed.lock().map(|mut pressed| { *pressed = Some(button); }) { @@ -279,7 +281,7 @@ impl InputListener { } } - pub fn get_last_button_pressed(&self) -> Option { + pub fn get_last_button_pressed(&self) -> Option