aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Leeb-du Toit <josh.leebdutoit@gmail.com>2018-07-22 10:38:53 +1000
committerChristian Duerr <chrisduerr@users.noreply.github.com>2018-07-22 00:38:53 +0000
commitdbcb5885adb1f0b23c29838ef8dd837212322409 (patch)
tree7fb3a64c39efd2693cac49885c9cc49cd9a28ac7
parent0d5edb7a7a7a33369bc2c1e5cc007edbd6fcf15f (diff)
downloadalacritty-dbcb5885adb1f0b23c29838ef8dd837212322409.tar.gz
alacritty-dbcb5885adb1f0b23c29838ef8dd837212322409.zip
Add binding action for hiding the window
-rw-r--r--alacritty_macos.yml1
-rw-r--r--src/config.rs3
-rw-r--r--src/event.rs36
-rw-r--r--src/input.rs13
-rw-r--r--src/window.rs5
5 files changed, 56 insertions, 2 deletions
diff --git a/alacritty_macos.yml b/alacritty_macos.yml
index 4bd9c026..76a4db4a 100644
--- a/alacritty_macos.yml
+++ b/alacritty_macos.yml
@@ -273,6 +273,7 @@ key_bindings:
- { key: C, mods: Command, action: Copy }
- { key: Paste, action: Paste }
- { key: Copy, action: Copy }
+ - { key: H, mods: Command, action: Hide }
- { key: Q, mods: Command, action: Quit }
- { key: W, mods: Command, action: Quit }
- { key: Home, chars: "\x1bOH", mode: AppCursor }
diff --git a/src/config.rs b/src/config.rs
index 8d63a9c0..76daee05 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -549,7 +549,7 @@ impl<'a> de::Deserialize<'a> for ActionWrapper {
type Value = ActionWrapper;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, ResetFontSize, or Quit")
+ f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, ResetFontSize, Hide, or Quit")
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E>
@@ -562,6 +562,7 @@ impl<'a> de::Deserialize<'a> for ActionWrapper {
"IncreaseFontSize" => Action::IncreaseFontSize,
"DecreaseFontSize" => Action::DecreaseFontSize,
"ResetFontSize" => Action::ResetFontSize,
+ "Hide" => Action::Hide,
"Quit" => Action::Quit,
_ => return Err(E::invalid_value(Unexpected::Str(value), &self)),
}))
diff --git a/src/event.rs b/src/event.rs
index c10f8a72..7e8a955c 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -40,6 +40,7 @@ pub struct ActionContext<'a, N: 'a> {
pub received_count: &'a mut usize,
pub suppress_chars: &'a mut bool,
pub last_modifiers: &'a mut ModifiersState,
+ pub window_changes: &'a mut WindowChanges,
}
impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
@@ -133,6 +134,33 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
fn last_modifiers(&mut self) -> &mut ModifiersState {
&mut self.last_modifiers
}
+
+ #[inline]
+ fn hide_window(&mut self) {
+ self.window_changes.hide = true;
+ }
+}
+
+/// The ActionContext can't really have direct access to the Window
+/// with the current design. Event handlers that want to change the
+/// window must set these flags instead. The processor will trigger
+/// the actual changes.
+pub struct WindowChanges {
+ pub hide: bool,
+}
+
+impl WindowChanges {
+ fn clear(&mut self) {
+ self.hide = false;
+ }
+}
+
+impl Default for WindowChanges {
+ fn default() -> WindowChanges {
+ WindowChanges {
+ hide: false,
+ }
+ }
}
pub enum ClickState {
@@ -199,6 +227,7 @@ pub struct Processor<N> {
suppress_chars: bool,
last_modifiers: ModifiersState,
pending_events: Vec<Event>,
+ window_changes: WindowChanges,
}
/// Notify that the terminal was resized
@@ -242,6 +271,7 @@ impl<N: Notify> Processor<N> {
suppress_chars: false,
last_modifiers: Default::default(),
pending_events: Vec::with_capacity(4),
+ window_changes: Default::default(),
}
}
@@ -401,6 +431,7 @@ impl<N: Notify> Processor<N> {
received_count: &mut self.received_count,
suppress_chars: &mut self.suppress_chars,
last_modifiers: &mut self.last_modifiers,
+ window_changes: &mut self.window_changes,
};
processor = input::Processor {
@@ -448,6 +479,11 @@ impl<N: Notify> Processor<N> {
}
}
+ if self.window_changes.hide {
+ window.hide();
+ }
+
+ self.window_changes.clear();
self.wait_for_event = !terminal.dirty;
terminal
diff --git a/src/input.rs b/src/input.rs
index bc33094a..52775678 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -66,6 +66,7 @@ pub trait ActionContext {
fn last_modifiers(&mut self) -> &mut ModifiersState;
fn change_font_size(&mut self, delta: f32);
fn reset_font_size(&mut self);
+ fn hide_window(&mut self);
}
/// Describes a state and action to take in that state
@@ -170,6 +171,9 @@ pub enum Action {
/// Run given command
Command(String, Vec<String>),
+ /// Hides the Alacritty window
+ Hide,
+
/// Quits Alacritty.
Quit,
}
@@ -224,6 +228,9 @@ impl Action {
},
}
},
+ Action::Hide => {
+ ctx.hide_window();
+ },
Action::Quit => {
// FIXME should do a more graceful shutdown
::std::process::exit(0);
@@ -626,7 +633,7 @@ mod tests {
use glutin::{VirtualKeyCode, Event, WindowEvent, ElementState, MouseButton, ModifiersState};
use term::{SizeInfo, Term, TermMode};
- use event::{Mouse, ClickState};
+ use event::{Mouse, ClickState, WindowChanges};
use config::{self, Config, ClickHandler};
use index::{Point, Side};
use selection::Selection;
@@ -651,6 +658,7 @@ mod tests {
pub received_count: usize,
pub suppress_chars: bool,
pub last_modifiers: ModifiersState,
+ pub window_changes: &'a mut WindowChanges,
}
impl <'a>super::ActionContext for ActionContext<'a> {
@@ -704,6 +712,8 @@ mod tests {
}
fn reset_font_size(&mut self) {
}
+ fn hide_window(&mut self) {
+ }
}
macro_rules! test_clickstate {
@@ -742,6 +752,7 @@ mod tests {
received_count: 0,
suppress_chars: false,
last_modifiers: ModifiersState::default(),
+ window_changes: &mut WindowChanges::default(),
};
let mut processor = Processor {
diff --git a/src/window.rs b/src/window.rs
index 1903360f..51a42232 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -379,6 +379,11 @@ impl Window {
pub fn get_window_id(&self) -> Option<usize> {
None
}
+
+ /// Hide the window
+ pub fn hide(&self) {
+ self.window.hide();
+ }
}
pub trait OsExtensions {