mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 15:04:36 +03:00
Add HideApplication and QuitApplication key assignments
``` [[keys]] key = "q" mods = "CMD" action = "QuitApplication" ``` refs: https://github.com/wez/wezterm/issues/150
This commit is contained in:
parent
da6783bbd0
commit
754f8166b5
@ -14,6 +14,11 @@ brief notes about them may accumulate here.
|
||||
size of new terminal windows
|
||||
* Added `hide_tab_bar_if_only_one_tab = true` config option to hide the tab
|
||||
bar when the window contains only a single tab.
|
||||
* Added `HideApplication` key action (defaults to `CMD-H` on macOS only) which
|
||||
hides the wezterm application. This is macOS specific.
|
||||
* Added `QuitApplication` key action which causes the gui loop to terminate
|
||||
and the application to exit. This is not bound by default, but you may
|
||||
choose to assign it to something like `CMD-Q`.
|
||||
|
||||
### 20200202-181957-765184e5
|
||||
|
||||
|
@ -38,6 +38,8 @@ impl std::convert::TryInto<KeyAssignment> for &Key {
|
||||
KeyAction::Copy => KeyAssignment::Copy,
|
||||
KeyAction::Paste => KeyAssignment::Paste,
|
||||
KeyAction::Hide => KeyAssignment::Hide,
|
||||
KeyAction::HideApplication => KeyAssignment::HideApplication,
|
||||
KeyAction::QuitApplication => KeyAssignment::QuitApplication,
|
||||
KeyAction::Show => KeyAssignment::Show,
|
||||
KeyAction::IncreaseFontSize => KeyAssignment::IncreaseFontSize,
|
||||
KeyAction::DecreaseFontSize => KeyAssignment::DecreaseFontSize,
|
||||
@ -103,6 +105,8 @@ pub enum KeyAction {
|
||||
SendString,
|
||||
Nop,
|
||||
Hide,
|
||||
HideApplication,
|
||||
QuitApplication,
|
||||
Show,
|
||||
CloseCurrentTab,
|
||||
ReloadConfiguration,
|
||||
|
@ -1250,6 +1250,14 @@ impl TermWindow {
|
||||
MoveTabRelative(n) => self.move_tab_relative(*n)?,
|
||||
ScrollByPage(n) => self.scroll_by_page(*n)?,
|
||||
ShowTabNavigator => self.show_tab_navigator(),
|
||||
HideApplication => {
|
||||
let con = Connection::get().expect("call on gui thread");
|
||||
con.hide_application();
|
||||
}
|
||||
QuitApplication => {
|
||||
let con = Connection::get().expect("call on gui thread");
|
||||
con.terminate_message_loop();
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ pub enum KeyAssignment {
|
||||
MoveTab(usize),
|
||||
ScrollByPage(isize),
|
||||
ShowTabNavigator,
|
||||
HideApplication,
|
||||
QuitApplication,
|
||||
}
|
||||
|
||||
pub struct KeyMap(HashMap<(KeyCode, KeyModifiers), KeyAssignment>);
|
||||
@ -150,6 +152,9 @@ impl KeyMap {
|
||||
[KeyModifiers::ALT, KeyCode::Char('9'), ShowTabNavigator],
|
||||
);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
m!([KeyModifiers::SUPER, KeyCode::Char('h'), HideApplication],);
|
||||
|
||||
Self(map)
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,11 @@ pub trait ConnectionOps {
|
||||
fn terminate_message_loop(&self);
|
||||
fn run_message_loop(&self) -> Fallible<()>;
|
||||
|
||||
/// Hide the application.
|
||||
/// This actions hides all of the windows of the application and switches
|
||||
/// focus away from it.
|
||||
fn hide_application(&self) {}
|
||||
|
||||
// TODO: return a handle that can be used to cancel the timer
|
||||
fn schedule_timer<F: FnMut() + 'static>(&self, interval: std::time::Duration, callback: F);
|
||||
}
|
||||
|
@ -85,6 +85,12 @@ impl ConnectionOps for Connection {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hide_application(&self) {
|
||||
unsafe {
|
||||
let () = msg_send![self.ns_app, hide: self.ns_app];
|
||||
}
|
||||
}
|
||||
|
||||
fn schedule_timer<F: FnMut() + 'static>(&self, interval: std::time::Duration, callback: F) {
|
||||
let secs_f64 =
|
||||
(interval.as_secs() as f64) + (f64::from(interval.subsec_nanos()) / 1_000_000_000_f64);
|
||||
|
Loading…
Reference in New Issue
Block a user