aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-08-05 16:26:37 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-08-05 16:26:37 +0000
commitaaf5894ad9272698cfafeb8e299b925fb9554417 (patch)
tree62cea6ec7e4b0a0ec034cb38daf49af4d4075370
parentAdd support for xdg_toplevel.wm_capabilities (diff)
grid: get rid of empty row at the bottom after reflowing
When the window is resized and we reflow the text, we ended up inserting an empty row at the bottom. This happens whenever the actual last row has a hard linebreak (which almost always is the case); we then end the reflow with a line break, causing an extra, empty, row to be allocated and inserted. This patch fixes this by detecting when: 1) the last row is empty 2) the next to last row has a hard line break In this case, we roll back the last line break, by adjusting the new offset we just calculated, and free:ing the empty row. TODO: it would be nice if we could detect this in the reflow loop instead, and avoid doing the last line break all together. I haven’t yet been able to find a way to do this correctly. Closes #1108
-rw-r--r--CHANGELOG.md2
-rw-r--r--grid.c20
2 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b82cfa00..1dddd2d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -109,6 +109,7 @@
* Poor performance when making very large selections ([#1114][1114]).
* Bogus error message when using systemd socket activation for server
mode ([#1107][1107])
+* Empty line at the bottom after a window resize ([#1108][1108]).
[1055]: https://codeberg.org/dnkl/foot/issues/1055
[1092]: https://codeberg.org/dnkl/foot/issues/1092
@@ -117,6 +118,7 @@
[1120]: https://codeberg.org/dnkl/foot/issues/1120
[1114]: https://codeberg.org/dnkl/foot/issues/1114
[1107]: https://codeberg.org/dnkl/foot/issues/1107
+[1108]: https://codeberg.org/dnkl/foot/issues/1108
### Security
diff --git a/grid.c b/grid.c
index 2790d16b..f40803e1 100644
--- a/grid.c
+++ b/grid.c
@@ -984,6 +984,26 @@ grid_resize_and_reflow(
/* Set offset such that the last reflowed row is at the bottom */
grid->offset = new_row_idx - new_screen_rows + 1;
+
+ if (new_col_idx == 0) {
+ int next_to_last_new_row_idx = new_row_idx - 1;
+ next_to_last_new_row_idx += new_rows;
+ next_to_last_new_row_idx &= new_rows - 1;
+
+ const struct row *next_to_last_row = new_grid[next_to_last_new_row_idx];
+ if (next_to_last_row != NULL && next_to_last_row->linebreak) {
+ /*
+ * The next to last row is actually the *last* row. But we
+ * ended the reflow with a line-break, causing an empty
+ * row to be inserted at the bottom. Undo this.
+ */
+ /* TODO: can we detect this in the reflow loop above instead? */
+ grid->offset--;
+ grid_row_free(new_grid[new_row_idx]);
+ new_grid[new_row_idx] = NULL;
+ }
+ }
+
while (grid->offset < 0)
grid->offset += new_rows;
while (new_grid[grid->offset] == NULL)