From cc24c5f2e0c74774add0113f0bea2ed6c5aab28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 25 Aug 2020 18:39:50 +0200 Subject: [PATCH 1/3] render: scrollback position: only count _used_ scrollback lines When calculating where in the scrollback history we are, we previously did this against the total number of scrollback lines. I.e. the `scrollback.lines` setting in `footrc`. Now, we count only the used/allocated scrollback lines. Note that the initial indicator position might still seem to start a bit high up, if the number of used scrollback lines is low. This is because we use the *top* of the screen for the current position. Thus, we'll never be at the bottom (except for the special case when we're *really* at the bottom). --- CHANGELOG.md | 2 ++ render.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76fa3802..c5e9e6b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ * Default `--server` socket path to use `$WAYLAND_DISPLAY` instead of `$XDG_SESSION_ID` (https://codeberg.org/dnkl/foot/issues/55). * Trailing empty cells are no longer highlighted in mouse selections. +* Scrollback position indicator is now based on the number of _used_ + scrollback lines, instead of the _total_ number of scrollback lines. ### Fixed diff --git a/render.c b/render.c index 12003468..dba047e5 100644 --- a/render.c +++ b/render.c @@ -1399,14 +1399,22 @@ render_scrollback_position(struct terminal *term) /* 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) + int empty_rows = 0; + while (term->grid->rows[scrollback_start & (term->grid->num_rows - 1)] == NULL) { scrollback_start++; + empty_rows++; + } /* 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 much of the scrollback is actually used? */ + int populated_rows = term->grid->num_rows - empty_rows; + assert(populated_rows > 0); + assert(populated_rows <= term->grid->num_rows); + /* * How far down in the scrollback we are. * @@ -1414,9 +1422,9 @@ render_scrollback_position(struct terminal *term) * 100% -> at the bottom, i.e. where new lines are inserted */ double percent = - rebased_view + term->rows == term->grid->num_rows + rebased_view + term->rows == populated_rows ? 1.0 - : (double)rebased_view / term->grid->num_rows; + : (double)rebased_view / populated_rows; wchar_t _text[64]; const wchar_t *text = _text; From 1109865c8e892137152da802f028e30bcdd49aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 26 Aug 2020 19:10:00 +0200 Subject: [PATCH 2/3] render: scrollback indicator: subtract visible rows from populated rows This prevents the indicator from starting too high up when the number of used scrollback rows is low. --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render.c b/render.c index dba047e5..d588718d 100644 --- a/render.c +++ b/render.c @@ -1424,7 +1424,7 @@ render_scrollback_position(struct terminal *term) double percent = rebased_view + term->rows == populated_rows ? 1.0 - : (double)rebased_view / populated_rows; + : (double)rebased_view / (populated_rows - term->rows); wchar_t _text[64]; const wchar_t *text = _text; From c8d0dc5750adef034c6616491d9ba6eee5501992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 26 Aug 2020 19:12:12 +0200 Subject: [PATCH 3/3] render: scrollback indicator: only leave room for search box when necessary --- render.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/render.c b/render.c index d588718d..34544356 100644 --- a/render.c +++ b/render.c @@ -1469,7 +1469,11 @@ render_scrollback_position(struct terminal *term) break; case SCROLLBACK_INDICATOR_POSITION_RELATIVE: { - int lines = term->rows - 3; /* Avoid using first and two last rows */ + int lines = term->rows - 2; /* Avoid using first and last rows */ + if (term->is_searching) { + /* Make sure we don't collide with the scrollback search box */ + lines--; + } assert(lines > 0); int pixels = lines * term->cell_height - height + 2 * margin;