diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-03-13 17:44:23 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-03-13 17:47:16 +0000 |
| commit | d482bf0a304b8224499bf9de9e0781518106ec7c (patch) | |
| tree | afc68b49ecaa21a3f1d5a089cfa5a7b18a95d654 /grid.c | |
| parent | input: maximize: unset fullscreen before toggling maximized state (diff) | |
sixel: improve handling of images when reflowing the grids
Update the sixels' 'row' attribute when re-flowing a grid, to ensure
it is rendered at the correct place.
This should work in most cases, but will break when the cell size has
changed (e.g. font size increase/decrease, or a DPI change).
This patch also moves the sixel image list from the terminal struct
into the grid struct. The sixels are per-grid after all.
Diffstat (limited to 'grid.c')
| -rw-r--r-- | grid.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -6,6 +6,7 @@ #define LOG_MODULE "grid" #define LOG_ENABLE_DBG 0 #include "log.h" +#include "sixel.h" #define max(x, y) ((x) > (y) ? (x) : (y)) @@ -76,6 +77,8 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, * at the output that is *oldest* */ int offset = grid->offset + old_screen_rows; + tll(struct sixel) new_sixels = tll_init(); + /* * Walk the old grid */ @@ -87,6 +90,28 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, continue; /* + * Update 'row' in all sixels that *begin* at current row + * + * Since we might end up pushing the sixel down, we can't + * simply update the row inline - we'd then end up pushing the + * sixel down again, when we reach the next 'old' + * row. Instead, copy the sixel (with 'row' updated), to a + * temporary list and remove the original sixel. + * + * After we've reflowed the grid we'll move the sixels back to + * the "real" sixel list. + */ + tll_foreach(grid->sixel_images, it) { + if (it->item.pos.row == ((offset + r) & (old_rows - 1))) { + struct sixel six = it->item; + six.pos.row = new_row_idx; + + tll_push_back(new_sixels, six); + tll_remove(grid->sixel_images, it); + } + } + + /* * Keep track of empty cells. If the old line ends with a * string of empty cells, we don't need to, nor do we want to, * add those to the new line. However, if there are non-empty @@ -191,5 +216,15 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, grid->num_rows = new_rows; grid->num_cols = new_cols; + /* Destroy any non-moved sixels */ + tll_foreach(grid->sixel_images, it) + sixel_destroy(&it->item); + tll_free(grid->sixel_images); + + /* Move updated sixels back */ + tll_foreach(new_sixels, it) + tll_push_back(grid->sixel_images, it->item); + tll_free(new_sixels); + return new_row_idx; } |
