aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-04-05 17:18:46 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-04-06 16:17:59 +0000
commit5ce1589c60feb7a9c41377f732955f6108d183ac (patch)
treee9746167cd8031910031c4c56c892a8722f02ff0
parentSmall clarification/rewording of default color values (diff)
render: ensure an underline cursor is not positioned too low
The underline cursor is positioned just below regular underlines. A bug in the positioning logic related to this, sometimes resulted in the cursor being thinner than what it should be, or even invisible. Fixes #1005
-rw-r--r--CHANGELOG.md3
-rw-r--r--render.c40
2 files changed, 24 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d41fe9af..2ae45501 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -93,6 +93,9 @@
(https://codeberg.org/dnkl/foot/issues/963).
* Key presses with e.g. `AltGr` triggering key combinations with the
base symbol (https://codeberg.org/dnkl/foot/issues/983).
+* Underline cursor sometimes being positioned too low, either making
+ it look thinner than what it should be, or being completely
+ invisible (https://codeberg.org/dnkl/foot/issues/1005).
### Security
diff --git a/render.c b/render.c
index d6fd6d6b..e9edc012 100644
--- a/render.c
+++ b/render.c
@@ -345,24 +345,13 @@ draw_beam_cursor(const struct terminal *term, pixman_image_t *pix,
term->fonts[0]->ascent + term->fonts[0]->descent});
}
-static void
-draw_underline_with_thickness(
- const struct terminal *term, pixman_image_t *pix,
- const struct fcft_font *font,
- const pixman_color_t *color, int x, int y, int cols, int thickness)
+static int
+underline_offset(const struct terminal *term, const struct fcft_font *font)
{
- /* Make sure the line isn't positioned below the cell */
- int y_ofs = font_baseline(term) -
+ return font_baseline(term) -
(term->conf->use_custom_underline_offset
? -term_pt_or_px_as_pixels(term, &term->conf->underline_offset)
: font->underline.position);
-
- y_ofs = min(y_ofs, term->cell_height - thickness);
-
- pixman_image_fill_rectangles(
- PIXMAN_OP_SRC, pix, color,
- 1, &(pixman_rectangle16_t){
- x, y + y_ofs, cols * term->cell_width, thickness});
}
static void
@@ -375,9 +364,14 @@ draw_underline_cursor(const struct terminal *term, pixman_image_t *pix,
term, &term->conf->cursor.underline_thickness)
: font->underline.thickness;
- draw_underline_with_thickness(
- term, pix, font, color, x, y + font->underline.thickness, cols,
- thickness);
+ /* Make sure the line isn't positioned below the cell */
+ const int y_ofs = min(underline_offset(term, font) + thickness,
+ term->cell_height - thickness);
+
+ pixman_image_fill_rectangles(
+ PIXMAN_OP_SRC, pix, color,
+ 1, &(pixman_rectangle16_t){
+ x, y + y_ofs, cols * term->cell_width, thickness});
}
static void
@@ -385,8 +379,16 @@ draw_underline(const struct terminal *term, pixman_image_t *pix,
const struct fcft_font *font,
const pixman_color_t *color, int x, int y, int cols)
{
- draw_underline_with_thickness(
- term, pix, font, color, x, y, cols, font->underline.thickness);
+ const int thickness = font->underline.thickness;
+
+ /* Make sure the line isn't positioned below the cell */
+ const int y_ofs = min(underline_offset(term, font),
+ term->cell_height - thickness);
+
+ pixman_image_fill_rectangles(
+ PIXMAN_OP_SRC, pix, color,
+ 1, &(pixman_rectangle16_t){
+ x, y + y_ofs, cols * term->cell_width, thickness});
}
static void