diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-11-11 02:27:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 02:27:18 -0500 |
commit | 9dc6d0c0d5766f431c31d5479ef97bbc54e25a63 (patch) | |
tree | f15b2dc529bedbadd51bfb8f1f752db780e575f7 /src/lib.rs | |
parent | 99fc5fc2c85b714c81ec6a7fca2615853e120caa (diff) |
other: remove the mouse throttler except for scroll events (#886)
The throttler is only really needed for scrolls (e.g. free scroll wheels
in Logitech mice), I don't really see it being needed in any other
contexts. Moves/drag is another one I guess but we outright ignore those
events right now.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 42 |
1 files changed, 22 insertions, 20 deletions
@@ -67,9 +67,9 @@ pub type Pid = usize; pub type Pid = libc::pid_t; #[derive(Debug)] -pub enum BottomEvent<I, J> { - KeyInput(I), - MouseInput(J), +pub enum BottomEvent { + KeyInput(KeyEvent), + MouseInput(MouseEvent), PasteEvent(String), Update(Box<data_harvester::Data>), Clean, @@ -410,8 +410,7 @@ pub fn update_data(app: &mut App) { } pub fn create_input_thread( - sender: Sender<BottomEvent<crossterm::event::KeyEvent, crossterm::event::MouseEvent>>, - termination_ctrl_lock: Arc<Mutex<bool>>, + sender: Sender<BottomEvent>, termination_ctrl_lock: Arc<Mutex<bool>>, ) -> JoinHandle<()> { thread::spawn(move || { let mut mouse_timer = Instant::now(); @@ -439,20 +438,23 @@ pub fn create_input_thread( break; } } - Event::Mouse(mouse) => { - if Instant::now().duration_since(mouse_timer).as_millis() >= 20 { - match mouse.kind { - MouseEventKind::Moved => {} - _ => { - if sender.send(BottomEvent::MouseInput(mouse)).is_err() - { - break; - } - mouse_timer = Instant::now(); + Event::Mouse(mouse) => match mouse.kind { + MouseEventKind::Moved | MouseEventKind::Drag(..) => {} + MouseEventKind::ScrollDown | MouseEventKind::ScrollUp => { + if Instant::now().duration_since(mouse_timer).as_millis() >= 20 + { + if sender.send(BottomEvent::MouseInput(mouse)).is_err() { + break; } + mouse_timer = Instant::now(); } } - } + _ => { + if sender.send(BottomEvent::MouseInput(mouse)).is_err() { + break; + } + } + }, _ => (), } } @@ -463,10 +465,10 @@ pub fn create_input_thread( } pub fn create_collection_thread( - sender: Sender<BottomEvent<crossterm::event::KeyEvent, crossterm::event::MouseEvent>>, - control_receiver: Receiver<ThreadControlEvent>, termination_ctrl_lock: Arc<Mutex<bool>>, - termination_ctrl_cvar: Arc<Condvar>, app_config_fields: &app::AppConfigFields, - filters: app::DataFilters, used_widget_set: UsedWidgets, + sender: Sender<BottomEvent>, control_receiver: Receiver<ThreadControlEvent>, + termination_ctrl_lock: Arc<Mutex<bool>>, termination_ctrl_cvar: Arc<Condvar>, + app_config_fields: &app::AppConfigFields, filters: app::DataFilters, + used_widget_set: UsedWidgets, ) -> JoinHandle<()> { let temp_type = app_config_fields.temperature_type; let use_current_cpu_total = app_config_fields.use_current_cpu_total; |