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

When using glutin, scaling fonts resizes the terminal to preserve rows/cols

This could be implemented for xcb too, just didn't get around to it
yet.
This commit is contained in:
Wez Furlong 2019-02-24 00:18:48 -08:00
parent aef26084ef
commit c647b4e87c
3 changed files with 36 additions and 7 deletions

View File

@ -11,7 +11,7 @@ use crate::opengl::render::Renderer;
use crate::{spawn_window_impl, Child, MasterPty};
use clipboard::{ClipboardContext, ClipboardProvider};
use glium;
use glium::glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition};
use glium::glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
use glium::glutin::{self, ElementState, MouseCursor};
use std::cell::RefMut;
use std::io::Write;
@ -281,6 +281,20 @@ impl TerminalWindow for GliumTerminalWindow {
self.height = height;
self.renderer.resize(&self.host.display, width, height)
}
fn resize_if_not_full_screen(&mut self, width: u16, height: u16) -> Result<bool, Error> {
if self.host.is_fullscreen.is_none() {
{
let size = PhysicalSize::new(width.into(), height.into());
let window = self.host.display.gl_window();
let dpi = window.get_hidpi_factor();
window.set_inner_size(size.to_logical(dpi));
}
self.resize_surfaces(width, height, true)?;
Ok(true)
} else {
Ok(false)
}
}
}
impl GliumTerminalWindow {

View File

@ -35,6 +35,7 @@ pub trait TerminalWindow {
fn config(&self) -> &Rc<Config>;
fn fonts(&self) -> &Rc<FontConfiguration>;
fn get_dimensions(&self) -> Dimensions;
fn resize_if_not_full_screen(&mut self, width: u16, height: u16) -> Result<bool, Error>;
fn activate_tab(&mut self, tab_idx: usize) -> Result<(), Error> {
let max = self.get_tabs().len();
@ -203,17 +204,25 @@ pub trait TerminalWindow {
let metrics = fonts.default_font_metrics()?;
let (cell_height, cell_width) = (metrics.cell_height, metrics.cell_width);
// FIXME: our current behavior is to preserve the dimensions of the window,
// but vary the size of the font when scaling changes. This can result
// in the number of rows and columns changing when we should really preserve
// the terminal surface dimensions.
// It is desirable to preserve the terminal rows/cols when scaling,
// so we query for that information here.
// If the backend supports `resize_if_not_full_screen` then we'll try
// to resize the window to match the new cell metrics.
let (rows, cols) = {
let term = self.get_tabs().get_active().unwrap().terminal();
(term.screen().physical_rows, term.screen().physical_cols)
};
self.advise_renderer_that_scaling_has_changed(
cell_width.ceil() as usize,
cell_height.ceil() as usize,
)?;
self.resize_surfaces(width, height, true)?;
if !self.resize_if_not_full_screen(
cell_width.ceil() as u16 * cols as u16,
cell_height.ceil() as u16 * rows as u16,
)? {
self.resize_surfaces(width, height, true)?;
}
Ok(())
}

View File

@ -233,6 +233,12 @@ impl TerminalWindow for X11TerminalWindow {
self.height = height;
self.renderer.resize(&self.host.window, width, height)
}
fn resize_if_not_full_screen(&mut self, _width: u16, _height: u16) -> Result<bool, Error> {
// FIXME: it would be nice to implement this!
// It requires some plumbing to allow sending xcb_configure_window with
// XCB_CONFIG_WINDOW_WIDTH and XCB_CONFIG_WINDOW_HEIGHT set.
Ok(false)
}
}
impl X11TerminalWindow {