Make cursor reset animation state on input

This commit is contained in:
daa 2017-03-26 00:38:22 +03:00
parent e9839b641d
commit e020a5825b
2 changed files with 21 additions and 12 deletions

View File

@ -37,7 +37,7 @@ enum AnimPhase {
Show,
}
pub struct State {
struct State {
alpha: Alpha,
anim_phase: AnimPhase,
@ -45,13 +45,18 @@ pub struct State {
}
impl State {
pub fn new() -> State {
fn new() -> State {
State {
alpha: Alpha(1.0),
anim_phase: AnimPhase::Shown,
timer: None,
}
}
fn reset(&mut self) {
self.alpha = Alpha(1.0);
self.anim_phase = AnimPhase::Shown;
}
}
pub struct Cursor {
@ -61,18 +66,22 @@ pub struct Cursor {
impl Cursor {
pub fn new() -> Cursor {
Cursor {
state: Arc::new(Mutex::new(State::new())),
}
Cursor { state: Arc::new(Mutex::new(State::new())) }
}
pub fn start(&mut self) {
let state = self.state.clone();
let mut mut_state = self.state.lock().unwrap();
if mut_state.timer.is_none() {
mut_state.timer = Some(glib::timeout_add(100, move || anim_step(&state)));
mut_state.reset();
if let Some(timer_id) = mut_state.timer {
glib::source_remove(timer_id);
}
mut_state.timer = Some(glib::timeout_add(500, move || anim_step(&state)));
}
pub fn reset_state(&mut self) {
self.start();
}
pub fn draw(&self,
@ -103,7 +112,6 @@ impl Cursor {
}
}
// [TODO]: Reset animation phase on events - 2017-03-24 11:33
fn anim_step(state: &Arc<Mutex<State>>) -> glib::Continue {
let moved_state = state.clone();
let mut mut_state = state.lock().unwrap();
@ -111,7 +119,7 @@ fn anim_step(state: &Arc<Mutex<State>>) -> glib::Continue {
let next_event = match mut_state.anim_phase {
AnimPhase::Shown => {
mut_state.anim_phase = AnimPhase::Hide;
Some(100)
Some(60)
}
AnimPhase::Hide => {
if !mut_state.alpha.hide(0.3) {
@ -125,7 +133,7 @@ fn anim_step(state: &Arc<Mutex<State>>) -> glib::Continue {
AnimPhase::Hidden => {
mut_state.anim_phase = AnimPhase::Show;
Some(100)
Some(60)
}
AnimPhase::Show => {
if !mut_state.alpha.show(0.3) {

View File

@ -219,6 +219,7 @@ fn gtk_key_press(_: &DrawingArea, ev: &EventKey) -> Inhibit {
if let Some(input) = convert_key(ev) {
SHELL!(shell = {
shell.nvim().input(&input).expect("Error run input command to nvim");
shell.cursor.reset_state();
});
Inhibit(true)
} else {