diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs index d7aeffece..3c8e24a9e 100644 --- a/config/src/keyassignment.rs +++ b/config/src/keyassignment.rs @@ -162,6 +162,7 @@ pub enum KeyAssignment { IncreaseFontSize, DecreaseFontSize, ResetFontSize, + ResetFontAndWindowSize, ActivateTab(isize), SendString(String), Nop, diff --git a/docs/changelog.md b/docs/changelog.md index 85f5b5b71..c35bc4e05 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -20,6 +20,7 @@ brief notes about them may accumulate here. * Wayland: fixed window decoration and full screen handling [#224](https://github.com/wez/wezterm/issues/224) * Wayland: fixed an issue where key repeat processing could "run away" and hang the application * New: added [foreground_text_hsb](config/lua/config/foreground_text_hsb.md) setting to adjust hue, saturation and brightness when text is rendered. +* New: added [ResetFontAndWindowSize](config/lua/keyassignment/ResetFontAndWindowSize.md) key assignment. ### 20210203-095643-70a364eb diff --git a/docs/config/lua/keyassignment/ResetFontAndWindowSize.md b/docs/config/lua/keyassignment/ResetFontAndWindowSize.md new file mode 100644 index 000000000..05e6bbfd7 --- /dev/null +++ b/docs/config/lua/keyassignment/ResetFontAndWindowSize.md @@ -0,0 +1,17 @@ +# ResetFontAndWindowSize + +*Since: nightly builds only* + +Reset both the font size and the terminal dimensions for the current window to +the values specified by your `font`, `initial_rows`, and `initial_cols` configuration. + +```lua +local wezterm = require 'wezterm'; +return { + keys = { + {key="0", mods="CTRL", action="ResetFontAndWindowSize"}, + } +} +``` + + diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs index f07a7cd98..d62f9cbc6 100644 --- a/wezterm-gui/src/gui/termwindow.rs +++ b/wezterm-gui/src/gui/termwindow.rs @@ -1976,6 +1976,7 @@ impl TermWindow { DecreaseFontSize => self.decrease_font_size(), IncreaseFontSize => self.increase_font_size(), ResetFontSize => self.reset_font_size(), + ResetFontAndWindowSize => self.reset_font_and_window_size()?, ActivateTab(n) => { self.activate_tab(*n)?; } @@ -2376,6 +2377,44 @@ impl TermWindow { self.adjust_font_scale(1.0); } + fn reset_font_and_window_size(&mut self) -> anyhow::Result<()> { + let config = configuration(); + let size = config.initial_size(); + let fontconfig = Rc::new(FontConfiguration::new()?); + let render_metrics = RenderMetrics::new(&fontconfig)?; + + let terminal_size = PtySize { + rows: size.rows as u16, + cols: size.cols as u16, + pixel_width: (render_metrics.cell_size.width as u16 * size.cols), + pixel_height: (render_metrics.cell_size.height as u16 * size.rows), + }; + + let show_tab_bar = config.enable_tab_bar && !config.hide_tab_bar_if_only_one_tab; + + let rows_with_tab_bar = if show_tab_bar { 1 } else { 0 } + terminal_size.rows; + let dimensions = Dimensions { + pixel_width: ((terminal_size.cols * render_metrics.cell_size.width as u16) + + config.window_padding.left + + effective_right_padding(&config, &render_metrics)) + as usize, + pixel_height: ((rows_with_tab_bar * render_metrics.cell_size.height as u16) + + config.window_padding.top + + config.window_padding.bottom) as usize, + dpi: config.dpi.unwrap_or(::window::DEFAULT_DPI) as usize, + }; + + self.apply_scale_change(&dimensions, 1.0); + self.apply_dimensions( + &dimensions, + Some(RowsAndCols { + rows: size.rows as usize, + cols: size.cols as usize, + }), + ); + Ok(()) + } + fn close_current_pane(&mut self, confirm: bool) { let mux_window_id = self.mux_window_id; let mux = Mux::get().unwrap();