1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-03 04:34:21 -05:00

Add hide cursor when typing option

This commit is contained in:
Tuomas Siipola 2017-02-22 21:52:37 +02:00 committed by Joe Wilm
parent 418df72a07
commit 7bb49fabfa
5 changed files with 36 additions and 0 deletions

View file

@ -233,6 +233,8 @@ mouse:
selection:
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
hide_cursor_when_typing: false
# Shell
#
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.

View file

@ -232,6 +232,8 @@ mouse:
selection:
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
hide_cursor_when_typing: false
# Shell
#
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.

View file

@ -227,6 +227,10 @@ pub struct Config {
/// Visual bell configuration
#[serde(default)]
visual_bell: VisualBellConfig,
/// Hide cursor when typing
#[serde(default)]
hide_cursor_when_typing: bool,
}
#[cfg(not(target_os="macos"))]
@ -273,6 +277,7 @@ impl Default for Config {
config_path: None,
visual_bell: Default::default(),
env: Default::default(),
hide_cursor_when_typing: Default::default(),
}
}
}
@ -1008,6 +1013,12 @@ impl Config {
&self.env
}
/// Should hide cursor when typing
#[inline]
pub fn hide_cursor_when_typing(&self) -> bool {
self.hide_cursor_when_typing
}
fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
let path = path.into();
let raw = Config::read_file(path.as_path())?;

View file

@ -142,6 +142,8 @@ pub struct Processor<N> {
ref_test: bool,
size_info: SizeInfo,
pub selection: Selection,
hide_cursor_when_typing: bool,
hide_cursor: bool,
}
/// Notify that the terminal was resized
@ -178,6 +180,8 @@ impl<N: Notify> Processor<N> {
mouse: Default::default(),
selection: Default::default(),
size_info: size_info,
hide_cursor_when_typing: config.hide_cursor_when_typing(),
hide_cursor: false,
}
}
@ -189,6 +193,7 @@ impl<N: Notify> Processor<N> {
event: glutin::Event,
ref_test: bool,
resize_tx: &mpsc::Sender<(u32, u32)>,
hide_cursor: &mut bool,
) {
match event {
glutin::Event::Closed => {
@ -219,9 +224,11 @@ impl<N: Notify> Processor<N> {
processor.ctx.terminal.dirty = true;
},
glutin::Event::KeyboardInput(state, _code, key, mods, string) => {
*hide_cursor = true;
processor.process_key(state, key, mods, string);
},
glutin::Event::MouseInput(state, button) => {
*hide_cursor = false;
processor.mouse_input(state, button);
processor.ctx.terminal.dirty = true;
},
@ -229,6 +236,7 @@ impl<N: Notify> Processor<N> {
let x = limit(x, 0, processor.ctx.size_info.width as i32);
let y = limit(y, 0, processor.ctx.size_info.height as i32);
*hide_cursor = false;
processor.mouse_moved(x as u32, y as u32);
if !processor.ctx.selection.is_empty() {
@ -236,6 +244,7 @@ impl<N: Notify> Processor<N> {
}
},
glutin::Event::MouseWheel(scroll_delta, touch_phase) => {
*hide_cursor = false;
processor.on_mouse_wheel(scroll_delta, touch_phase);
},
glutin::Event::Focused(true) |
@ -275,6 +284,7 @@ impl<N: Notify> Processor<N> {
$event,
self.ref_test,
&self.resize_tx,
&mut self.hide_cursor,
)
}
}
@ -309,6 +319,10 @@ impl<N: Notify> Processor<N> {
for event in window.poll_events() {
process!(event);
}
if self.hide_cursor_when_typing {
window.set_cursor_visible(!self.hide_cursor);
}
}
self.wait_for_event = !terminal.dirty;

View file

@ -288,6 +288,13 @@ impl Window {
pub fn set_title(&self, title: &str) {
self.glutin_window.set_title(title);
}
/// Set cursor visible
#[inline]
pub fn set_cursor_visible(&self, show: bool) {
self.glutin_window.set_cursor(if show { glutin::MouseCursor::Default }
else { glutin::MouseCursor::NoneCursor });
}
}
impl Proxy {