diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-10-04 11:12:44 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-10-09 05:44:16 +0000 |
| commit | dbfc636ade8bd59a4a5af4531c19af8a163e8c09 (patch) | |
| tree | bde150d22aa31038a879be13ad3d0ceaca6c9ec5 /sixel.c | |
| parent | term: update sixel rows/cols *after* cell dimension change, *before* resize (diff) | |
sixel: implement reflow
Move sixel reflow from grid_reflow() to sixel_reflow(). This lets us
use internal sixel functions to update the sixels.
Note that grid_reflow() still needs to remap the sixelss coordinates.
Diffstat (limited to 'sixel.c')
| -rw-r--r-- | sixel.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -509,6 +509,54 @@ sixel_cell_size_changed(struct terminal *term) } void +sixel_reflow(struct terminal *term) +{ + struct grid *g = term->grid; + + for (size_t i = 0; i < 2; i++) { + struct grid *grid = i == 0 ? &term->normal : &term->alt; + + term->grid = grid; + + /* Need the “real” list to be empty from the beginning */ + tll(struct sixel) copy = tll_init(); + tll_foreach(grid->sixel_images, it) + tll_push_back(copy, it->item); + tll_free(grid->sixel_images); + + tll_rforeach(copy, it) { + struct sixel *six = &it->item; + int start = six->pos.row; + int end = (start + six->rows - 1) & (grid->num_rows - 1); + + if (end < start) { + /* Crosses scrollback wrap-around */ + /* TOOD: split image */ + sixel_destroy(six); + continue; + } + + if (six->rows > grid->num_rows) { + /* Image too large */ + /* TODO: keep bottom part? */ + sixel_destroy(six); + continue; + } + + /* Sixels that didn’t overlap may now do so, which isn’t + * allowed of course */ + _sixel_overwrite_by_rectangle( + term, six->pos.row, six->pos.col, six->rows, six->cols); + sixel_insert(term, it->item); + } + + tll_free(copy); + } + + term->grid = g; +} + +void sixel_unhook(struct terminal *term) { int pixel_row_idx = 0; |
