diff options
author | ii41 <23465321+ii41@users.noreply.github.com> | 2020-09-27 15:36:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-27 22:36:08 +0000 |
commit | a754d06b44139b85e8b34a71ece4477cb1caa85e (patch) | |
tree | 1733f8d17101947b6df5e1ad15b3fd64cf1db9a0 /alacritty/src/renderer | |
parent | e9c0034f4d3ee003149fe5454942bea7ff3d98be (diff) | |
download | r-alacritty-a754d06b44139b85e8b34a71ece4477cb1caa85e.tar.gz r-alacritty-a754d06b44139b85e8b34a71ece4477cb1caa85e.tar.bz2 r-alacritty-a754d06b44139b85e8b34a71ece4477cb1caa85e.zip |
Add support for single line terminals
This changes the minimum terminal dimensions from 2 lines and 2 columns,
to 1 line and 2 columns.
This also reworks the `SizeInfo` to store the number of columns and
lines and consistently has only the terminal lines/columns stored,
instead of including the message bar and search in some places of the
Alacritty renderer/input.
These new changes also make it easy to properly start the selection
scrolling as soon as the mouse is over the message bar, instead of
waiting until it is beyond it.
Fixes #4207.
Co-authored-by: Christian Duerr <contact@christianduerr.com>
Diffstat (limited to 'alacritty/src/renderer')
-rw-r--r-- | alacritty/src/renderer/mod.rs | 70 | ||||
-rw-r--r-- | alacritty/src/renderer/rects.rs | 15 |
2 files changed, 34 insertions, 51 deletions
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index da5f68a0..e97ac025 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -26,7 +26,6 @@ use alacritty_terminal::thread; use crate::config::font::{Font, FontDescription}; use crate::config::ui_config::{Delta, UIConfig}; -use crate::config::window::{StartupMode, WindowConfig}; use crate::cursor; use crate::gl; use crate::gl::types::*; @@ -231,7 +230,7 @@ impl GlyphCache { if desc == regular_desc { regular } else { - rasterizer.load_font(&desc, size).unwrap_or_else(|_| regular) + rasterizer.load_font(&desc, size).unwrap_or(regular) } }; @@ -358,34 +357,6 @@ impl GlyphCache { rasterizer.metrics(regular, font.size) } - - pub fn calculate_dimensions( - window_config: &WindowConfig, - dpr: f64, - cell_width: f32, - cell_height: f32, - ) -> Option<(u32, u32)> { - let dimensions = window_config.dimensions; - - if dimensions.columns_u32() == 0 - || dimensions.lines_u32() == 0 - || window_config.startup_mode != StartupMode::Windowed - { - return None; - } - - let padding_x = f64::from(window_config.padding.x) * dpr; - let padding_y = f64::from(window_config.padding.y) * dpr; - - // Calculate new size based on cols/lines specified in config. - let grid_width = cell_width as u32 * dimensions.columns_u32(); - let grid_height = cell_height as u32 * dimensions.lines_u32(); - - let width = padding_x.mul_add(2., f64::from(grid_width)).floor(); - let height = padding_y.mul_add(2., f64::from(grid_height)).floor(); - - Some((width as u32, height as u32)) - } } #[derive(Debug)] @@ -705,7 +676,7 @@ impl QuadRenderer { gl::UseProgram(self.rect_program.id); // Remove padding from viewport. - gl::Viewport(0, 0, props.width as i32, props.height as i32); + gl::Viewport(0, 0, props.width() as i32, props.height() as i32); // Change blending strategy. gl::BlendFuncSeparate(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA, gl::SRC_ALPHA, gl::ONE); @@ -740,10 +711,10 @@ impl QuadRenderer { gl::BindBuffer(gl::ARRAY_BUFFER, 0); gl::BindVertexArray(0); - let padding_x = props.padding_x as i32; - let padding_y = props.padding_y as i32; - let width = props.width as i32; - let height = props.height as i32; + let padding_x = props.padding_x() as i32; + let padding_y = props.padding_y() as i32; + let width = props.width() as i32; + let height = props.height() as i32; gl::Viewport(padding_x, padding_y, width - 2 * padding_x, height - 2 * padding_y); // Disable program. @@ -821,10 +792,10 @@ impl QuadRenderer { unsafe { gl::UseProgram(program.id); program.update_projection( - props.width, - props.height, - props.padding_x, - props.padding_y, + props.width(), + props.height(), + props.padding_x(), + props.padding_y(), ); gl::UseProgram(0); } @@ -847,15 +818,20 @@ impl QuadRenderer { // Viewport. unsafe { gl::Viewport( - size.padding_x as i32, - size.padding_y as i32, - size.width as i32 - 2 * size.padding_x as i32, - size.height as i32 - 2 * size.padding_y as i32, + size.padding_x() as i32, + size.padding_y() as i32, + size.width() as i32 - 2 * size.padding_x() as i32, + size.height() as i32 - 2 * size.padding_y() as i32, ); // Update projection. gl::UseProgram(self.program.id); - self.program.update_projection(size.width, size.height, size.padding_x, size.padding_y); + self.program.update_projection( + size.width(), + size.height(), + size.padding_x(), + size.padding_y(), + ); gl::UseProgram(0); } } @@ -870,8 +846,8 @@ impl QuadRenderer { } // Calculate rectangle position. - let center_x = size.width / 2.; - let center_y = size.height / 2.; + let center_x = size.width() / 2.; + let center_y = size.height() / 2.; let x = (rect.x - center_x) / center_x; let y = -(rect.y - center_y) / center_y; let width = rect.width / center_x; @@ -1226,7 +1202,7 @@ impl TextShaderProgram { fn set_term_uniforms(&self, props: &SizeInfo) { unsafe { - gl::Uniform2f(self.u_cell_dim, props.cell_width, props.cell_height); + gl::Uniform2f(self.u_cell_dim, props.cell_width(), props.cell_height()); } } diff --git a/alacritty/src/renderer/rects.rs b/alacritty/src/renderer/rects.rs index 83b59cb3..ca0bbd1c 100644 --- a/alacritty/src/renderer/rects.rs +++ b/alacritty/src/renderer/rects.rs @@ -99,14 +99,14 @@ impl RenderLine { mut thickness: f32, color: Rgb, ) -> RenderRect { - let start_x = start.col.0 as f32 * size.cell_width; - let end_x = (end.col.0 + 1) as f32 * size.cell_width; + let start_x = start.col.0 as f32 * size.cell_width(); + let end_x = (end.col.0 + 1) as f32 * size.cell_width(); let width = end_x - start_x; // Make sure lines are always visible. thickness = thickness.max(1.); - let line_bottom = (start.line.0 as f32 + 1.) * size.cell_height; + let line_bottom = (start.line.0 as f32 + 1.) * size.cell_height(); let baseline = line_bottom + descent; let mut y = (baseline - position - thickness / 2.).ceil(); @@ -115,7 +115,14 @@ impl RenderLine { y = max_y; } - RenderRect::new(start_x + size.padding_x, y + size.padding_y, width, thickness, color, 1.) + RenderRect::new( + start_x + size.padding_x(), + y + size.padding_y(), + width, + thickness, + color, + 1., + ) } } |