mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Fix incorrect padding calculations
The extra window padding was calculated in the renderer which lead to problems with the paddings calculated in the `src/display.rs` and `src/term/mod.rs`. As a solution, every instance of `config.padding().x/y` has been removed from the renderer (`src/renderer/mod.rs`), instead the padding is always passed through from the `src/display.rs`. The initial calculations during display creation and after resize then are scaled appropriately and then the extra padding is calculated. As a result every other location can just make use of the correctly calculated `size_info.padding_x` and `size_info.padding_y`. This fixes #1773.
This commit is contained in:
parent
f182afafe5
commit
1e17838a25
3 changed files with 64 additions and 72 deletions
30
Cargo.lock
generated
30
Cargo.lock
generated
|
@ -22,7 +22,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "alacritty"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"arraydeque 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -684,9 +684,9 @@ name = "failure_derive"
|
|||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -1420,9 +1420,9 @@ version = "0.2.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1643,7 +1643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.21"
|
||||
version = "0.4.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1664,7 +1664,7 @@ name = "quote"
|
|||
version = "0.6.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1946,9 +1946,9 @@ name = "serde_derive"
|
|||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2094,10 +2094,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.19"
|
||||
version = "0.15.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -2107,9 +2107,9 @@ name = "synstructure"
|
|||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -2940,7 +2940,7 @@ dependencies = [
|
|||
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
|
||||
"checksum png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f54b9600d584d3b8a739e1662a595fab051329eff43f20e7d8cc22872962145b"
|
||||
"checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd"
|
||||
"checksum proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)" = "ab2fc21ba78ac73e4ff6b3818ece00be4e175ffbef4d0a717d978b48b24150c4"
|
||||
"checksum proc-macro2 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)" = "88dae56b29da695d783ea7fc5a90de281f79eb38407e77f6d674dd8befc4ac47"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
|
||||
|
@ -2993,7 +2993,7 @@ dependencies = [
|
|||
"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5"
|
||||
"checksum stb_truetype 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "48fa7d3136d8645909de1f7c7eb5416cc43057a75ace08fc39ae736bc9da8af1"
|
||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||
"checksum syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)" = "39054bb43f2c5e4f3aef47718a391bf397c1b820fefc86f467d4d354f67bf7ef"
|
||||
"checksum syn 0.15.20 (registry+https://github.com/rust-lang/crates.io-index)" = "8886c8d2774e853fcd7d9d2131f6e40ba46c9c0e358e4d57178452abd6859bb0"
|
||||
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
|
||||
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
|
||||
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
|
||||
|
|
|
@ -144,28 +144,33 @@ impl Display {
|
|||
.expect("glutin returns window size").to_physical(dpr);
|
||||
|
||||
// Create renderer
|
||||
let mut renderer = QuadRenderer::new(config, viewport_size, dpr)?;
|
||||
let mut renderer = QuadRenderer::new(viewport_size)?;
|
||||
|
||||
let (glyph_cache, cell_width, cell_height) =
|
||||
Self::new_glyph_cache(dpr, &mut renderer, config)?;
|
||||
|
||||
|
||||
let dimensions = options.dimensions()
|
||||
.unwrap_or_else(|| config.dimensions());
|
||||
|
||||
// Resize window to specified dimensions unless one or both dimensions are 0
|
||||
if dimensions.columns_u32() > 0 && dimensions.lines_u32() > 0 {
|
||||
debug_assert!(dimensions.columns_u32() > 0);
|
||||
debug_assert!(dimensions.lines_u32() > 0);
|
||||
|
||||
let width = cell_width as u32 * dimensions.columns_u32();
|
||||
let height = cell_height as u32 * dimensions.lines_u32();
|
||||
|
||||
let mut padding_x = config.padding().x as f64 * dpr;
|
||||
let mut padding_y = config.padding().y as f64 * dpr;
|
||||
padding_x = (padding_x + ((width as f64 - 2. * padding_x) % cell_width as f64) / 2.).floor();
|
||||
padding_y = (padding_y + ((height as f64 - 2. * padding_y) % cell_height as f64) / 2.).floor();
|
||||
|
||||
let new_viewport_size = PhysicalSize::new(
|
||||
f64::from(width + 2 * (f64::from(config.padding().x) * dpr) as u32),
|
||||
f64::from(height + 2 * (f64::from(config.padding().y) * dpr) as u32) as f64);
|
||||
f64::from(width) + 2. * padding_x,
|
||||
f64::from(height) + 2. * padding_y,
|
||||
);
|
||||
|
||||
window.set_inner_size(new_viewport_size.to_logical(dpr));
|
||||
renderer.resize(new_viewport_size, dpr, cell_width as i32, cell_height as i32);
|
||||
renderer.resize(new_viewport_size, padding_x as f32, padding_y as f32);
|
||||
viewport_size = new_viewport_size;
|
||||
}
|
||||
|
||||
info!("Cell Size: ({} x {})", cell_width, cell_height);
|
||||
|
||||
|
@ -175,8 +180,8 @@ impl Display {
|
|||
height: viewport_size.height as f32,
|
||||
cell_width: cell_width as f32,
|
||||
cell_height: cell_height as f32,
|
||||
padding_x: (f64::from(config.padding().x) * dpr).floor() as f32,
|
||||
padding_y: (f64::from(config.padding().y) * dpr).floor() as f32,
|
||||
padding_x: padding_x as f32,
|
||||
padding_y: padding_y as f32,
|
||||
};
|
||||
|
||||
// Channel for resize events
|
||||
|
@ -302,16 +307,27 @@ impl Display {
|
|||
|
||||
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_y = (f64::from(config.padding().y) * dpr).floor() as f32;
|
||||
|
||||
self.update_glyph_cache(config);
|
||||
}
|
||||
|
||||
// Receive any resize events; only call gl::Viewport on last
|
||||
// available
|
||||
if let Some(psize) = new_size.take() {
|
||||
self.size_info.width = psize.width as f32;
|
||||
self.size_info.height = psize.height as f32;
|
||||
let width = psize.width as f32;
|
||||
let height = psize.height as f32;
|
||||
let cell_width = self.size_info.cell_width;
|
||||
let cell_height = self.size_info.cell_height;
|
||||
|
||||
self.size_info.width = width;
|
||||
self.size_info.height = height;
|
||||
|
||||
let mut padding_x = f32::from(config.padding().x) * dpr as f32;
|
||||
let mut padding_y = f32::from(config.padding().y) * dpr as f32;
|
||||
padding_x = (padding_x + ((width - 2. * padding_x) % cell_width) / 2.).floor();
|
||||
padding_y = (padding_y + ((height - 2. * padding_y) % cell_height) / 2.).floor();
|
||||
self.size_info.padding_x = padding_x;
|
||||
self.size_info.padding_y = padding_y;
|
||||
|
||||
let size = &self.size_info;
|
||||
terminal.resize(size);
|
||||
|
@ -320,11 +336,8 @@ impl Display {
|
|||
item.on_resize(size)
|
||||
}
|
||||
|
||||
let cw = self.size_info.cell_width as i32;
|
||||
let ch = self.size_info.cell_height as i32;
|
||||
|
||||
self.window.resize(psize);
|
||||
self.renderer.resize(psize, dpr, cw, ch);
|
||||
self.renderer.resize(psize, padding_x, padding_y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,9 +118,6 @@ pub struct ShaderProgram {
|
|||
///
|
||||
/// Rendering is split into two passes; 1 for backgrounds, and one for text
|
||||
u_background: GLint,
|
||||
|
||||
padding_x: u8,
|
||||
padding_y: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -472,8 +469,8 @@ const ATLAS_SIZE: i32 = 1024;
|
|||
|
||||
impl QuadRenderer {
|
||||
// TODO should probably hand this a transform instead of width/height
|
||||
pub fn new(config: &Config, size: PhysicalSize, dpr: f64) -> Result<QuadRenderer, Error> {
|
||||
let program = ShaderProgram::new(config, size, dpr)?;
|
||||
pub fn new(size: PhysicalSize) -> Result<QuadRenderer, Error> {
|
||||
let program = ShaderProgram::new(size)?;
|
||||
|
||||
let mut vao: GLuint = 0;
|
||||
let mut vbo: GLuint = 0;
|
||||
|
@ -668,7 +665,7 @@ impl QuadRenderer {
|
|||
while let Ok(msg) = self.rx.try_recv() {
|
||||
match msg {
|
||||
Msg::ShaderReload => {
|
||||
self.reload_shaders(config, PhysicalSize::new(f64::from(props.width), f64::from(props.height)), props.dpr);
|
||||
self.reload_shaders(PhysicalSize::new(f64::from(props.width), f64::from(props.height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -720,9 +717,9 @@ impl QuadRenderer {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize, dpr: f64) {
|
||||
pub fn reload_shaders(&mut self, size: PhysicalSize) {
|
||||
warn!("Reloading shaders ...");
|
||||
let program = match ShaderProgram::new(config, size, dpr) {
|
||||
let program = match ShaderProgram::new(size) {
|
||||
Ok(program) => {
|
||||
warn!(" ... OK");
|
||||
program
|
||||
|
@ -748,30 +745,21 @@ impl QuadRenderer {
|
|||
self.program = program;
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, size: PhysicalSize, dpr: f64, cell_width: i32, cell_height: i32) {
|
||||
pub fn resize(&mut self, size: PhysicalSize, padding_x: f32, padding_y: f32) {
|
||||
let (width, height): (u32, u32) = size.into();
|
||||
let (width, height) = (width as i32, height as i32);
|
||||
|
||||
let mut padding_x = (f64::from(self.program.padding_x) * dpr) as i32;
|
||||
let mut padding_y = (f64::from(self.program.padding_y) * dpr) as i32;
|
||||
|
||||
// Add padding to center the grid inside the window
|
||||
padding_y += ((height - 2 * padding_y) % cell_height) / 2;
|
||||
padding_x += ((width - 2 * padding_x) % cell_width) / 2;
|
||||
|
||||
// viewport
|
||||
unsafe {
|
||||
let width = width as i32;
|
||||
let height = height as i32;
|
||||
let padding_x = padding_x as i32;
|
||||
let padding_y = padding_y as i32;
|
||||
gl::Viewport(padding_x, padding_y, width - 2 * padding_x, height - 2 * padding_y);
|
||||
}
|
||||
|
||||
// update projection
|
||||
self.program.activate();
|
||||
self.program.update_projection(
|
||||
width as f32,
|
||||
height as f32,
|
||||
padding_x as f32,
|
||||
padding_y as f32,
|
||||
);
|
||||
self.program.update_projection(width as f32, height as f32, padding_x, padding_y);
|
||||
self.program.deactivate();
|
||||
}
|
||||
}
|
||||
|
@ -1007,11 +995,7 @@ impl ShaderProgram {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
config: &Config,
|
||||
size: PhysicalSize,
|
||||
dpr: f64
|
||||
) -> Result<ShaderProgram, ShaderCreationError> {
|
||||
pub fn new(size: PhysicalSize) -> Result<ShaderProgram, ShaderCreationError> {
|
||||
let vertex_source = if cfg!(feature = "live-shader-reload") {
|
||||
None
|
||||
} else {
|
||||
|
@ -1061,9 +1045,6 @@ impl ShaderProgram {
|
|||
|
||||
assert_uniform_valid!(projection, term_dim, cell_dim);
|
||||
|
||||
let padding_x = (f32::from(config.padding().x) * dpr as f32).floor();
|
||||
let padding_y = (f32::from(config.padding().y) * dpr as f32).floor();
|
||||
|
||||
let shader = ShaderProgram {
|
||||
id: program,
|
||||
u_projection: projection,
|
||||
|
@ -1071,11 +1052,9 @@ impl ShaderProgram {
|
|||
u_cell_dim: cell_dim,
|
||||
u_visual_bell: visual_bell,
|
||||
u_background: background,
|
||||
padding_x: padding_x as u8,
|
||||
padding_y: padding_y as u8,
|
||||
};
|
||||
|
||||
shader.update_projection(size.width as f32, size.height as f32, padding_x, padding_y);
|
||||
shader.update_projection(size.width as f32, size.height as f32, 0., 0.);
|
||||
|
||||
shader.deactivate();
|
||||
|
||||
|
|
Loading…
Reference in a new issue