grid: enable rows to have ‘extra’ data associated with them

This patch adds an ‘extra’ member to the row struct. It is a pointer
to a struct containing extra data to be associated with this row.

Initially, this struct contains a list of URL ranges. These
define (OSC-8) URLs on this row.

The ‘extra’ data is allocated on-demand. I.e. the pointer is NULL by
default; it is *not* allocated by grid_row_alloc().
This commit is contained in:
Daniel Eklöf 2021-02-13 12:31:55 +01:00
parent 3339915d20
commit fd87bca102
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 44 additions and 4 deletions

9
grid.c
View file

@ -33,6 +33,7 @@ grid_row_alloc(int cols, bool initialize)
struct row *row = xmalloc(sizeof(*row));
row->dirty = false;
row->linebreak = false;
row->extra = NULL;
if (initialize) {
row->cells = xcalloc(cols, sizeof(row->cells[0]));
@ -50,6 +51,14 @@ grid_row_free(struct row *row)
if (row == NULL)
return;
if (row->extra != NULL) {
tll_foreach(row->extra->uri_ranges, it) {
free(it->item.uri);
tll_remove(row->extra->uri_ranges, it);
}
}
free(row->extra);
free(row->cells);
free(row);
}