diff options
Diffstat (limited to 'alacritty/src/display/mod.rs')
-rw-r--r-- | alacritty/src/display/mod.rs | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index a942a88d..5cd59711 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -35,7 +35,7 @@ use crate::config::font::Font; use crate::config::window::Dimensions; #[cfg(not(windows))] use crate::config::window::StartupMode; -use crate::config::Config; +use crate::config::UiConfig; use crate::display::bell::VisualBell; use crate::display::color::List; use crate::display::content::RenderableContent; @@ -202,7 +202,7 @@ pub struct Display { impl Display { pub fn new<E>( - config: &Config, + config: &UiConfig, event_loop: &EventLoopWindowTarget<E>, #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] wayland_event_queue: Option<&EventQueue>, @@ -221,11 +221,11 @@ impl Display { }; // Guess the target window dimensions. - let metrics = GlyphCache::static_metrics(config.ui_config.font.clone(), estimated_dpr)?; + let metrics = GlyphCache::static_metrics(config.font.clone(), estimated_dpr)?; let (cell_width, cell_height) = compute_cell_size(config, &metrics); // Guess the target window size if the user has specified the number of lines/columns. - let dimensions = config.ui_config.window.dimensions(); + let dimensions = config.window.dimensions(); let estimated_size = dimensions.map(|dimensions| { window_size(config, dimensions, cell_width, cell_height, estimated_dpr) }); @@ -261,7 +261,7 @@ impl Display { } } - let padding = config.ui_config.window.padding(window.dpr); + let padding = config.window.padding(window.dpr); let viewport_size = window.inner_size(); // Create new size with at least one column and row. @@ -272,7 +272,7 @@ impl Display { cell_height, padding.0, padding.1, - config.ui_config.window.dynamic_padding && dimensions.is_none(), + config.window.dynamic_padding && dimensions.is_none(), ); info!("Cell size: {} x {}", cell_width, cell_height); @@ -283,25 +283,25 @@ impl Display { renderer.resize(&size_info); // Clear screen. - let background_color = config.ui_config.colors.primary.background; - renderer.with_api(&config.ui_config, &size_info, |api| { + let background_color = config.colors.primary.background; + renderer.with_api(config, &size_info, |api| { api.clear(background_color); }); // Set subpixel anti-aliasing. #[cfg(target_os = "macos")] - crossfont::set_font_smoothing(config.ui_config.font.use_thin_strokes); + crossfont::set_font_smoothing(config.font.use_thin_strokes); // Disable shadows for transparent windows on macOS. #[cfg(target_os = "macos")] - window.set_has_shadow(config.ui_config.window_opacity() >= 1.0); + window.set_has_shadow(config.window_opacity() >= 1.0); // On Wayland we can safely ignore this call, since the window isn't visible until you // actually draw something into it and commit those changes. #[cfg(not(any(target_os = "macos", windows)))] if is_x11 { window.swap_buffers(); - renderer.with_api(&config.ui_config, &size_info, |api| { + renderer.with_api(config, &size_info, |api| { api.finish(); }); } @@ -312,13 +312,13 @@ impl Display { // // TODO: replace `set_position` with `with_position` once available. // Upstream issue: https://github.com/rust-windowing/winit/issues/806. - if let Some(position) = config.ui_config.window.position { + if let Some(position) = config.window.position { window.set_outer_position(PhysicalPosition::from((position.x, position.y))); } #[allow(clippy::single_match)] #[cfg(not(windows))] - match config.ui_config.window.startup_mode { + match config.window.startup_mode { #[cfg(target_os = "macos")] StartupMode::SimpleFullscreen => window.set_simple_fullscreen(true), #[cfg(not(target_os = "macos"))] @@ -326,7 +326,7 @@ impl Display { _ => (), } - let hint_state = HintState::new(config.ui_config.hints.alphabet()); + let hint_state = HintState::new(config.hints.alphabet()); Ok(Self { window, @@ -340,8 +340,8 @@ impl Display { #[cfg(not(any(target_os = "macos", windows)))] is_x11, cursor_hidden: false, - visual_bell: VisualBell::from(&config.ui_config.bell), - colors: List::from(&config.ui_config.colors), + visual_bell: VisualBell::from(&config.bell), + colors: List::from(&config.colors), pending_update: Default::default(), }) } @@ -349,10 +349,10 @@ impl Display { fn new_glyph_cache( dpr: f64, renderer: &mut QuadRenderer, - config: &Config, + config: &UiConfig, ) -> Result<(GlyphCache, f32, f32), Error> { - let font = config.ui_config.font.clone(); - let rasterizer = Rasterizer::new(dpr as f32, config.ui_config.font.use_thin_strokes)?; + let font = config.font.clone(); + let rasterizer = Rasterizer::new(dpr as f32, config.font.use_thin_strokes)?; // Initialize glyph cache. let glyph_cache = { @@ -380,7 +380,7 @@ impl Display { /// Update font size and cell dimensions. /// /// This will return a tuple of the cell width and height. - fn update_glyph_cache(&mut self, config: &Config, font: &Font) -> (f32, f32) { + fn update_glyph_cache(&mut self, config: &UiConfig, font: &Font) -> (f32, f32) { let cache = &mut self.glyph_cache; let dpr = self.window.dpr; @@ -407,7 +407,7 @@ impl Display { pty_resize_handle: &mut dyn OnResize, message_buffer: &MessageBuffer, search_active: bool, - config: &Config, + config: &UiConfig, ) where T: EventListener, { @@ -436,7 +436,7 @@ impl Display { height = dimensions.height as f32; } - let padding = config.ui_config.window.padding(self.window.dpr); + let padding = config.window.padding(self.window.dpr); self.size_info = SizeInfo::new( width, @@ -445,7 +445,7 @@ impl Display { cell_height, padding.0, padding.1, - config.ui_config.window.dynamic_padding, + config.window.dynamic_padding, ); // Update number of column/lines in the viewport. @@ -478,7 +478,7 @@ impl Display { &mut self, terminal: MutexGuard<'_, Term<T>>, message_buffer: &MessageBuffer, - config: &Config, + config: &UiConfig, search_state: &SearchState, ) { // Collect renderable content before the terminal is dropped. @@ -505,7 +505,7 @@ impl Display { // Make sure this window's OpenGL context is active. self.window.make_current(); - self.renderer.with_api(&config.ui_config, &size_info, |api| { + self.renderer.with_api(config, &size_info, |api| { api.clear(background_color); }); @@ -522,7 +522,7 @@ impl Display { let glyph_cache = &mut self.glyph_cache; let highlighted_hint = &self.highlighted_hint; let vi_highlighted_hint = &self.vi_highlighted_hint; - self.renderer.with_api(&config.ui_config, &size_info, |mut api| { + self.renderer.with_api(config, &size_info, |mut api| { // Iterate over all non-empty cells in the grid. for mut cell in grid_cells { // Underline hints hovered by mouse or vi mode cursor. @@ -559,7 +559,7 @@ impl Display { // Push the cursor rects for rendering. if let Some(cursor) = cursor { - for rect in cursor.rects(&size_info, config.cursor.thickness()) { + for rect in cursor.rects(&size_info, config.terminal_config.cursor.thickness()) { rects.push(rect); } } @@ -572,7 +572,7 @@ impl Display { 0., size_info.width(), size_info.height(), - config.ui_config.bell.color, + config.bell.color, visual_bell_intensity as f32, ); rects.push(visual_bell_rect); @@ -587,8 +587,8 @@ impl Display { let y = size_info.cell_height().mul_add(start_line as f32, size_info.padding_y()); let bg = match message.ty() { - MessageType::Error => config.ui_config.colors.normal.red, - MessageType::Warning => config.ui_config.colors.normal.yellow, + MessageType::Error => config.colors.normal.red, + MessageType::Warning => config.colors.normal.yellow, }; let message_bar_rect = @@ -602,10 +602,10 @@ impl Display { // Relay messages to the user. let glyph_cache = &mut self.glyph_cache; - let fg = config.ui_config.colors.primary.background; + let fg = config.colors.primary.background; for (i, message_text) in text.iter().enumerate() { let point = Point::new(start_line + i, Column(0)); - self.renderer.with_api(&config.ui_config, &size_info, |mut api| { + self.renderer.with_api(config, &size_info, |mut api| { api.render_string(glyph_cache, point, fg, bg, message_text); }); } @@ -651,16 +651,16 @@ impl Display { // On X11 `swap_buffers` does not block for vsync. However the next OpenGl command // will block to synchronize (this is `glClear` in Alacritty), which causes a // permanent one frame delay. - self.renderer.with_api(&config.ui_config, &size_info, |api| { + self.renderer.with_api(config, &size_info, |api| { api.finish(); }); } } /// Update to a new configuration. - pub fn update_config(&mut self, config: &Config) { - self.visual_bell.update_config(&config.ui_config.bell); - self.colors = List::from(&config.ui_config.colors); + pub fn update_config(&mut self, config: &UiConfig) { + self.visual_bell.update_config(&config.bell); + self.colors = List::from(&config.colors); } /// Update the mouse/vi mode cursor hint highlighting. @@ -669,7 +669,7 @@ impl Display { pub fn update_highlighted_hints<T>( &mut self, term: &Term<T>, - config: &Config, + config: &UiConfig, mouse: &Mouse, modifiers: ModifiersState, ) -> bool { @@ -744,7 +744,7 @@ impl Display { } /// Draw current search regex. - fn draw_search(&mut self, config: &Config, size_info: &SizeInfo, text: &str) { + fn draw_search(&mut self, config: &UiConfig, size_info: &SizeInfo, text: &str) { let glyph_cache = &mut self.glyph_cache; let num_cols = size_info.columns(); @@ -752,17 +752,17 @@ impl Display { let text = format!("{:<1$}", text, num_cols); let point = Point::new(size_info.screen_lines(), Column(0)); - let fg = config.ui_config.colors.search_bar_foreground(); - let bg = config.ui_config.colors.search_bar_background(); + let fg = config.colors.search_bar_foreground(); + let bg = config.colors.search_bar_background(); - self.renderer.with_api(&config.ui_config, size_info, |mut api| { + self.renderer.with_api(config, size_info, |mut api| { api.render_string(glyph_cache, point, fg, bg, &text); }); } /// Draw render timer. - fn draw_render_timer(&mut self, config: &Config, size_info: &SizeInfo) { - if !config.ui_config.debug.render_timer { + fn draw_render_timer(&mut self, config: &UiConfig, size_info: &SizeInfo) { + if !config.debug.render_timer { return; } @@ -770,10 +770,10 @@ impl Display { let timing = format!("{:.3} usec", self.meter.average()); let point = Point::new(size_info.screen_lines().saturating_sub(2), Column(0)); - let fg = config.ui_config.colors.primary.background; - let bg = config.ui_config.colors.normal.red; + let fg = config.colors.primary.background; + let bg = config.colors.normal.red; - self.renderer.with_api(&config.ui_config, size_info, |mut api| { + self.renderer.with_api(config, size_info, |mut api| { api.render_string(glyph_cache, point, fg, bg, &timing); }); } @@ -781,7 +781,7 @@ impl Display { /// Draw an indicator for the position of a line in history. fn draw_line_indicator( &mut self, - config: &Config, + config: &UiConfig, size_info: &SizeInfo, total_lines: usize, obstructed_column: Option<Column>, @@ -789,14 +789,14 @@ impl Display { ) { let text = format!("[{}/{}]", line, total_lines - 1); let column = Column(size_info.columns().saturating_sub(text.len())); - let colors = &config.ui_config.colors; + let colors = &config.colors; let fg = colors.line_indicator.foreground.unwrap_or(colors.primary.background); let bg = colors.line_indicator.background.unwrap_or(colors.primary.foreground); // Do not render anything if it would obscure the vi mode cursor. if obstructed_column.map_or(true, |obstructed_column| obstructed_column < column) { let glyph_cache = &mut self.glyph_cache; - self.renderer.with_api(&config.ui_config, size_info, |mut api| { + self.renderer.with_api(config, size_info, |mut api| { api.render_string(glyph_cache, Point::new(0, column), fg, bg, &text); }); } @@ -847,9 +847,9 @@ pub fn viewport_to_point(display_offset: usize, point: Point<usize>) -> Point { /// /// This will return a tuple of the cell width and height. #[inline] -fn compute_cell_size(config: &Config, metrics: &crossfont::Metrics) -> (f32, f32) { - let offset_x = f64::from(config.ui_config.font.offset.x); - let offset_y = f64::from(config.ui_config.font.offset.y); +fn compute_cell_size(config: &UiConfig, metrics: &crossfont::Metrics) -> (f32, f32) { + let offset_x = f64::from(config.font.offset.x); + let offset_y = f64::from(config.font.offset.y); ( (metrics.average_advance + offset_x).floor().max(1.) as f32, (metrics.line_height + offset_y).floor().max(1.) as f32, @@ -858,13 +858,13 @@ fn compute_cell_size(config: &Config, metrics: &crossfont::Metrics) -> (f32, f32 /// Calculate the size of the window given padding, terminal dimensions and cell size. fn window_size( - config: &Config, + config: &UiConfig, dimensions: Dimensions, cell_width: f32, cell_height: f32, dpr: f64, ) -> PhysicalSize<u32> { - let padding = config.ui_config.window.padding(dpr); + let padding = config.window.padding(dpr); let grid_width = cell_width * dimensions.columns.0.max(MIN_COLUMNS) as f32; let grid_height = cell_height * dimensions.lines.max(MIN_SCREEN_LINES) as f32; |