From b1950ac222f525f6763908ad57ff6d6399e061a0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 24 Jul 2020 17:51:40 +0200 Subject: render: add code that calculates current position in scrollback --- render.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 80611d22..da6c2610 100644 --- a/render.c +++ b/render.c @@ -1287,6 +1287,50 @@ render_csd(struct terminal *term) render_csd_title(term); } +static void +render_scrollback_position(struct terminal *term) +{ +#if 0 + if (!term->conf->show_scrollback_position) + return; +#endif + + /* Find absolute row number of the scrollback start */ + int scrollback_start = term->grid->offset + term->rows; + while (term->grid->rows[scrollback_start & (term->grid->num_rows - 1)] == NULL) + scrollback_start++; + + /* Rebase viewport against scrollback start (so that 0 is at + * the beginning of the scrollback) */ + int rebased_view = term->grid->view - scrollback_start + term->grid->num_rows; + rebased_view &= term->grid->num_rows - 1; + + /* + * How far down in the scrollback we are. + * + * 0% -> at the beginning of the scrollback + * 100% -> at the bottom, i.e. where new lines are inserted + */ + int percentage __attribute__((unused)) = + rebased_view + term->rows == term->grid->num_rows + ? 100 + : 100 * rebased_view / term->grid->num_rows; + + int next_row_no = term->grid->view + term->rows; + next_row_no &= term->grid->num_rows - 1; + + /* Are we at the end of the scrollback? */ + bool at_bottom = rebased_view + term->rows == term->grid->num_rows || + term->grid->rows[next_row_no] == NULL; + + LOG_DBG("scrollback position: %d/%d (%d%%), at-bottom: %d", + rebased_view, term->grid->num_rows, percentage, at_bottom); + + if (!at_bottom) { + /* TODO: insert rendering code here */ + } +} + static void frame_callback( void *data, struct wl_callback *wl_callback, uint32_t callback_data); @@ -1498,6 +1542,8 @@ grid_render(struct terminal *term) term->window->surface, 0, 0, term->width, term->height); } + render_scrollback_position(term); + assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows); assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); -- cgit v1.3 From 2c6f7adc17832c77b2353338b0c76c8a19f4112b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 24 Jul 2020 18:20:26 +0200 Subject: config: add 'show-scrollback-position' option to footrc --- config.c | 4 ++++ config.h | 1 + doc/foot.5.scd | 4 ++++ render.c | 2 -- 4 files changed, 9 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index 283a72ea..9666da61 100644 --- a/config.c +++ b/config.c @@ -291,6 +291,9 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback_lines = lines; } + else if (strcmp(key, "show-scrollback-position") == 0) + conf->show_scrollback_position = str_to_bool(value); + else { LOG_ERR("%s:%u: invalid key: %s", path, lineno, key); return false; @@ -918,6 +921,7 @@ config_load(struct config *conf, const char *conf_path) .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), .scrollback_lines = 1000, + .show_scrollback_position = true, .colors = { .fg = default_foreground, diff --git a/config.h b/config.h index 2b43b806..c21e1160 100644 --- a/config.h +++ b/config.h @@ -40,6 +40,7 @@ struct config { tll(struct config_font) fonts; int scrollback_lines; + bool show_scrollback_position; struct { uint32_t fg; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 92ac7c01..fd5a5d42 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,6 +68,10 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. +*show-scrollback-position* + Boolean. Enables a position indicator when the viewport is not at + the bottom of the scrollback history. Default: _yes_. + *workers* Number of threads to use for rendering. Set to 0 to disable multithreading. Default: the number of available logical CPUs diff --git a/render.c b/render.c index da6c2610..6611fbb9 100644 --- a/render.c +++ b/render.c @@ -1290,10 +1290,8 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { -#if 0 if (!term->conf->show_scrollback_position) return; -#endif /* Find absolute row number of the scrollback start */ int scrollback_start = term->grid->offset + term->rows; -- cgit v1.3 From e94506362028b57fa5d2c77f73a152a47cc06768 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 24 Jul 2020 18:26:44 +0200 Subject: config: rename show-scrollback-position to scrollback-indicator --- config.c | 6 +++--- config.h | 2 +- doc/foot.5.scd | 2 +- render.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index 9666da61..e7ba74b2 100644 --- a/config.c +++ b/config.c @@ -291,8 +291,8 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback_lines = lines; } - else if (strcmp(key, "show-scrollback-position") == 0) - conf->show_scrollback_position = str_to_bool(value); + else if (strcmp(key, "scrollback-indicator") == 0) + conf->scrollback_indicator = str_to_bool(value); else { LOG_ERR("%s:%u: invalid key: %s", path, lineno, key); @@ -921,7 +921,7 @@ config_load(struct config *conf, const char *conf_path) .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), .scrollback_lines = 1000, - .show_scrollback_position = true, + .scrollback_indicator = true, .colors = { .fg = default_foreground, diff --git a/config.h b/config.h index c21e1160..f0f077be 100644 --- a/config.h +++ b/config.h @@ -40,7 +40,7 @@ struct config { tll(struct config_font) fonts; int scrollback_lines; - bool show_scrollback_position; + bool scrollback_indicator; struct { uint32_t fg; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index fd5a5d42..1f71a8d3 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,7 +68,7 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. -*show-scrollback-position* +*scrollback-indicator* Boolean. Enables a position indicator when the viewport is not at the bottom of the scrollback history. Default: _yes_. diff --git a/render.c b/render.c index 6611fbb9..d5cdb8dc 100644 --- a/render.c +++ b/render.c @@ -1290,7 +1290,7 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { - if (!term->conf->show_scrollback_position) + if (!term->conf->scrollback_indicator) return; /* Find absolute row number of the scrollback start */ -- cgit v1.3 From c4679e474e0546ee8dad6e122c226ece85bdb134 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 25 Jul 2020 14:31:45 +0200 Subject: config: rename scrollback-indicator to scrollback-indicator-style And turn it from a boolean to an enum. It can be set to: * `none` - disables the indicator * `static` - always rendered near the top of the window * `moving` - position reflects the scrollback position --- config.c | 37 ++++++++++++++++++++++++++----------- config.h | 19 ++++++++++++++++--- doc/foot.5.scd | 12 ++++++++---- footrc | 2 ++ render.c | 2 +- terminal.c | 2 +- 6 files changed, 54 insertions(+), 20 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index 332fd11a..7c4c9d9f 100644 --- a/config.c +++ b/config.c @@ -288,21 +288,33 @@ parse_section_main(const char *key, const char *value, struct config *conf, LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); return false; } - conf->scrollback_lines = lines; + conf->scrollback.lines = lines; } - else if (strcmp(key, "scrollback-indicator") == 0) - conf->scrollback_indicator = str_to_bool(value); + else if (strcmp(key, "scrollback-indicator") == 0) { + if (strcmp(value, "none") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_NONE; + else if (strcmp(value, "static") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_STATIC; + else if (strcmp(value, "moving") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_MOVING; + else { + LOG_ERR("%s:%d: scrollback-indicator-style must be one of " + "'none', 'static' or 'moving'", + path, lineno); + return false; + } + } else if (strcmp(key, "scrollback-indicator-format") == 0) { if (strcmp(value, "percent") == 0) - conf->scrollback_indicator_format = SCROLLBACK_INDICATOR_PERCENT; + conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_PERCENT; else if (strcmp(value, "line") == 0) - conf->scrollback_indicator_format = SCROLLBACK_INDICATOR_LINENO; + conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; else { LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " - "of 'percent' or 'line', not %s", - path, lineno, value); + "of 'percent' or 'line'", + path, lineno); return false; } } @@ -933,10 +945,13 @@ config_load(struct config *conf, const char *conf_path) .pad_y = 2, .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), - .scrollback_lines = 1000, - .scrollback_indicator = true, - .scrollback_indicator_format = SCROLLBACK_INDICATOR_PERCENT, - + .scrollback = { + .lines = 1000, + .indicator = { + .style = SCROLLBACK_INDICATOR_STYLE_MOVING, + .format = SCROLLBACK_INDICATOR_FORMAT_PERCENT, + }, + }, .colors = { .fg = default_foreground, .bg = default_background, diff --git a/config.h b/config.h index 109eecb8..9ff83b77 100644 --- a/config.h +++ b/config.h @@ -39,9 +39,22 @@ struct config { tll(struct config_font) fonts; - int scrollback_lines; - bool scrollback_indicator; - enum {SCROLLBACK_INDICATOR_PERCENT, SCROLLBACK_INDICATOR_LINENO} scrollback_indicator_format; + struct { + int lines; + + struct { + enum { + SCROLLBACK_INDICATOR_STYLE_NONE, + SCROLLBACK_INDICATOR_STYLE_STATIC, + SCROLLBACK_INDICATOR_STYLE_MOVING + } style; + + enum { + SCROLLBACK_INDICATOR_FORMAT_PERCENT, + SCROLLBACK_INDICATOR_FORMAT_LINENO + } format; + } indicator; + } scrollback; struct { uint32_t fg; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 485886fa..9813741c 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,14 +68,18 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. -*scrollback-indicator* - Boolean. Enables a position indicator when the viewport is not at - the bottom of the scrollback history. Default: _yes_. +*scrollback-indicator-style* + Configures the style of the scrollback position indicator. One of + *none*, *static* or *moving*. *none* disables the indicator + completely. *static* always renders the indicator near the top at + the window, and *moving* renders the indicator at the position + corresponding to the current scrollback position. Default: + _moving_. *scrollback-indicator-format* Which format to use when displaying the scrollback position indicator. Either _percent_ or _line_. This option is ignored if - *scrollback-indicator=no*. Default: _percent_. + *scrollback-indicator-style=none*. Default: _percent_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index 624c688b..911ebb28 100644 --- a/footrc +++ b/footrc @@ -2,6 +2,8 @@ # font=monospace # scrollback=1000 +# scrollback-indicator-style=moving +# scrollback-indicator-format=percent # geometry=700x500 # pad=2x2 # initial-window-mode=windowed diff --git a/render.c b/render.c index d5cdb8dc..bab87cf4 100644 --- a/render.c +++ b/render.c @@ -1290,7 +1290,7 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { - if (!term->conf->scrollback_indicator) + if (term->conf->scrollback.indicator.style == SCROLLBACK_INDICATOR_STYLE_NONE) return; /* Find absolute row number of the scrollback start */ diff --git a/terminal.c b/terminal.c index 86672f06..1e355fe3 100644 --- a/terminal.c +++ b/terminal.c @@ -909,7 +909,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .tab_stops = tll_init(), .wl = wayl, .render = { - .scrollback_lines = conf->scrollback_lines, + .scrollback_lines = conf->scrollback.lines, .app_sync_updates.timer_fd = app_sync_updates_fd, .workers = { .count = conf->render_worker_count, -- cgit v1.3 From c2362c10f133c707101302249763e5c66d5c8653 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 10:01:05 +0200 Subject: render: search: fix subpixel argument to fcft_glyph_rasterize() --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index bab87cf4..ffab85ab 100644 --- a/render.c +++ b/render.c @@ -1660,7 +1660,7 @@ render_search_box(struct terminal *term) draw_bar(term, buf->pix[0], font, &fg, x, y); const struct fcft_glyph *glyph = fcft_glyph_rasterize( - font, term->search.buf[i], true); + font, term->search.buf[i], term->font_subpixel); if (glyph == NULL) continue; -- cgit v1.3 From 67758a7cb7207582671d223730123a63c0231642 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 10:01:26 +0200 Subject: render: scrollback indicator: wip: implement 'fixed:percent' indicator When scrollback indicator has been enabled, and the viewport isn't at the bottom, we now render a *static* indicator with the position in percent. We use the color scheme's blue color as background, and it's white color as foreground. This is subject to change... Should maybe be configurable as well. The Wayland surface + sub-surface are instantiated on-demand, and automatically destroyed when no longer used. --- render.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 100 insertions(+), 10 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index ffab85ab..a64654f2 100644 --- a/render.c +++ b/render.c @@ -1293,6 +1293,53 @@ render_scrollback_position(struct terminal *term) if (term->conf->scrollback.indicator.style == SCROLLBACK_INDICATOR_STYLE_NONE) return; + struct wayland *wayl = term->wl; + struct wl_window *win = term->window; + + if (term->grid->view == term->grid->offset) { + if (win->scrollback_indicator_surface != NULL) { + wl_subsurface_destroy(win->scrollback_indicator_sub_surface); + wl_surface_destroy(win->scrollback_indicator_surface); + + win->scrollback_indicator_surface = NULL; + win->scrollback_indicator_sub_surface = NULL; + + LOG_INFO("destroyed indicator surfaces"); + } + return; + } + + if (win->scrollback_indicator_surface == NULL) { + win->scrollback_indicator_surface + = wl_compositor_create_surface(wayl->compositor); + + if (win->scrollback_indicator_surface == NULL) { + LOG_ERR("failed to create scrollback indicator surface"); + return; + } + + wl_surface_set_user_data(win->scrollback_indicator_surface, win); + + term->window->scrollback_indicator_sub_surface + = wl_subcompositor_get_subsurface( + wayl->sub_compositor, + win->scrollback_indicator_surface, + win->surface); + + if (win->scrollback_indicator_sub_surface == NULL) { + LOG_ERR("failed to create scrollback indicator sub-surface"); + wl_surface_destroy(win->scrollback_indicator_surface); + win->scrollback_indicator_surface = NULL; + return; + } + + wl_subsurface_set_sync(win->scrollback_indicator_sub_surface); + LOG_INFO("instantiated indicator surfaces"); + } + + assert(win->scrollback_indicator_surface != NULL); + assert(win->scrollback_indicator_sub_surface != NULL); + /* Find absolute row number of the scrollback start */ int scrollback_start = term->grid->offset + term->rows; while (term->grid->rows[scrollback_start & (term->grid->num_rows - 1)] == NULL) @@ -1309,24 +1356,67 @@ render_scrollback_position(struct terminal *term) * 0% -> at the beginning of the scrollback * 100% -> at the bottom, i.e. where new lines are inserted */ - int percentage __attribute__((unused)) = + int percentage = rebased_view + term->rows == term->grid->num_rows ? 100 : 100 * rebased_view / term->grid->num_rows; - int next_row_no = term->grid->view + term->rows; - next_row_no &= term->grid->num_rows - 1; + const int scale = term->scale; + const int margin = 3 * scale; + const int width = 2 * margin + 3 * term->cell_width; /* TODO: this is percent only */ + const int height = 2 * margin + term->cell_height; - /* Are we at the end of the scrollback? */ - bool at_bottom = rebased_view + term->rows == term->grid->num_rows || - term->grid->rows[next_row_no] == NULL; + unsigned long cookie = shm_cookie_scrollback_indicator(term); + struct buffer *buf = shm_get_buffer( + term->wl->shm, width, height, cookie, false, 1); - LOG_DBG("scrollback position: %d/%d (%d%%), at-bottom: %d", - rebased_view, term->grid->num_rows, percentage, at_bottom); + pixman_color_t bg = color_hex_to_pixman(term->colors.table[4]); + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix[0], &bg, 1, + &(pixman_rectangle16_t){0, 0, width, height}); + + struct fcft_font *font = term->fonts[0]; + pixman_color_t fg = color_hex_to_pixman(term->colors.table[7]); - if (!at_bottom) { - /* TODO: insert rendering code here */ + wchar_t text[64]; + swprintf(text, sizeof(text) / sizeof(text[0]), L"%d%%", percentage); + + unsigned x = width - margin - wcslen(text) * term->cell_width; + const unsigned y = margin; + + for (size_t i = 0; i < wcslen(text); i++) { + const struct fcft_glyph *glyph = fcft_glyph_rasterize( + font, text[i], term->font_subpixel); + + if (glyph == NULL) + continue; + + pixman_image_t *src = pixman_image_create_solid_fill(&fg); + pixman_image_composite32( + PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0, + x + glyph->x, y + font_baseline(term) - glyph->y, + glyph->width, glyph->height); + pixman_image_unref(src); + + x += term->cell_width; + } + + wl_subsurface_set_position( + win->scrollback_indicator_sub_surface, + (term->width - term->margins.right - width) / scale, + term->margins.top / scale + term->cell_height); + wl_surface_attach(win->scrollback_indicator_surface, buf->wl_buf, 0, 0); + wl_surface_damage_buffer(win->scrollback_indicator_surface, 0, 0, width, height); + wl_surface_set_buffer_scale(win->scrollback_indicator_surface, scale); + + struct wl_region *region = wl_compositor_create_region(wayl->compositor); + if (region != NULL) { + wl_region_add(region, 0, 0, width, height); + wl_surface_set_opaque_region(win->scrollback_indicator_surface, region); + wl_region_destroy(region); } + + wl_surface_commit(win->scrollback_indicator_surface); } static void frame_callback( -- cgit v1.3 From 2e519ed5b6f94940f7c70b7eba42b68ccf5c18a3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 10:18:05 +0200 Subject: render: scrollback indicator: implement 'relative' and 'line' variants We now implement all combinations of 'scrollback-indicator-style' and 'scrollback-indicator-format'. --- render.c | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index a64654f2..1d21a615 100644 --- a/render.c +++ b/render.c @@ -1303,8 +1303,6 @@ render_scrollback_position(struct terminal *term) win->scrollback_indicator_surface = NULL; win->scrollback_indicator_sub_surface = NULL; - - LOG_INFO("destroyed indicator surfaces"); } return; } @@ -1334,7 +1332,6 @@ render_scrollback_position(struct terminal *term) } wl_subsurface_set_sync(win->scrollback_indicator_sub_surface); - LOG_INFO("instantiated indicator surfaces"); } assert(win->scrollback_indicator_surface != NULL); @@ -1356,14 +1353,30 @@ render_scrollback_position(struct terminal *term) * 0% -> at the beginning of the scrollback * 100% -> at the bottom, i.e. where new lines are inserted */ - int percentage = + unsigned percent = rebased_view + term->rows == term->grid->num_rows ? 100 : 100 * rebased_view / term->grid->num_rows; + wchar_t text[64]; + int cell_count; + + /* *What* to render */ + switch (term->conf->scrollback.indicator.format) { + case SCROLLBACK_INDICATOR_FORMAT_PERCENT: + swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", percent); + cell_count = 3; + break; + + case SCROLLBACK_INDICATOR_FORMAT_LINENO: + swprintf(text, sizeof(text) / sizeof(text[0]), L"%d", rebased_view + 1); + cell_count = 1 + (int)log10(term->grid->num_rows); + break; + } + const int scale = term->scale; const int margin = 3 * scale; - const int width = 2 * margin + 3 * term->cell_width; /* TODO: this is percent only */ + const int width = 2 * margin + cell_count * term->cell_width; const int height = 2 * margin + term->cell_height; unsigned long cookie = shm_cookie_scrollback_indicator(term); @@ -1378,9 +1391,7 @@ render_scrollback_position(struct terminal *term) struct fcft_font *font = term->fonts[0]; pixman_color_t fg = color_hex_to_pixman(term->colors.table[7]); - wchar_t text[64]; - swprintf(text, sizeof(text) / sizeof(text[0]), L"%d%%", percentage); - + /* Sub-surface relative coordinates */ unsigned x = width - margin - wcslen(text) * term->cell_width; const unsigned y = margin; @@ -1401,10 +1412,31 @@ render_scrollback_position(struct terminal *term) x += term->cell_width; } + /* *Where* to render - parent relative coordinates */ + int surf_top = 0; + switch (term->conf->scrollback.indicator.style) { + case SCROLLBACK_INDICATOR_STYLE_NONE: + assert(false); + return; + + case SCROLLBACK_INDICATOR_STYLE_FIXED: + surf_top = margin + term->cell_height; + break; + + case SCROLLBACK_INDICATOR_STYLE_RELATIVE: { + int lines = term->rows - 2; /* Avoid using first and last row */ + assert(lines > 0); + + int on_line = 1 + percent * lines / 100; + surf_top = margin + on_line * term->cell_height; + break; + } + } + wl_subsurface_set_position( win->scrollback_indicator_sub_surface, (term->width - term->margins.right - width) / scale, - term->margins.top / scale + term->cell_height); + surf_top / scale); wl_surface_attach(win->scrollback_indicator_surface, buf->wl_buf, 0, 0); wl_surface_damage_buffer(win->scrollback_indicator_surface, 0, 0, width, height); wl_surface_set_buffer_scale(win->scrollback_indicator_surface, scale); -- cgit v1.3 From 9a9e876d6e41da21eb3fdfc385135c8a94ce1183 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 10:42:38 +0200 Subject: render: scrollback indicator: use black on bright blue --- render.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 1d21a615..55213408 100644 --- a/render.c +++ b/render.c @@ -1383,13 +1383,13 @@ render_scrollback_position(struct terminal *term) struct buffer *buf = shm_get_buffer( term->wl->shm, width, height, cookie, false, 1); - pixman_color_t bg = color_hex_to_pixman(term->colors.table[4]); + pixman_color_t bg = color_hex_to_pixman(term->colors.table[8 + 4]); pixman_image_fill_rectangles( PIXMAN_OP_SRC, buf->pix[0], &bg, 1, &(pixman_rectangle16_t){0, 0, width, height}); struct fcft_font *font = term->fonts[0]; - pixman_color_t fg = color_hex_to_pixman(term->colors.table[7]); + pixman_color_t fg = color_hex_to_pixman(term->colors.table[0]); /* Sub-surface relative coordinates */ unsigned x = width - margin - wcslen(text) * term->cell_width; -- cgit v1.3 From 50d116dcb9183047899d93095117632c669d5f03 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 11:39:02 +0200 Subject: config: scrollback-indicator-format: percent -> percentage --- config.c | 14 ++++++++------ config.h | 2 +- doc/foot.5.scd | 4 ++-- footrc | 2 +- render.c | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index f87eb67f..2b989d62 100644 --- a/config.c +++ b/config.c @@ -307,11 +307,13 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "scrollback-indicator-format") == 0) { - if (strcmp(value, "percent") == 0) - conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_PERCENT; - else if (strcmp(value, "line") == 0) - conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; - else { + if (strcmp(value, "percent") == 0) { + conf->scrollback.indicator.format + = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE; + } else if (strcmp(value, "line") == 0) { + conf->scrollback.indicator.format + = SCROLLBACK_INDICATOR_FORMAT_LINENO; + } else { LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " "of 'percent' or 'line'", path, lineno); @@ -949,7 +951,7 @@ config_load(struct config *conf, const char *conf_path) .lines = 1000, .indicator = { .style = SCROLLBACK_INDICATOR_STYLE_RELATIVE, - .format = SCROLLBACK_INDICATOR_FORMAT_PERCENT, + .format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, }, }, .colors = { diff --git a/config.h b/config.h index 57701606..456019b5 100644 --- a/config.h +++ b/config.h @@ -50,7 +50,7 @@ struct config { } style; enum { - SCROLLBACK_INDICATOR_FORMAT_PERCENT, + SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, SCROLLBACK_INDICATOR_FORMAT_LINENO } format; } indicator; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 573eb313..c348391b 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -78,8 +78,8 @@ in this order: *scrollback-indicator-format* Which format to use when displaying the scrollback position - indicator. Either _percent_ or _line_. This option is ignored if - *scrollback-indicator-style=none*. Default: _percent_. + indicator. Either _percentage_ or _line_. This option is ignored + if *scrollback-indicator-style=none*. Default: _percentage_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index c2ee52e7..3ab2e6c1 100644 --- a/footrc +++ b/footrc @@ -3,7 +3,7 @@ # font=monospace # scrollback=1000 # scrollback-indicator-style=relative -# scrollback-indicator-format=percent +# scrollback-indicator-format=percentage # geometry=700x500 # pad=2x2 # initial-window-mode=windowed diff --git a/render.c b/render.c index 55213408..6e8a56d4 100644 --- a/render.c +++ b/render.c @@ -1363,7 +1363,7 @@ render_scrollback_position(struct terminal *term) /* *What* to render */ switch (term->conf->scrollback.indicator.format) { - case SCROLLBACK_INDICATOR_FORMAT_PERCENT: + case SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE: swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", percent); cell_count = 3; break; -- cgit v1.3 From a98484c6ebb2aa7f0ba1f99bb1f03e2d6a251b1c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 12:37:57 +0200 Subject: render: scrollback indicator: add top margin --- render.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 6e8a56d4..d9999bf0 100644 --- a/render.c +++ b/render.c @@ -1420,7 +1420,7 @@ render_scrollback_position(struct terminal *term) return; case SCROLLBACK_INDICATOR_STYLE_FIXED: - surf_top = margin + term->cell_height; + surf_top = term->cell_height - margin; break; case SCROLLBACK_INDICATOR_STYLE_RELATIVE: { @@ -1428,15 +1428,15 @@ render_scrollback_position(struct terminal *term) assert(lines > 0); int on_line = 1 + percent * lines / 100; - surf_top = margin + on_line * term->cell_height; + surf_top = on_line * term->cell_height - margin; break; } } wl_subsurface_set_position( win->scrollback_indicator_sub_surface, - (term->width - term->margins.right - width) / scale, - surf_top / scale); + (term->width - margin - width) / scale, + (term->margins.top + surf_top) / scale); wl_surface_attach(win->scrollback_indicator_surface, buf->wl_buf, 0, 0); wl_surface_damage_buffer(win->scrollback_indicator_surface, 0, 0, width, height); wl_surface_set_buffer_scale(win->scrollback_indicator_surface, scale); -- cgit v1.3 From 9bc10cdb01056fc22f6eef601a7113c8efefc195 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 27 Jul 2020 16:39:08 +0200 Subject: render: scrollback indicator: render relative indicator "smoothly" That is, don't require it to be placed on a grid row. --- render.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index d9999bf0..2f95e5b3 100644 --- a/render.c +++ b/render.c @@ -1353,10 +1353,10 @@ render_scrollback_position(struct terminal *term) * 0% -> at the beginning of the scrollback * 100% -> at the bottom, i.e. where new lines are inserted */ - unsigned percent = + double percent = rebased_view + term->rows == term->grid->num_rows - ? 100 - : 100 * rebased_view / term->grid->num_rows; + ? 1.0 + : (double)rebased_view / term->grid->num_rows; wchar_t text[64]; int cell_count; @@ -1364,7 +1364,7 @@ render_scrollback_position(struct terminal *term) /* *What* to render */ switch (term->conf->scrollback.indicator.format) { case SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE: - swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", percent); + swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", (int)(100 * percent)); cell_count = 3; break; @@ -1424,11 +1424,11 @@ render_scrollback_position(struct terminal *term) break; case SCROLLBACK_INDICATOR_STYLE_RELATIVE: { - int lines = term->rows - 2; /* Avoid using first and last row */ + int lines = term->rows - 3; /* Avoid using first and two last rows */ assert(lines > 0); - int on_line = 1 + percent * lines / 100; - surf_top = on_line * term->cell_height - margin; + int pixels = lines * term->cell_height - height + 2 * margin; + surf_top = term->cell_height - margin + (int)(percent * pixels); break; } } -- cgit v1.3 From aca5a64954ee736373d3f125632807582498c772 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 27 Jul 2020 20:00:42 +0200 Subject: render: scrollback indicator: apply weston sub-surface quirk --- render.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 2f95e5b3..59601c05 100644 --- a/render.c +++ b/render.c @@ -1433,6 +1433,7 @@ render_scrollback_position(struct terminal *term) } } + quirk_weston_subsurface_desync_on(win->scrollback_indicator_sub_surface); wl_subsurface_set_position( win->scrollback_indicator_sub_surface, (term->width - margin - width) / scale, @@ -1449,6 +1450,7 @@ render_scrollback_position(struct terminal *term) } wl_surface_commit(win->scrollback_indicator_surface); + quirk_weston_subsurface_desync_off(win->scrollback_indicator_sub_surface); } static void frame_callback( -- cgit v1.3 From 718e5b4a7787cc9d68b9c422b8b6703f3b7c5c26 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 27 Jul 2020 20:02:51 +0200 Subject: config: rename scrollback-indicator-style to scrollback-indicator-position --- CHANGELOG.md | 2 +- config.c | 12 ++++++------ config.h | 8 ++++---- doc/foot.5.scd | 4 ++-- footrc | 2 +- render.c | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) (limited to 'render.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 35669232..dc6fc301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ * Mouse cursor is now always a `left_ptr` when inside the margins, to indicate it is not possible to start a selection. * Scrollback position indicator. This feature is optional and - controlled by the **scrollback-indicator-style** and + controlled by the **scrollback-indicator-position** and **scrollback-indicator-format** options in `footrc` (https://codeberg.org/dnkl/foot/issues/42). diff --git a/config.c b/config.c index 2b989d62..169b2b40 100644 --- a/config.c +++ b/config.c @@ -291,15 +291,15 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback.lines = lines; } - else if (strcmp(key, "scrollback-indicator-style") == 0) { + else if (strcmp(key, "scrollback-indicator-position") == 0) { if (strcmp(value, "none") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_NONE; + conf->scrollback.indicator.position = SCROLLBACK_INDICATOR_POSITION_NONE; else if (strcmp(value, "fixed") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_FIXED; + conf->scrollback.indicator.position = SCROLLBACK_INDICATOR_POSITION_FIXED; else if (strcmp(value, "relative") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_RELATIVE; + conf->scrollback.indicator.position = SCROLLBACK_INDICATOR_POSITION_RELATIVE; else { - LOG_ERR("%s:%d: scrollback-indicator-style must be one of " + LOG_ERR("%s:%d: scrollback-indicator-position must be one of " "'none', 'fixed' or 'moving'", path, lineno); return false; @@ -950,7 +950,7 @@ config_load(struct config *conf, const char *conf_path) .scrollback = { .lines = 1000, .indicator = { - .style = SCROLLBACK_INDICATOR_STYLE_RELATIVE, + .position = SCROLLBACK_INDICATOR_POSITION_RELATIVE, .format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, }, }, diff --git a/config.h b/config.h index 456019b5..eee01e65 100644 --- a/config.h +++ b/config.h @@ -44,10 +44,10 @@ struct config { struct { enum { - SCROLLBACK_INDICATOR_STYLE_NONE, - SCROLLBACK_INDICATOR_STYLE_FIXED, - SCROLLBACK_INDICATOR_STYLE_RELATIVE - } style; + SCROLLBACK_INDICATOR_POSITION_NONE, + SCROLLBACK_INDICATOR_POSITION_FIXED, + SCROLLBACK_INDICATOR_POSITION_RELATIVE + } position; enum { SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 188e8edf..949e2751 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,7 +68,7 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. -*scrollback-indicator-style* +*scrollback-indicator-position* Configures the style of the scrollback position indicator. One of *none*, *fixed* or *relative*. *none* disables the indicator completely. *fixed* always renders the indicator near the top at @@ -79,7 +79,7 @@ in this order: *scrollback-indicator-format* Which format to use when displaying the scrollback position indicator. Either _percentage_ or _line_. This option is ignored - if *scrollback-indicator-style=none*. Default: _percentage_. + if *scrollback-indicator-position=none*. Default: _percentage_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index 117b73fe..900ce149 100644 --- a/footrc +++ b/footrc @@ -2,7 +2,7 @@ # font=monospace # scrollback=1000 -# scrollback-indicator-style=relative +# scrollback-indicator-position=relative # scrollback-indicator-format=percentage # geometry=700x500 # pad=2x2 diff --git a/render.c b/render.c index 59601c05..195839fb 100644 --- a/render.c +++ b/render.c @@ -1290,7 +1290,7 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { - if (term->conf->scrollback.indicator.style == SCROLLBACK_INDICATOR_STYLE_NONE) + if (term->conf->scrollback.indicator.position == SCROLLBACK_INDICATOR_POSITION_NONE) return; struct wayland *wayl = term->wl; @@ -1414,16 +1414,16 @@ render_scrollback_position(struct terminal *term) /* *Where* to render - parent relative coordinates */ int surf_top = 0; - switch (term->conf->scrollback.indicator.style) { - case SCROLLBACK_INDICATOR_STYLE_NONE: + switch (term->conf->scrollback.indicator.position) { + case SCROLLBACK_INDICATOR_POSITION_NONE: assert(false); return; - case SCROLLBACK_INDICATOR_STYLE_FIXED: + case SCROLLBACK_INDICATOR_POSITION_FIXED: surf_top = term->cell_height - margin; break; - case SCROLLBACK_INDICATOR_STYLE_RELATIVE: { + case SCROLLBACK_INDICATOR_POSITION_RELATIVE: { int lines = term->rows - 3; /* Avoid using first and two last rows */ assert(lines > 0); -- cgit v1.3 From 2882fbb537f53feb33d407c3aac103d0189af725 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 28 Jul 2020 19:56:53 +0200 Subject: config: add free-form text variant to 'scrollback-indicator-format' And make the empty string the new default. --- config.c | 19 ++++++++++++++----- config.h | 5 ++++- doc/footrc.5.scd | 5 +++-- footrc | 2 +- render.c | 12 +++++++++--- 5 files changed, 31 insertions(+), 12 deletions(-) (limited to 'render.c') diff --git a/config.c b/config.c index 8da9c258..19e2a2ca 100644 --- a/config.c +++ b/config.c @@ -314,10 +314,17 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; } else { - LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " - "of 'percent' or 'line'", - path, lineno); - return false; + free(conf->scrollback.indicator.text); + conf->scrollback.indicator.text = NULL; + + size_t len = mbstowcs(NULL, value, -1); + if (len < 0) { + LOG_ERRNO("%s:%d: invalid scrollback-indicator-format value", path, lineno); + return false; + } + + conf->scrollback.indicator.text = calloc(len + 1, sizeof(wchar_t)); + mbstowcs(conf->scrollback.indicator.text, value, len); } } @@ -967,7 +974,8 @@ config_load(struct config *conf, const char *conf_path) .lines = 1000, .indicator = { .position = SCROLLBACK_INDICATOR_POSITION_RELATIVE, - .format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, + .format = SCROLLBACK_INDICATOR_FORMAT_TEXT, + .text = wcsdup(L""), }, }, .colors = { @@ -1119,6 +1127,7 @@ config_free(struct config conf) free(conf.shell); free(conf.title); free(conf.app_id); + free(conf.scrollback.indicator.text); tll_foreach(conf.fonts, it) config_font_destroy(&it->item); tll_free(conf.fonts); diff --git a/config.h b/config.h index eee01e65..9de282a0 100644 --- a/config.h +++ b/config.h @@ -51,8 +51,11 @@ struct config { enum { SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, - SCROLLBACK_INDICATOR_FORMAT_LINENO + SCROLLBACK_INDICATOR_FORMAT_LINENO, + SCROLLBACK_INDICATOR_FORMAT_TEXT, } format; + + wchar_t *text; } indicator; } scrollback; diff --git a/doc/footrc.5.scd b/doc/footrc.5.scd index f23d7a36..6bba164f 100644 --- a/doc/footrc.5.scd +++ b/doc/footrc.5.scd @@ -78,8 +78,9 @@ in this order: *scrollback-indicator-format* Which format to use when displaying the scrollback position - indicator. Either _percentage_ or _line_. This option is ignored - if *scrollback-indicator-position=none*. Default: _percentage_. + indicator. Either _percentage_, _line_, or a custom fixed + string. This option is ignored if + *scrollback-indicator-position=none*. Default: _empty string_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index 900ce149..30eeee39 100644 --- a/footrc +++ b/footrc @@ -3,7 +3,7 @@ # font=monospace # scrollback=1000 # scrollback-indicator-position=relative -# scrollback-indicator-format=percentage +# scrollback-indicator-format= # geometry=700x500 # pad=2x2 # initial-window-mode=windowed diff --git a/render.c b/render.c index 195839fb..92b546ed 100644 --- a/render.c +++ b/render.c @@ -1358,20 +1358,26 @@ render_scrollback_position(struct terminal *term) ? 1.0 : (double)rebased_view / term->grid->num_rows; - wchar_t text[64]; + wchar_t _text[64]; + const wchar_t *text = _text; int cell_count; /* *What* to render */ switch (term->conf->scrollback.indicator.format) { case SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE: - swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", (int)(100 * percent)); + swprintf(_text, sizeof(_text) / sizeof(_text[0]), L"%u%%", (int)(100 * percent)); cell_count = 3; break; case SCROLLBACK_INDICATOR_FORMAT_LINENO: - swprintf(text, sizeof(text) / sizeof(text[0]), L"%d", rebased_view + 1); + swprintf(_text, sizeof(_text) / sizeof(_text[0]), L"%d", rebased_view + 1); cell_count = 1 + (int)log10(term->grid->num_rows); break; + + case SCROLLBACK_INDICATOR_FORMAT_TEXT: + text = term->conf->scrollback.indicator.text; + cell_count = wcslen(text); + break; } const int scale = term->scale; -- cgit v1.3