mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
WIP
This commit is contained in:
parent
31362dd3b8
commit
a35466169e
2 changed files with 42 additions and 35 deletions
|
@ -19,7 +19,7 @@ use std::f64;
|
||||||
|
|
||||||
use parking_lot::{MutexGuard};
|
use parking_lot::{MutexGuard};
|
||||||
|
|
||||||
use {LogicalPosition, PhysicalSize, Rgb};
|
use {LogicalPosition, LogicalSize, PhysicalSize, Rgb};
|
||||||
use cli;
|
use cli;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use font::{self, Rasterize};
|
use font::{self, Rasterize};
|
||||||
|
@ -30,6 +30,10 @@ use sync::FairMutex;
|
||||||
|
|
||||||
use window::{self, Window};
|
use window::{self, Window};
|
||||||
|
|
||||||
|
pub enum SizeOrDprChange {
|
||||||
|
Size(LogicalSize),
|
||||||
|
Dpr(f64),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
@ -95,8 +99,8 @@ pub struct Display {
|
||||||
renderer: QuadRenderer,
|
renderer: QuadRenderer,
|
||||||
glyph_cache: GlyphCache,
|
glyph_cache: GlyphCache,
|
||||||
render_timer: bool,
|
render_timer: bool,
|
||||||
rx: mpsc::Receiver<PhysicalSize>,
|
rx: mpsc::Receiver<SizeOrDprChange>,
|
||||||
tx: mpsc::Sender<PhysicalSize>,
|
tx: mpsc::Sender<SizeOrDprChange>,
|
||||||
meter: Meter,
|
meter: Meter,
|
||||||
font_size: font::Size,
|
font_size: font::Size,
|
||||||
size_info: SizeInfo,
|
size_info: SizeInfo,
|
||||||
|
@ -262,7 +266,7 @@ impl Display {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn resize_channel(&self) -> mpsc::Sender<PhysicalSize> {
|
pub fn resize_channel(&self) -> mpsc::Sender<SizeOrDprChange> {
|
||||||
self.tx.clone()
|
self.tx.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,42 +281,41 @@ impl Display {
|
||||||
config: &Config,
|
config: &Config,
|
||||||
items: &mut [&mut OnResize]
|
items: &mut [&mut OnResize]
|
||||||
) {
|
) {
|
||||||
// Resize events new_size and are handled outside the poll_events
|
// Get the latest logical size and dpr
|
||||||
// iterator. This has the effect of coalescing multiple resize
|
let mut dpr = self.size_info.dpr;
|
||||||
// events into one.
|
let mut lsize = None;
|
||||||
let mut new_size = None;
|
while let Ok(change) = self.rx.try_recv() {
|
||||||
|
match change {
|
||||||
// Take most recent resize event, if any
|
SizeOrDprChange::Size(new_lsize) => lsize = Some(new_lsize),
|
||||||
while let Ok(size) = self.rx.try_recv() {
|
SizeOrDprChange::Dpr(new_dpr) => dpr = new_dpr,
|
||||||
new_size = Some(size);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the DPR
|
let dpr_changed = (dpr - self.size_info.dpr).abs() > f64::EPSILON;
|
||||||
let dpr = self.window.hidpi_factor();
|
self.size_info.dpr = dpr;
|
||||||
|
|
||||||
// Font size/DPI factor modification detected
|
// Font size/DPI factor modification detected
|
||||||
if terminal.font_size != self.font_size || (dpr - self.size_info.dpr).abs() > f64::EPSILON {
|
if terminal.font_size != self.font_size || dpr_changed {
|
||||||
if new_size == None {
|
|
||||||
// Force a resize to refresh things
|
|
||||||
new_size = Some(PhysicalSize::new(
|
|
||||||
f64::from(self.size_info.width) / self.size_info.dpr * dpr,
|
|
||||||
f64::from(self.size_info.height) / self.size_info.dpr * dpr,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.font_size = terminal.font_size;
|
|
||||||
self.size_info.dpr = dpr;
|
|
||||||
self.size_info.padding_x = (f64::from(config.padding().x) * dpr).floor() as f32;
|
self.size_info.padding_x = (f64::from(config.padding().x) * dpr).floor() as f32;
|
||||||
self.size_info.padding_y = (f64::from(config.padding().y) * dpr).floor() as f32;
|
self.size_info.padding_y = (f64::from(config.padding().y) * dpr).floor() as f32;
|
||||||
|
self.font_size = terminal.font_size;
|
||||||
self.update_glyph_cache(config);
|
self.update_glyph_cache(config);
|
||||||
|
|
||||||
|
if lsize.is_none() {
|
||||||
|
// Force a resize to refresh things
|
||||||
|
lsize = Some(LogicalSize::new(
|
||||||
|
f64::from(self.size_info.width) / self.size_info.dpr,
|
||||||
|
f64::from(self.size_info.height) / self.size_info.dpr,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive any resize events; only call gl::Viewport on last
|
// Receive any resize events; only call gl::Viewport on last
|
||||||
// available
|
// available
|
||||||
if let Some(psize) = new_size.take() {
|
if let Some(lsize) = lsize.take() {
|
||||||
|
let psize = lsize.to_physical(dpr);
|
||||||
self.size_info.width = psize.width as f32;
|
self.size_info.width = psize.width as f32;
|
||||||
self.size_info.height = psize.height as f32;
|
self.size_info.height = psize.height as f32;
|
||||||
self.size_info.dpr = dpr;
|
|
||||||
|
|
||||||
let size = &self.size_info;
|
let size = &self.size_info;
|
||||||
terminal.resize(size);
|
terminal.resize(size);
|
||||||
|
|
20
src/event.rs
20
src/event.rs
|
@ -14,7 +14,7 @@ use ansi::{Handler, ClearMode};
|
||||||
use grid::Scroll;
|
use grid::Scroll;
|
||||||
use config::{self, Config};
|
use config::{self, Config};
|
||||||
use cli::Options;
|
use cli::Options;
|
||||||
use display::OnResize;
|
use display::{OnResize, SizeOrDprChange};
|
||||||
use index::{Line, Column, Side, Point};
|
use index::{Line, Column, Side, Point};
|
||||||
use input::{self, MouseBinding, KeyBinding};
|
use input::{self, MouseBinding, KeyBinding};
|
||||||
use selection::Selection;
|
use selection::Selection;
|
||||||
|
@ -23,7 +23,6 @@ use term::{Term, SizeInfo, TermMode};
|
||||||
use util::limit;
|
use util::limit;
|
||||||
use util::fmt::Red;
|
use util::fmt::Red;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
use PhysicalSize;
|
|
||||||
|
|
||||||
/// Byte sequences are sent to a `Notify` in response to some events
|
/// Byte sequences are sent to a `Notify` in response to some events
|
||||||
pub trait Notify {
|
pub trait Notify {
|
||||||
|
@ -229,7 +228,7 @@ pub struct Processor<N> {
|
||||||
wait_for_event: bool,
|
wait_for_event: bool,
|
||||||
notifier: N,
|
notifier: N,
|
||||||
mouse: Mouse,
|
mouse: Mouse,
|
||||||
resize_tx: mpsc::Sender<PhysicalSize>,
|
resize_tx: mpsc::Sender<SizeOrDprChange>,
|
||||||
ref_test: bool,
|
ref_test: bool,
|
||||||
size_info: SizeInfo,
|
size_info: SizeInfo,
|
||||||
hide_cursor_when_typing: bool,
|
hide_cursor_when_typing: bool,
|
||||||
|
@ -257,7 +256,7 @@ impl<N: Notify> Processor<N> {
|
||||||
/// pty.
|
/// pty.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
notifier: N,
|
notifier: N,
|
||||||
resize_tx: mpsc::Sender<PhysicalSize>,
|
resize_tx: mpsc::Sender<SizeOrDprChange>,
|
||||||
options: &Options,
|
options: &Options,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
ref_test: bool,
|
ref_test: bool,
|
||||||
|
@ -292,7 +291,7 @@ impl<N: Notify> Processor<N> {
|
||||||
processor: &mut input::Processor<'a, ActionContext<'a, N>>,
|
processor: &mut input::Processor<'a, ActionContext<'a, N>>,
|
||||||
event: Event,
|
event: Event,
|
||||||
ref_test: bool,
|
ref_test: bool,
|
||||||
resize_tx: &mpsc::Sender<PhysicalSize>,
|
resize_tx: &mpsc::Sender<SizeOrDprChange>,
|
||||||
hide_cursor: &mut bool,
|
hide_cursor: &mut bool,
|
||||||
window_is_focused: &mut bool,
|
window_is_focused: &mut bool,
|
||||||
) {
|
) {
|
||||||
|
@ -331,7 +330,7 @@ impl<N: Notify> Processor<N> {
|
||||||
// However the terminal, window and renderer use physical sizes
|
// However the terminal, window and renderer use physical sizes
|
||||||
// so a conversion must be done here
|
// so a conversion must be done here
|
||||||
resize_tx
|
resize_tx
|
||||||
.send(lsize.to_physical(processor.ctx.size_info.dpr))
|
.send(SizeOrDprChange::Size(lsize))
|
||||||
.expect("send new size");
|
.expect("send new size");
|
||||||
processor.ctx.terminal.dirty = true;
|
processor.ctx.terminal.dirty = true;
|
||||||
},
|
},
|
||||||
|
@ -386,8 +385,13 @@ impl<N: Notify> Processor<N> {
|
||||||
let path: String = path.to_string_lossy().into();
|
let path: String = path.to_string_lossy().into();
|
||||||
processor.ctx.write_to_pty(path.into_bytes());
|
processor.ctx.write_to_pty(path.into_bytes());
|
||||||
},
|
},
|
||||||
HiDpiFactorChanged(new_dpr) => {
|
HiDpiFactorChanged(dpr) => {
|
||||||
processor.ctx.size_info.dpr = new_dpr;
|
// 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
|
||||||
|
resize_tx
|
||||||
|
.send(SizeOrDprChange::Dpr(dpr))
|
||||||
|
.expect("send new size");
|
||||||
processor.ctx.terminal.dirty = true;
|
processor.ctx.terminal.dirty = true;
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
Loading…
Reference in a new issue