Center the grid inside the window

Currently alacritty always puts the grid at the top-left position of the
window. The only distance to the top-left window border is set by the
padding in the config.

However the grid always has a fixed size, and if a cell doesn't
completely fit the screen anymore, the padding at the bottom right
window corner can be significantly bigger than the padding at the top
left.

To fix this whenever there is more space left and there would usually be
a bigger padding at the bottom right, the space is now split up and
added to the padding.

This should always center the grid inside the window and make sure all
borders have the same padding from the text area.

This screenshot shows how it has been until now:
![Before](https://u.teknik.io/kRJwg.png)

Here is how it looks now:
![After](https://u.teknik.io/m4puV.png)

This fixes #1065.
This commit is contained in:
Christian Duerr 2018-11-11 20:24:41 +00:00 committed by GitHub
parent dba3cccf69
commit 6a0bd7409d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 29 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moved `unfocused_hollow_cursor` to `cursor.unfocused_hollow`
- Moved `hide_cursor_when_typing` to `mouse.hide_when_typing`
- Mouse bindings now ignore additional modifiers
- Extra padding is now spread evenly around the terminal grid
### Removed

26
Cargo.lock generated
View File

@ -74,7 +74,7 @@ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rusttype 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -686,7 +686,7 @@ 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)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1410,7 +1410,7 @@ dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1422,7 +1422,7 @@ 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)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1863,7 +1863,7 @@ dependencies = [
[[package]]
name = "ryu"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -1948,7 +1948,7 @@ 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)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1957,7 +1957,7 @@ version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2094,7 +2094,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.15.18"
version = "0.15.19"
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)",
@ -2109,7 +2109,7 @@ 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)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.18 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2503,7 +2503,7 @@ dependencies = [
[[package]]
name = "walkdir"
version = "2.2.6"
version = "2.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2964,7 +2964,7 @@ dependencies = [
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rusttype 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "11ff03da02f6d340bbee5ec55eed03ff9abd6ea013b93bc7c35973cc28f65999"
"checksum rusttype 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b8eb11f5b0a98c8eca2fb1483f42646d8c340e83e46ab416f8a063a0fd0eeb20"
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56"
@ -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.18 (registry+https://github.com/rust-lang/crates.io-index)" = "90c39a061e2f412a9f869540471ab679e85e50c6b05604daf28bc3060f75c430"
"checksum syn 0.15.19 (registry+https://github.com/rust-lang/crates.io-index)" = "39054bb43f2c5e4f3aef47718a391bf397c1b820fefc86f467d4d354f67bf7ef"
"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"
@ -3037,7 +3037,7 @@ dependencies = [
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum vte 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4f42f536e22f7fcbb407639765c8fd78707a33109301f834a594758bedd6e8cf"
"checksum walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0ffb549f212c31e19f3667c55a7f515b983a84aef10fd0a4d1f9c125425115f3"
"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1"
"checksum want 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a05d9d966753fa4b5c8db73fcab5eed4549cfe0e1e4e66911e5564a0085c35d1"
"checksum wayland-client 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ff03d0651389f99aba804e89685c6211fc1d66fb3c234ed52d028904675adbcb"
"checksum wayland-commons 0.21.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6f06d6b155a2be033ee1684fd084c1c1821e0d61d4c303f11fc9400a911fa24a"

View File

@ -163,7 +163,7 @@ impl Display {
f64::from(height + 2 * (f64::from(config.padding().y) * dpr) as u32) as f64);
window.set_inner_size(new_viewport_size.to_logical(dpr));
renderer.resize(new_viewport_size, dpr);
renderer.resize(new_viewport_size, dpr, cell_width as i32, cell_height as i32);
viewport_size = new_viewport_size;
}
@ -320,8 +320,11 @@ 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);
self.renderer.resize(psize, dpr, cw, ch);
}
}

View File

@ -303,7 +303,7 @@ impl GlyphCache {
// Recompute font keys
let font = font.to_owned().with_size(size);
let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?;
self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
let metrics = self.rasterizer.metrics(regular, size)?;
@ -748,20 +748,30 @@ impl QuadRenderer {
self.program = program;
}
pub fn resize(&mut self, size: PhysicalSize, dpr: f64) {
let (width, height) : (u32, u32) = size.into();
pub fn resize(&mut self, size: PhysicalSize, dpr: f64, cell_width: i32, cell_height: i32) {
let (width, height): (u32, u32) = size.into();
let (width, height) = (width as i32, height as i32);
let padding_x = (f64::from(self.program.padding_x) * dpr) as i32;
let padding_y = (f64::from(self.program.padding_y) * dpr) 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 {
gl::Viewport(padding_x, padding_y, (width as i32) - 2 * padding_x, (height as i32) - 2 * padding_y);
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, dpr as f32);
self.program.update_projection(
width as f32,
height as f32,
padding_x as f32,
padding_y as f32,
);
self.program.deactivate();
}
}
@ -1051,6 +1061,9 @@ 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,
@ -1058,21 +1071,18 @@ impl ShaderProgram {
u_cell_dim: cell_dim,
u_visual_bell: visual_bell,
u_background: background,
padding_x: config.padding().x,
padding_y: config.padding().y,
padding_x: padding_x as u8,
padding_y: padding_y as u8,
};
shader.update_projection(size.width as f32, size.height as f32, dpr as f32);
shader.update_projection(size.width as f32, size.height as f32, padding_x, padding_y);
shader.deactivate();
Ok(shader)
}
fn update_projection(&self, width: f32, height: f32, dpr: f32) {
let padding_x = (f32::from(self.padding_x) * dpr).floor();
let padding_y = (f32::from(self.padding_y) * dpr).floor();
fn update_projection(&self, width: f32, height: f32, padding_x: f32, padding_y: f32) {
// Bounds check
if (width as u32) < (2 * padding_x as u32) ||
(height as u32) < (2 * padding_y as u32)