From aa9942e6d4ea9e5295c1f0d055411cebafe627bf Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 23 Feb 2019 17:11:23 -0800 Subject: [PATCH] spawned windows no longer inherit scaling On hidpi displays we'd end up with a window twice the size; whoops! --- src/font/mod.rs | 12 ++++++++++++ src/gliumwindows.rs | 2 +- src/guiloop/x11.rs | 4 ++-- src/main.rs | 10 ++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/font/mod.rs b/src/font/mod.rs index 731d6b99a..7e5b254a9 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -131,6 +131,18 @@ impl FontConfiguration { } } + /// Used when spawning a window to start with an unscaled font configuration + pub fn clone_unscaled(&self) -> Rc { + Rc::new(Self { + config: Rc::clone(&self.config), + fonts: RefCell::new(HashMap::new()), + system: Rc::clone(&self.system), + metrics: RefCell::new(None), + font_scale: RefCell::new(1.0), + dpi_scale: RefCell::new(1.0), + }) + } + /// Given a text style, load (with caching) the font that best /// matches according to the fontconfig pattern. pub fn cached_font(&self, style: &TextStyle) -> Result>>, Error> { diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index ed5f183ae..528a3e5d8 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -134,7 +134,7 @@ impl<'a> term::TerminalHost for TabHost<'a> { let config = Rc::clone(&self.host.config); let fonts = Rc::clone(&self.host.fonts); self.host.event_loop.spawn_fn(move || { - let (terminal, master, child) = spawn_window_impl(None, &config, &fonts)?; + let (terminal, master, child, fonts) = spawn_window_impl(None, &config, &fonts)?; let window = TerminalWindow::new(&event_loop, terminal, master, child, &fonts, &config)?; diff --git a/src/guiloop/x11.rs b/src/guiloop/x11.rs index f6ea85e46..0f0eff0ab 100644 --- a/src/guiloop/x11.rs +++ b/src/guiloop/x11.rs @@ -244,9 +244,9 @@ impl GuiEventLoop { config: &Rc, fontconfig: &Rc, ) -> Result<(), Error> { - let (terminal, master, child) = spawn_window_impl(None, config, fontconfig)?; + let (terminal, master, child, fontconfig) = spawn_window_impl(None, config, fontconfig)?; - let window = TerminalWindow::new(event_loop, terminal, master, child, fontconfig, config)?; + let window = TerminalWindow::new(event_loop, terminal, master, child, &fontconfig, config)?; self.add_window(window) } diff --git a/src/main.rs b/src/main.rs index e1a9d94b6..5d1a83704 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,9 +127,11 @@ fn spawn_window_impl( cmd: Option>, config: &Rc, fontconfig: &Rc, -) -> Result<(term::Terminal, MasterPty, Child), Error> { +) -> Result<(term::Terminal, MasterPty, Child, Rc), Error> { let cmd = config.build_prog(cmd)?; + let fontconfig = fontconfig.clone_unscaled(); + // First step is to figure out the font metrics so that we know how // big things are going to be. // we always load the cell_height for font 0, @@ -159,7 +161,7 @@ fn spawn_window_impl( config.hyperlink_rules.clone(), ); - Ok((terminal, master, child)) + Ok((terminal, master, child, fontconfig)) } fn spawn_window( @@ -168,7 +170,7 @@ fn spawn_window( config: &Rc, fontconfig: &Rc, ) -> Result<(), Error> { - let (terminal, master, child) = spawn_window_impl(cmd, config, fontconfig)?; + let (terminal, master, child, fontconfig) = spawn_window_impl(cmd, config, fontconfig)?; - gui.spawn_new_window(terminal, master, child, config, fontconfig) + gui.spawn_new_window(terminal, master, child, config, &fontconfig) }