1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 14:22:37 +03:00

add Hide/Show key actions

Usage example is to put this in your `wezterm.toml` to get the
macOS CMD-M shortcut for minimizing a window:

```
[[keys]]
key = "m"
mods = "CMD"
action = "Hide"
```

Refs: https://github.com/wez/wezterm/issues/32
This commit is contained in:
Wez Furlong 2019-06-08 08:37:50 -07:00
parent 3b94cddf8e
commit f10e59245e
4 changed files with 34 additions and 0 deletions

View File

@ -104,6 +104,8 @@ impl std::convert::TryInto<KeyAssignment> for &Key {
KeyAction::ToggleFullScreen => KeyAssignment::ToggleFullScreen,
KeyAction::Copy => KeyAssignment::Copy,
KeyAction::Paste => KeyAssignment::Paste,
KeyAction::Hide => KeyAssignment::Hide,
KeyAction::Show => KeyAssignment::Show,
KeyAction::IncreaseFontSize => KeyAssignment::IncreaseFontSize,
KeyAction::DecreaseFontSize => KeyAssignment::DecreaseFontSize,
KeyAction::ResetFontSize => KeyAssignment::ResetFontSize,
@ -144,6 +146,8 @@ pub enum KeyAction {
ActivateTab,
SendString,
Nop,
Hide,
Show,
}
fn de_keycode<'de, D>(deserializer: D) -> Result<KeyCode, D::Error>

View File

@ -101,6 +101,15 @@ impl TerminalWindow for GliumTerminalWindow {
Ok(())
}
fn hide_window(&mut self) {
eprintln!("Hide");
self.host.display.gl_window().hide();
}
fn show_window(&mut self) {
self.host.display.gl_window().show();
}
fn frame(&self) -> glium::Frame {
self.host.display.draw()
}

View File

@ -29,6 +29,8 @@ pub enum KeyAssignment {
ActivateTab(usize),
SendString(String),
Nop,
Hide,
Show,
}
pub trait HostHelper {
@ -166,6 +168,8 @@ impl<H: HostHelper> HostImpl<H> {
ResetFontSize => self.reset_font_size(),
ActivateTab(n) => self.activate_tab(*n),
SendString(s) => tab.writer().write_all(s.as_bytes())?,
Hide => self.hide_window(),
Show => self.show_window(),
Nop => {}
}
Ok(())
@ -269,6 +273,20 @@ impl<H: HostHelper> HostImpl<H> {
win.scaling_changed(Some(1.0), None, dims.width, dims.height)
})
}
pub fn hide_window(&mut self) {
self.with_window(move |win| {
win.hide_window();
Ok(())
});
}
pub fn show_window(&mut self) {
self.with_window(move |win| {
win.show_window();
Ok(())
});
}
}
impl<H: HostHelper> Deref for HostImpl<H> {

View File

@ -45,6 +45,9 @@ pub trait TerminalWindow {
Ok(())
}
fn hide_window(&mut self) {}
fn show_window(&mut self) {}
fn activate_tab(&mut self, tab_idx: usize) -> Result<(), Error> {
let mux = Mux::get().unwrap();
let mut window = mux