aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-02-19 15:27:50 -0700
committerJosh Rahm <rahm@google.com>2025-02-05 17:49:34 -0700
commit04ef76f059c751f2c1c5a7e7c691f0e7c63e89c1 (patch)
tree37b9b86b3ca8cbbc9c58d01e50f714e4b056c022
parent463a86798401927d463424aff3639dda18a7a27d (diff)
downloadr-alacritty-04ef76f059c751f2c1c5a7e7c691f0e7c63e89c1.tar.gz
r-alacritty-04ef76f059c751f2c1c5a7e7c691f0e7c63e89c1.tar.bz2
r-alacritty-04ef76f059c751f2c1c5a7e7c691f0e7c63e89c1.zip
Re-implement crosshairs on newer alacritty.
The config values are hardcoded atm.
-rw-r--r--alacritty/src/display/cursor.rs86
1 files changed, 82 insertions, 4 deletions
diff --git a/alacritty/src/display/cursor.rs b/alacritty/src/display/cursor.rs
index b0e2d6c3..0b72b249 100644
--- a/alacritty/src/display/cursor.rs
+++ b/alacritty/src/display/cursor.rs
@@ -26,25 +26,103 @@ impl IntoRects for RenderableCursor {
width *= self.width().get() as f32;
- match self.shape() {
+ let crosshairs = crosshair(x, y, size_info);
+
+ let mut shape = match self.shape() {
CursorShape::Beam => beam(x, y, height, thickness, self.color()),
CursorShape::Underline => underline(x, y, width, height, thickness, self.color()),
CursorShape::HollowBlock => hollow(x, y, width, height, thickness, self.color()),
_ => CursorRects::default(),
+ };
+ // shape.append(&mut crosshairs);
+
+ let mut i = 0;
+ let mut ci = 0;
+ while i < shape.rects.len() && ci < crosshairs.len() {
+ match shape.rects[i] {
+ None => {
+ shape.rects[i] = Some(crosshairs[ci]);
+ ci = ci + 1;
+ }
+ Some(_) => {}
+ }
+ i = i + 1;
}
+ shape
+ }
+}
+
+fn abs_rect(x0: f32, y0: f32, x1: f32, y1: f32, color: Rgb, opacity: f32) -> Option<RenderRect> {
+ if x0 >= x1 || y0 >= y1 {
+ None
+ } else {
+ Some(RenderRect::new(x0, y0, x1 - x0, y1 - y0, color, opacity))
}
}
+fn crosshair(x: f32, y: f32, size_info: &SizeInfo) -> Vec<RenderRect> {
+ let width = size_info.cell_width();
+ let height = size_info.cell_height();
+ let y_inner_padding = 2.; // config.y_inner_padding as f32;
+ let x_inner_padding = 4.; // config.x_inner_padding as f32;
+ let opacity = 0.05; // config.opacity.as_f32();
+ let color = Rgb::new(255,255,255); // config.color;
+
+ let crosshair_max_height =
+ 20. * size_info.cell_height();
+ let crosshair_max_width =
+ 40. * size_info.cell_width();
+
+ (vec![
+ abs_rect(
+ x,
+ (y - crosshair_max_height).max(0.),
+ x + width,
+ y - (size_info.cell_height() * y_inner_padding),
+ color,
+ opacity,
+ ),
+ abs_rect(
+ x,
+ y + size_info.cell_height() * (y_inner_padding + 1.),
+ x + width,
+ size_info.height().min(y + crosshair_max_height + height),
+ color,
+ opacity,
+ ),
+ abs_rect(
+ (x - crosshair_max_width).max(0.),
+ y,
+ x - (size_info.cell_width() * x_inner_padding),
+ y + height,
+ color,
+ opacity,
+ ),
+ abs_rect(
+ x + size_info.cell_width()
+ * (x_inner_padding + if x_inner_padding > 0. { 1. } else { 0. }),
+ y,
+ size_info.width().min(x + crosshair_max_width + width),
+ y + height,
+ color,
+ opacity,
+ ),
+ ])
+ .into_iter()
+ .flatten()
+ .collect::<Vec<RenderRect>>()
+}
+
/// Cursor rect iterator.
#[derive(Default)]
pub struct CursorRects {
- rects: [Option<RenderRect>; 4],
+ rects: [Option<RenderRect>; 8],
index: usize,
}
impl From<RenderRect> for CursorRects {
fn from(rect: RenderRect) -> Self {
- Self { rects: [Some(rect), None, None, None], index: 0 }
+ Self { rects: [Some(rect), None, None, None, None, None, None, None], index: 0 }
}
}
@@ -84,7 +162,7 @@ fn hollow(x: f32, y: f32, width: f32, height: f32, thickness: f32, color: Rgb) -
let right_line = RenderRect::new(right_x, vertical_y, thickness, vertical_height, color, 1.);
CursorRects {
- rects: [Some(top_line), Some(bottom_line), Some(left_line), Some(right_line)],
+ rects: [Some(top_line), Some(bottom_line), Some(left_line), Some(right_line), None, None, None, None],
index: 0,
}
}