From d482bf0a304b8224499bf9de9e0781518106ec7c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 13 Mar 2020 18:44:23 +0100 Subject: 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. --- sixel.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 90d886fe..98a82deb 100644 --- a/sixel.c +++ b/sixel.c @@ -76,22 +76,19 @@ sixel_erase(struct terminal *term, struct sixel *sixel) void sixel_delete_at_row(struct terminal *term, int _row) { - if (likely(tll_length(term->sixel_images) == 0)) + if (likely(tll_length(term->grid->sixel_images) == 0)) return; - tll_foreach(term->sixel_images, it) { + tll_foreach(term->grid->sixel_images, it) { struct sixel *six = &it->item; - if (six->grid != term->grid) - continue; - const int row = (term->grid->offset + _row) & (term->grid->num_rows - 1); const int six_start = six->pos.row; const int six_end = six_start + six->rows - 1; if (row >= six_start && row <= six_end) { sixel_erase(term, six); - tll_remove(term->sixel_images, it); + tll_remove(term->grid->sixel_images, it); } } } @@ -101,18 +98,15 @@ sixel_delete_in_range(struct terminal *term, int _start, int _end) { assert(_end >= _start); - if (likely(tll_length(term->sixel_images) == 0)) + if (likely(tll_length(term->grid->sixel_images) == 0)) return; if (_start == _end) return sixel_delete_at_row(term, _start); - tll_foreach(term->sixel_images, it) { + tll_foreach(term->grid->sixel_images, it) { struct sixel *six = &it->item; - if (six->grid != term->grid) - continue; - const int start = (term->grid->offset + _start) & (term->grid->num_rows - 1); const int end = start + (_end - _start); const int six_start = six->pos.row; @@ -123,7 +117,7 @@ sixel_delete_in_range(struct terminal *term, int _start, int _end) (start >= six_start && end <= six_end)) /* Fully within sixel range */ { sixel_erase(term, six); - tll_remove(term->sixel_images, it); + tll_remove(term->grid->sixel_images, it); } } } @@ -147,7 +141,6 @@ sixel_unhook(struct terminal *term) .width = term->sixel.image.width, .height = term->sixel.image.height, .rows = (term->sixel.image.height + term->cell_height - 1) / term->cell_height, - .grid = term->grid, .pos = (struct coord){ term->cursor.point.col, (term->grid->offset + term->cursor.point.row) & (term->grid->num_rows - 1)}, @@ -172,7 +165,7 @@ sixel_unhook(struct terminal *term) term_formfeed(term); render_refresh(term); - tll_push_back(term->sixel_images, image); + tll_push_back(term->grid->sixel_images, image); } static unsigned -- cgit v1.3