aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuomas Siipola <siiptuo@kapsi.fi>2017-02-22 21:52:37 +0200
committerJoe Wilm <jwilm@users.noreply.github.com>2017-02-22 14:49:29 -0800
commit7bb49fabfa0d2686e4e74c1c11362d6b6aade1ca (patch)
tree6d8512f2bc7d75be76d656a8d019e9e5ed90204e
parent418df72a077cd85b14cbede78e281bb224515a40 (diff)
downloadalacritty-7bb49fabfa0d2686e4e74c1c11362d6b6aade1ca.tar.gz
alacritty-7bb49fabfa0d2686e4e74c1c11362d6b6aade1ca.zip
Add hide cursor when typing option
-rw-r--r--alacritty.yml2
-rw-r--r--alacritty_macos.yml2
-rw-r--r--src/config.rs11
-rw-r--r--src/event.rs14
-rw-r--r--src/window.rs7
5 files changed, 36 insertions, 0 deletions
diff --git a/alacritty.yml b/alacritty.yml
index ba44cf11..15ea4fa8 100644
--- a/alacritty.yml
+++ b/alacritty.yml
@@ -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.
diff --git a/alacritty_macos.yml b/alacritty_macos.yml
index 98a0ee63..8f024dbc 100644
--- a/alacritty_macos.yml
+++ b/alacritty_macos.yml
@@ -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.
diff --git a/src/config.rs b/src/config.rs
index 3be8e4c8..bab2cc20 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -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())?;
diff --git a/src/event.rs b/src/event.rs
index 9a7d2e8e..d6b0796a 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -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;
diff --git a/src/window.rs b/src/window.rs
index a5f6e2c6..b90c242d 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -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 {