From d661cf28946d55aa7d2de87b0021138330ce06fe Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 22 Feb 2018 23:50:52 -0800 Subject: [PATCH] take a stab at hidpi scaling for Jacob I noticed this looked crazy when he dragged the window between screens, so maybe this is better? --- src/gliumwindows.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index c29a2e40e..5317a4804 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -154,6 +154,14 @@ impl TerminalWindow { } fn resize_surfaces(&mut self, width: u16, height: u16) -> Result { + // Simple approach to hidpi displays; if the display factor is + // two (retina) then we want things to be twice as large so we + // simply divide by the scaling factor to have them take up + // twice as much space. OpenGL is going to scale things automatically. + let scale = self.host.display.gl_window().hidpi_factor(); + let width = (width as f32 / scale) as u16; + let height = (height as f32 / scale) as u16; + if width != self.width || height != self.height { debug!("resize {},{}", width, height); @@ -169,7 +177,6 @@ impl TerminalWindow { let cols = ((width as usize + 1) / self.cell_width) as u16; self.host.pty.resize(rows, cols, width, height)?; self.terminal.resize(rows as usize, cols as usize); - self.paint_if_needed()?; Ok(true) } else { @@ -403,6 +410,17 @@ impl TerminalWindow { } => { bail!("window close requested!"); } + Event::WindowEvent { + event: WindowEvent::HiDPIFactorChanged(_), + .. + } => { + // Assuming that this is dragging a window between hidpi and + // normal dpi displays. Treat this as a resize event of sorts + let size = self.host.display.gl_window().get_inner_size(); + if let Some((width, height)) = size { + self.resize_surfaces(width as u16, height as u16)?; + } + } Event::WindowEvent { event: WindowEvent::Resized(width, height), ..