From 057fad0e8728612efb1bf6fa65e357bef5d3c4c8 Mon Sep 17 00:00:00 2001 From: daa84 Date: Mon, 3 Apr 2017 18:16:04 +0300 Subject: [PATCH] Implement busy_start/stop cursor hiding --- src/cursor.rs | 17 ++++++++++++++++- src/nvim.rs | 10 ++++++---- src/shell.rs | 14 +++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/cursor.rs b/src/cursor.rs index ee499d0..8b5e236 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -37,6 +37,7 @@ enum AnimPhase { Hidden, Show, NoFocus, + Busy, } struct State { @@ -93,6 +94,14 @@ impl Cursor { self.state.borrow_mut().reset_to(AnimPhase::NoFocus); } + pub fn busy_on(&mut self) { + self.state.borrow_mut().reset_to(AnimPhase::Busy); + } + + pub fn busy_off(&mut self) { + self.start(); + } + pub fn draw(&self, ctx: &cairo::Context, shell: &Shell, @@ -102,8 +111,13 @@ impl Cursor { double_width: bool, bg: &Color) { - let current_point = ctx.get_current_point(); let state = self.state.borrow(); + + if state.anim_phase == AnimPhase::Busy { + return; + } + + let current_point = ctx.get_current_point(); ctx.set_source_rgba(1.0 - bg.0, 1.0 - bg.1, 1.0 - bg.2, 0.6 * state.alpha.0); let cursor_width = if shell.mode == NvimMode::Insert { @@ -158,6 +172,7 @@ fn anim_step(state: &Arc>) -> glib::Continue { } } AnimPhase::NoFocus => None, + AnimPhase::Busy => None, }; SHELL!(&shell = { diff --git a/src/nvim.rs b/src/nvim.rs index a3e9394..feac23d 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -33,9 +33,9 @@ pub trait RedrawEvents { fn on_mode_change(&mut self, mode: &str) -> RepaintMode; - fn on_mouse_on(&mut self) -> RepaintMode; + fn on_mouse(&mut self, on: bool) -> RepaintMode; - fn on_mouse_off(&mut self) -> RepaintMode; + fn on_busy(&mut self, busy: bool) -> RepaintMode; } pub trait GuiApi { @@ -189,8 +189,10 @@ fn call(ui: &mut Shell, method: &str, args: &Vec) -> result::Result ui.on_update_fg(try_int!(args[0])), "update_sp" => ui.on_update_sp(try_int!(args[0])), "mode_change" => ui.on_mode_change(try_str!(args[0])), - "mouse_on" => ui.on_mouse_on(), - "mouse_off" => ui.on_mouse_off(), + "mouse_on" => ui.on_mouse(true), + "mouse_off" => ui.on_mouse(false), + "busy_start" => ui.on_busy(true), + "busy_stop" => ui.on_busy(false), _ => { println!("Event {}({:?})", method, args); RepaintMode::Nothing diff --git a/src/shell.rs b/src/shell.rs index 6b367cb..4ce1aab 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -636,14 +636,18 @@ impl RedrawEvents for Shell { RepaintMode::Area(self.model.cur_point()) } - fn on_mouse_on(&mut self) -> RepaintMode { - self.mouse_enabled = true; + fn on_mouse(&mut self, on: bool) -> RepaintMode { + self.mouse_enabled = on; RepaintMode::Nothing } - fn on_mouse_off(&mut self) -> RepaintMode { - self.mouse_enabled = false; - RepaintMode::Nothing + fn on_busy(&mut self, busy: bool) -> RepaintMode { + if busy { + self.cursor.busy_on(); + } else { + self.cursor.busy_off(); + } + RepaintMode::Area(self.model.cur_point()) } }