From 7ce767ab87ca915b2ac4023cc95dbda81fe87abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 30 Apr 2021 20:31:47 +0200 Subject: [PATCH] =?UTF-8?q?config:=20add=20=E2=80=98beam-thickness?= =?UTF-8?q?=E2=80=99=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rename cursor.style value ‘bar’ to ‘beam’. ‘bar’ remains recognized, but should eventually be deprecated and then removed. * Add ‘cursor.beam-thickness’ option, a pt-or-px value specifying the thickness of the beam cursor. Defaults to 1.5pt. * Rename (and export) pt_or_px_as_pixels() to term_pt_or_px_as_pixels() * Change term_pt_or_px_as_pixels() to round point values instead of truncating them. --- CHANGELOG.md | 8 ++++++++ config.c | 15 ++++++++++++--- config.h | 1 + csi.c | 2 +- doc/foot.ini.5.scd | 15 ++++++++++----- foot.ini | 1 + ime.c | 2 +- render.c | 21 +++++++++++---------- terminal.c | 16 ++++++++-------- terminal.h | 5 ++++- 10 files changed, 57 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a64154..2fce1af5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,9 @@ * Support for DECSET/DECRST 2026, as an alternative to the existing "synchronized updates" DCS sequences (https://codeberg.org/dnkl/foot/issues/459). +* `cursor.beam-thickness` option to `foot.ini` + (https://codeberg.org/dnkl/foot/issues/464). + ### Changed @@ -43,6 +46,11 @@ foreground and background colors are the same, making the highlighted text legible (https://codeberg.org/dnkl/foot/issues/455). +* `cursor.style=bar` to `cursor.style=beam`. `bar` remains a + recognized value, but will eventually be deprecated, and removed. +* Point values in `line-height`, `letter-spacing`, + `horizontal-letter-offset` and `vertical-letter-offset` are now + rounded, not truncated, when translated to pixel values. ### Deprecated diff --git a/config.c b/config.c index 3aed1e7d..f5446107 100644 --- a/config.c +++ b/config.c @@ -941,13 +941,14 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, if (strcmp(key, "style") == 0) { if (strcmp(value, "block") == 0) conf->cursor.style = CURSOR_BLOCK; - else if (strcmp(value, "bar") == 0) - conf->cursor.style = CURSOR_BAR; + else if (strcmp(value, "beam") == 0 || strcmp(value, "bar") == 0) + conf->cursor.style = CURSOR_BEAM; else if (strcmp(value, "underline") == 0) conf->cursor.style = CURSOR_UNDERLINE; else { - LOG_AND_NOTIFY_ERR("%s:%d: invalid 'style': %s", path, lineno, value); + LOG_AND_NOTIFY_ERR("%s:%d: style: one of block, beam or underline", + path, lineno); return false; } } @@ -967,6 +968,13 @@ parse_section_cursor(const char *key, const char *value, struct config *conf, conf->cursor.color.cursor |= 1u << 31; } + else if (strcmp(key, "beam-thickness") == 0) { + if (!str_to_pt_or_px( + value, &conf->cursor.beam_thickness, + conf, path, lineno, "cursor", "beam-thickness")) + return false; + } + else { LOG_AND_NOTIFY_ERR("%s:%d: [cursor]: %s: invalid key", path, lineno, key); return false; @@ -2261,6 +2269,7 @@ config_load(struct config *conf, const char *conf_path, .text = 0, .cursor = 0, }, + .beam_thickness = {.pt = 1.5}, }, .mouse = { .hide_when_typing = false, diff --git a/config.h b/config.h index 06184658..2a5ca79d 100644 --- a/config.h +++ b/config.h @@ -154,6 +154,7 @@ struct config { uint32_t text; uint32_t cursor; } color; + struct pt_or_px beam_thickness; } cursor; struct { diff --git a/csi.c b/csi.c index c5f5ccc0..585ca9d5 100644 --- a/csi.c +++ b/csi.c @@ -1591,7 +1591,7 @@ csi_dispatch(struct terminal *term, uint8_t final) case 5: /* blinking bar */ case 6: /* steady bar */ - term->cursor_style = CURSOR_BAR; + term->cursor_style = CURSOR_BEAM; break; default: diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 4af48307..f32be208 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -68,7 +68,7 @@ in this order: An absolute value, in _points_, that override line height from the font metrics. - You can specify a height in _pixels_ by using the _px_ suffix: + You can specify a height in _pixels_ by using the *px* suffix: e.g. *line-height=12px*. See also: *vertical-letter-offset*. @@ -79,7 +79,7 @@ in this order: Spacing between letters, in _points_. A positive value will increase the cell size, and a negative value shrinks it. - You can specify a letter spacing in _pixels_ by using the _px_ + You can specify a letter spacing in _pixels_ by using the *px* suffix: e.g. *letter-spacing=2px*. See also: *horizontal-letter-offset*. @@ -91,7 +91,7 @@ in this order: positioning glyphs within cells, in _points_, relative to the top left corner. - To specify an offset in _pixels_, append _px_: + To specify an offset in _pixels_, append *px*: e.g. *horizontal-letter-offset=2px*. Default: _0_. @@ -320,8 +320,8 @@ This section controls the cursor style and color. Note that applications can change these at runtime. *style* - Configures the default cursor style, and is one of: _block_, _bar_ - or _underline_. Note that this can be overridden by + Configures the default cursor style, and is one of: *block*, + *beam* or *underline*. Note that this can be overridden by applications. Default: _block_. *blink* @@ -335,6 +335,11 @@ applications can change these at runtime. cursor. The other cursor styles are always rendered with the foreground color. +*beam-thickness* + Thickness (width) of the beam styled cursor. The value is in + _points_, and its exact value thus depends on the monitor's + DPI. To instead specify a thickness in _pixels_, use the *px* + suffix: e.g. *beam-thickness=2px*. Default: _1.5_ # SECTION: mouse diff --git a/foot.ini b/foot.ini index a194a145..81bfb489 100644 --- a/foot.ini +++ b/foot.ini @@ -42,6 +42,7 @@ # style=block # color=111111 dcdccc # blink=no +# beam-thickness=1.5 [mouse] # hide-when-typing=no diff --git a/ime.c b/ime.c index 91a746e9..b1852ed3 100644 --- a/ime.c +++ b/ime.c @@ -466,7 +466,7 @@ ime_update_cursor_rect(struct seat *seat) x = term->margins.left + col * term->cell_width; y = term->margins.top + row * term->cell_height; - if (term->cursor_style == CURSOR_BAR) + if (term->cursor_style == CURSOR_BEAM) width = 1; else width = term->cell_width; diff --git a/render.c b/render.c index faa04183..e4387c08 100644 --- a/render.c +++ b/render.c @@ -299,16 +299,17 @@ draw_unfocused_block(const struct terminal *term, pixman_image_t *pix, } static void -draw_bar(const struct terminal *term, pixman_image_t *pix, - const struct fcft_font *font, - const pixman_color_t *color, int x, int y) +draw_beam(const struct terminal *term, pixman_image_t *pix, + const struct fcft_font *font, + const pixman_color_t *color, int x, int y) { int baseline = y + font_baseline(term) - term->fonts[0]->ascent; pixman_image_fill_rectangles( PIXMAN_OP_SRC, pix, color, 1, &(pixman_rectangle16_t){ x, baseline, - font->underline.thickness, term->fonts[0]->ascent + term->fonts[0]->descent}); + term_pt_or_px_as_pixels(term, &term->conf->cursor.beam_thickness), + term->fonts[0]->ascent + term->fonts[0]->descent}); } static void @@ -386,11 +387,11 @@ draw_cursor(const struct terminal *term, const struct cell *cell, } break; - case CURSOR_BAR: + case CURSOR_BEAM: if (likely(term->cursor_blink.state == CURSOR_BLINK_ON || !term->kbd_focus)) { - draw_bar(term, pix, font, &cursor_color, x, y); + draw_beam(term, pix, font, &cursor_color, x, y); } break; @@ -1265,7 +1266,7 @@ render_ime_preedit_for_seat(struct terminal *term, struct seat *seat, /* Bar */ if (start >= 0) { struct fcft_font *font = attrs_to_font(term, &start_cell->attrs); - draw_bar(term, buf->pix[0], font, &cursor_color, x, y); + draw_beam(term, buf->pix[0], font, &cursor_color, x, y); } term_ime_set_cursor_rect(term, x, y, 1, term->cell_height); } @@ -2475,7 +2476,7 @@ render_search_box(struct terminal *term) /* Bar-styled cursor, if in the visible area */ if (start >= 0 && start <= visible_cells) - draw_bar(term, buf->pix[0], font, &fg, x + start * term->cell_width, y); + draw_beam(term, buf->pix[0], font, &fg, x + start * term->cell_width, y); term_ime_set_cursor_rect(term, WINDOW_X(x + start * term->cell_width), WINDOW_Y(y), 1, term->cell_height); @@ -2504,7 +2505,7 @@ render_search_box(struct terminal *term) /* Cursor *should* be in the visible area */ xassert(cell_idx >= glyph_offset); xassert(cell_idx <= glyph_offset + visible_cells); - draw_bar(term, buf->pix[0], font, &fg, x, y); + draw_beam(term, buf->pix[0], font, &fg, x, y); term_ime_set_cursor_rect( term, WINDOW_X(x), WINDOW_Y(y), 1, term->cell_height); } @@ -2560,7 +2561,7 @@ render_search_box(struct terminal *term) else #endif if (term->search.cursor >= term->search.len) { - draw_bar(term, buf->pix[0], font, &fg, x, y); + draw_beam(term, buf->pix[0], font, &fg, x, y); term_ime_set_cursor_rect( term, WINDOW_X(x), WINDOW_Y(y), 1, term->cell_height); } diff --git a/terminal.c b/terminal.c index bcb8a868..cd1ecbd9 100644 --- a/terminal.c +++ b/terminal.c @@ -600,12 +600,12 @@ err_sem_destroy: return false; } -static int -pt_or_px_as_pixels(const struct terminal *term, - const struct pt_or_px *pt_or_px) +int +term_pt_or_px_as_pixels(const struct terminal *term, + const struct pt_or_px *pt_or_px) { return pt_or_px->px == 0 - ? pt_or_px->pt * term->font_dpi / 72 + ? round(pt_or_px->pt * term->font_dpi / 72) : pt_or_px->px; } @@ -636,15 +636,15 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4]) (term->fonts[0]->space_advance.x > 0 ? term->fonts[0]->space_advance.x : term->fonts[0]->max_advance.x) - + pt_or_px_as_pixels(term, &conf->letter_spacing); + + term_pt_or_px_as_pixels(term, &conf->letter_spacing); term->cell_height = term->font_line_height.px >= 0 - ? pt_or_px_as_pixels(term, &term->font_line_height) + ? term_pt_or_px_as_pixels(term, &term->font_line_height) : max(term->fonts[0]->height, term->fonts[0]->ascent + term->fonts[0]->descent); - term->font_x_ofs = pt_or_px_as_pixels(term, &conf->horizontal_letter_offset); - term->font_y_ofs = pt_or_px_as_pixels(term, &conf->vertical_letter_offset); + term->font_x_ofs = term_pt_or_px_as_pixels(term, &conf->horizontal_letter_offset); + term->font_y_ofs = term_pt_or_px_as_pixels(term, &conf->vertical_letter_offset); LOG_INFO("cell width=%d, height=%d", term->cell_width, term->cell_height); diff --git a/terminal.h b/terminal.h index 72685101..3de7b8f4 100644 --- a/terminal.h +++ b/terminal.h @@ -212,7 +212,7 @@ enum mouse_reporting { MOUSE_URXVT, /* ?1015h */ }; -enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR }; +enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BEAM }; enum selection_kind { SELECTION_NONE, @@ -615,6 +615,9 @@ bool term_font_size_decrease(struct terminal *term); bool term_font_size_reset(struct terminal *term); bool term_font_dpi_changed(struct terminal *term); void term_font_subpixel_changed(struct terminal *term); +int term_pt_or_px_as_pixels( + const struct terminal *term, const struct pt_or_px *pt_or_px); + void term_window_configured(struct terminal *term);