Commit 3814622c authored by Christian Duerr's avatar Christian Duerr Committed by Peter van der meulen

Attach fixed DPR to resize events

Moving a window to a different screen which is a different DPI caused a
racing condition where the logical size of the event was sent to the
`handle_resize` method in `src/display.rs`, however if there was a DPI
change event before `handle_resize` is able to process this message, it
would incorrectly use the new DPI to scale the resize event.

To solve this issue instead of sending the logical size to the
`handle_resize` method and then converting it to a physical size in
there, the `LogicalSize` of the resize event is transformed into a
`PhysicalSize` as soon as it's received. This fixes potential racing
conditions since all events are processed in order.
parent ef82dfcd
......@@ -18,7 +18,7 @@ use std::sync::mpsc;
use parking_lot::{MutexGuard};
use {LogicalPosition, LogicalSize, PhysicalSize, Rgb};
use {LogicalPosition, PhysicalSize, Rgb};
use cli;
use config::Config;
use font::{self, Rasterize};
......@@ -94,8 +94,8 @@ pub struct Display {
renderer: QuadRenderer,
glyph_cache: GlyphCache,
render_timer: bool,
rx: mpsc::Receiver<LogicalSize>,
tx: mpsc::Sender<LogicalSize>,
rx: mpsc::Receiver<PhysicalSize>,
tx: mpsc::Sender<PhysicalSize>,
meter: Meter,
font_size: font::Size,
size_info: SizeInfo,
......@@ -261,7 +261,7 @@ impl Display {
}
#[inline]
pub fn resize_channel(&self) -> mpsc::Sender<LogicalSize> {
pub fn resize_channel(&self) -> mpsc::Sender<PhysicalSize> {
self.tx.clone()
}
......@@ -281,17 +281,17 @@ impl Display {
// events into one.
let mut new_size = None;
// Update the DPR
let dpr = self.window.hidpi_factor();
// Take most recent resize event, if any
while let Ok(sz) = self.rx.try_recv() {
while let Ok(size) = self.rx.try_recv() {
// Resize events are emitted via glutin/winit with logical sizes
// However the terminal, window and renderer use physical sizes
// so a conversion must be done here
new_size = Some(sz.to_physical(dpr));
new_size = Some(size);
}
// Update the DPR
let dpr = self.window.hidpi_factor();
// Font size/DPI factor modification detected
if terminal.font_size != self.font_size || dpr != self.size_info.dpr {
self.font_size = terminal.font_size;
......
......@@ -23,7 +23,7 @@ use term::{Term, SizeInfo, TermMode};
use util::limit;
use util::fmt::Red;
use window::Window;
use LogicalSize;
use PhysicalSize;
/// Byte sequences are sent to a `Notify` in response to some events
pub trait Notify {
......@@ -231,7 +231,7 @@ pub struct Processor<N> {
wait_for_event: bool,
notifier: N,
mouse: Mouse,
resize_tx: mpsc::Sender<LogicalSize>,
resize_tx: mpsc::Sender<PhysicalSize>,
ref_test: bool,
size_info: SizeInfo,
hide_cursor_when_typing: bool,
......@@ -260,7 +260,7 @@ impl<N: Notify> Processor<N> {
/// pty.
pub fn new(
notifier: N,
resize_tx: mpsc::Sender<LogicalSize>,
resize_tx: mpsc::Sender<PhysicalSize>,
options: &Options,
config: &Config,
ref_test: bool,
......@@ -296,9 +296,10 @@ impl<N: Notify> Processor<N> {
processor: &mut input::Processor<'a, ActionContext<'a, N>>,
event: Event,
ref_test: bool,
resize_tx: &mpsc::Sender<LogicalSize>,
resize_tx: &mpsc::Sender<PhysicalSize>,
hide_cursor: &mut bool,
window_is_focused: &mut bool,
dpr: f64,
) {
match event {
// Pass on device events
......@@ -331,7 +332,7 @@ impl<N: Notify> Processor<N> {
::std::process::exit(0);
},
Resized(lsize) => {
resize_tx.send(lsize).expect("send new size");
resize_tx.send(lsize.to_physical(dpr)).expect("send new size");
processor.ctx.terminal.dirty = true;
},
KeyboardInput { input, .. } => {
......@@ -453,6 +454,7 @@ impl<N: Notify> Processor<N> {
};
let mut window_is_focused = window.is_focused;
let dpr = window.hidpi_factor();
// Scope needed to that hide_cursor isn't borrowed after the scope
// ends.
......@@ -469,6 +471,7 @@ impl<N: Notify> Processor<N> {
resize_tx,
hide_cursor,
&mut window_is_focused,
dpr,
);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment