Implement busy_start/stop cursor hiding
This commit is contained in:
parent
1a2e2a4d9b
commit
057fad0e87
@ -37,6 +37,7 @@ enum AnimPhase {
|
|||||||
Hidden,
|
Hidden,
|
||||||
Show,
|
Show,
|
||||||
NoFocus,
|
NoFocus,
|
||||||
|
Busy,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
@ -93,6 +94,14 @@ impl Cursor {
|
|||||||
self.state.borrow_mut().reset_to(AnimPhase::NoFocus);
|
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,
|
pub fn draw(&self,
|
||||||
ctx: &cairo::Context,
|
ctx: &cairo::Context,
|
||||||
shell: &Shell,
|
shell: &Shell,
|
||||||
@ -102,8 +111,13 @@ impl Cursor {
|
|||||||
double_width: bool,
|
double_width: bool,
|
||||||
bg: &Color) {
|
bg: &Color) {
|
||||||
|
|
||||||
let current_point = ctx.get_current_point();
|
|
||||||
let state = self.state.borrow();
|
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);
|
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 {
|
let cursor_width = if shell.mode == NvimMode::Insert {
|
||||||
@ -158,6 +172,7 @@ fn anim_step(state: &Arc<UiMutex<State>>) -> glib::Continue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
AnimPhase::NoFocus => None,
|
AnimPhase::NoFocus => None,
|
||||||
|
AnimPhase::Busy => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
SHELL!(&shell = {
|
SHELL!(&shell = {
|
||||||
|
10
src/nvim.rs
10
src/nvim.rs
@ -33,9 +33,9 @@ pub trait RedrawEvents {
|
|||||||
|
|
||||||
fn on_mode_change(&mut self, mode: &str) -> RepaintMode;
|
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 {
|
pub trait GuiApi {
|
||||||
@ -189,8 +189,10 @@ fn call(ui: &mut Shell, method: &str, args: &Vec<Value>) -> result::Result<Repai
|
|||||||
"update_fg" => ui.on_update_fg(try_int!(args[0])),
|
"update_fg" => ui.on_update_fg(try_int!(args[0])),
|
||||||
"update_sp" => ui.on_update_sp(try_int!(args[0])),
|
"update_sp" => ui.on_update_sp(try_int!(args[0])),
|
||||||
"mode_change" => ui.on_mode_change(try_str!(args[0])),
|
"mode_change" => ui.on_mode_change(try_str!(args[0])),
|
||||||
"mouse_on" => ui.on_mouse_on(),
|
"mouse_on" => ui.on_mouse(true),
|
||||||
"mouse_off" => ui.on_mouse_off(),
|
"mouse_off" => ui.on_mouse(false),
|
||||||
|
"busy_start" => ui.on_busy(true),
|
||||||
|
"busy_stop" => ui.on_busy(false),
|
||||||
_ => {
|
_ => {
|
||||||
println!("Event {}({:?})", method, args);
|
println!("Event {}({:?})", method, args);
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
|
14
src/shell.rs
14
src/shell.rs
@ -636,14 +636,18 @@ impl RedrawEvents for Shell {
|
|||||||
RepaintMode::Area(self.model.cur_point())
|
RepaintMode::Area(self.model.cur_point())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_mouse_on(&mut self) -> RepaintMode {
|
fn on_mouse(&mut self, on: bool) -> RepaintMode {
|
||||||
self.mouse_enabled = true;
|
self.mouse_enabled = on;
|
||||||
RepaintMode::Nothing
|
RepaintMode::Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_mouse_off(&mut self) -> RepaintMode {
|
fn on_busy(&mut self, busy: bool) -> RepaintMode {
|
||||||
self.mouse_enabled = false;
|
if busy {
|
||||||
RepaintMode::Nothing
|
self.cursor.busy_on();
|
||||||
|
} else {
|
||||||
|
self.cursor.busy_off();
|
||||||
|
}
|
||||||
|
RepaintMode::Area(self.model.cur_point())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user