From c647b4e87cc363ddb787e95bd235265b58a6a83b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 24 Feb 2019 00:18:48 -0800 Subject: [PATCH] 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. --- src/gliumwindows.rs | 16 +++++++++++++++- src/guicommon/window.rs | 21 +++++++++++++++------ src/xwindows/xwin.rs | 6 ++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index 97968ad73..5bca9aaee 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -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 { + 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 { diff --git a/src/guicommon/window.rs b/src/guicommon/window.rs index 70bd4e356..5bc220b6f 100644 --- a/src/guicommon/window.rs +++ b/src/guicommon/window.rs @@ -35,6 +35,7 @@ pub trait TerminalWindow { fn config(&self) -> &Rc; fn fonts(&self) -> &Rc; fn get_dimensions(&self) -> Dimensions; + fn resize_if_not_full_screen(&mut self, width: u16, height: u16) -> Result; 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(()) } diff --git a/src/xwindows/xwin.rs b/src/xwindows/xwin.rs index 2899a9fc3..2d09d482c 100644 --- a/src/xwindows/xwin.rs +++ b/src/xwindows/xwin.rs @@ -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 { + // 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 {