sixel: insert: sort sixels such that those furthest up in the scrollback is at the back

This commit is contained in:
Daniel Eklöf 2020-06-28 09:16:43 +02:00
parent 247e0c42d3
commit 4a0042ba15
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

19
sixel.c
View file

@ -90,6 +90,25 @@ sixel_erase(struct terminal *term, struct sixel *sixel)
static void
sixel_insert(struct terminal *term, struct sixel sixel)
{
const int scrollback_end
= (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
int end_row = sixel.pos.row + sixel.rows - scrollback_end;
while (end_row < 0)
end_row += term->grid->num_rows;
tll_foreach(term->grid->sixel_images, it) {
int e = it->item.pos.row + it->item.rows - scrollback_end;
e -= scrollback_end;
while (e < 0)
e += term->grid->num_rows;
if (e < end_row) {
tll_insert_before(term->grid->sixel_images, it, sixel);
return;
}
}
tll_push_back(term->grid->sixel_images, sixel);
}