Add binding action for hiding the window
This commit is contained in:
parent
0d5edb7a7a
commit
dbcb5885ad
|
@ -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 }
|
||||
|
|
|
@ -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)),
|
||||
}))
|
||||
|
|
36
src/event.rs
36
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
|
||||
|
|
13
src/input.rs
13
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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue