idle timer wip

pull/821/head
Blaž Hrastnik 3 years ago
parent 8925fdd6f3
commit f99bea404f

@ -199,6 +199,11 @@ impl Application {
self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback); self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
self.render(); self.render();
} }
_ = &mut self.editor.idle_timer => {
self.editor.clear_idle_timer();
println!("idle!")
// idle timeout
}
} }
} }
} }

@ -901,6 +901,7 @@ impl Component for EditorView {
EventResult::Consumed(None) EventResult::Consumed(None)
} }
Event::Key(key) => { Event::Key(key) => {
cxt.editor.reset_idle_timer();
let mut key = KeyEvent::from(key); let mut key = KeyEvent::from(key);
canonicalize_key(&mut key); canonicalize_key(&mut key);
// clear status // clear status

@ -9,10 +9,12 @@ use crate::{
use futures_util::future; use futures_util::future;
use std::{ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
pin::Pin,
sync::Arc, sync::Arc,
time::Duration,
}; };
use tokio::time::{sleep, Duration, Instant, Sleep};
use slotmap::SlotMap; use slotmap::SlotMap;
use anyhow::Error; use anyhow::Error;
@ -91,6 +93,8 @@ pub struct Editor {
pub status_msg: Option<(String, Severity)>, pub status_msg: Option<(String, Severity)>,
pub config: Config, pub config: Config,
pub idle_timer: Pin<Box<Sleep>>,
} }
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
@ -125,10 +129,24 @@ impl Editor {
registers: Registers::default(), registers: Registers::default(),
clipboard_provider: get_clipboard_provider(), clipboard_provider: get_clipboard_provider(),
status_msg: None, status_msg: None,
idle_timer: Box::pin(sleep(Duration::from_millis(500))),
config, config,
} }
} }
pub fn clear_idle_timer(&mut self) {
// equivalent to internal Instant::far_future() (30 years)
self.idle_timer
.as_mut()
.reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
}
pub fn reset_idle_timer(&mut self) {
self.idle_timer
.as_mut()
.reset(Instant::now() + Duration::from_millis(500));
}
pub fn clear_status(&mut self) { pub fn clear_status(&mut self) {
self.status_msg = None; self.status_msg = None;
} }

Loading…
Cancel
Save