diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-12-08 23:25:05 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-08 23:25:05 +0400 |
commit | c0c267d60e1b877d5c2c76893751d13547a233c4 (patch) | |
tree | 88ea0bb709926b978a955b62539134107d9915ab /alacritty/src/display/damage.rs | |
parent | e12c750edb776ace9d7f6d302786f5dd06d6e968 (diff) | |
download | r-alacritty-c0c267d60e1b877d5c2c76893751d13547a233c4.tar.gz r-alacritty-c0c267d60e1b877d5c2c76893751d13547a233c4.tar.bz2 r-alacritty-c0c267d60e1b877d5c2c76893751d13547a233c4.zip |
Fix message bar not damaged when the same size
The regression was added due to `y` coordinate in OpenGL differs to
`y` inside the damage rectangles.
Fixes: 40160c5d (Damage only terminal inside `alacritty_terminal`)
Diffstat (limited to 'alacritty/src/display/damage.rs')
-rw-r--r-- | alacritty/src/display/damage.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/alacritty/src/display/damage.rs b/alacritty/src/display/damage.rs index 24033fa5..450643b7 100644 --- a/alacritty/src/display/damage.rs +++ b/alacritty/src/display/damage.rs @@ -164,11 +164,19 @@ impl FrameDamage { self.full = true; } - /// Add a damage rectangle. + /// Add viewport rectangle to damage. /// /// This allows covering elements outside of the terminal viewport, like message bar. #[inline] - pub fn add_rect(&mut self, x: i32, y: i32, width: i32, height: i32) { + pub fn add_viewport_rect( + &mut self, + size_info: &SizeInfo, + x: i32, + y: i32, + width: i32, + height: i32, + ) { + let y = viewport_y_to_damage_y(size_info, y, height); self.rects.push(Rect { x, y, width, height }); } @@ -183,6 +191,16 @@ impl FrameDamage { } } +/// Convert viewport `y` coordinate to [`Rect`] damage coordinate. +pub fn viewport_y_to_damage_y(size_info: &SizeInfo, y: i32, height: i32) -> i32 { + size_info.height() as i32 - y - height +} + +/// Convert viewport `y` coordinate to [`Rect`] damage coordinate. +pub fn damage_y_to_viewport_y(size_info: &SizeInfo, rect: &Rect) -> i32 { + size_info.height() as i32 - rect.y - rect.height +} + /// Iterator which converts `alacritty_terminal` damage information into renderer damaged rects. struct RenderDamageIterator<'a> { damaged_lines: Peekable<TermDamageIterator<'a>>, @@ -316,4 +334,24 @@ mod tests { rect ); } + + #[test] + fn add_viewport_damage() { + let mut frame_damage = FrameDamage::default(); + let viewport_height = 100.; + let x = 0; + let y = 40; + let height = 5; + let width = 10; + let size_info = SizeInfo::new(viewport_height, viewport_height, 5., 5., 0., 0., true); + frame_damage.add_viewport_rect(&size_info, x, y, width, height); + assert_eq!(frame_damage.rects[0], Rect { + x, + y: viewport_height as i32 - y - height, + width, + height + }); + assert_eq!(frame_damage.rects[0].y, viewport_y_to_damage_y(&size_info, y, height)); + assert_eq!(damage_y_to_viewport_y(&size_info, &frame_damage.rects[0]), y); + } } |