Add ResetFontAndWindowSize key assignment

closes: https://github.com/wez/wezterm/issues/480
This commit is contained in:
Wez Furlong committed 2021-02-20 21:50:20 -08:00
1 parent a91c0a5d98
commit 7a16e71e07
4 files changed
+58

No files matched your search

+1
View File
@@ -162,6 +162,7 @@ pub enum KeyAssignment {
IncreaseFontSize,
DecreaseFontSize,
ResetFontSize,
ResetFontAndWindowSize,
ActivateTab(isize),
SendString(String),
Nop,
+1
View File
@@ -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
@@ -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"},
}
}
```
+39
View File
@@ -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();