osc: extend damage-cells-by-color to default fg/bg as well

When changing part of the color palette, through either OSC-4, or
OSC-10 and OSC-11 (and the corresponding reset OSCs: 104, 110 and
111), only dirty affected cells.

We've always done this, but only for OSC-4.

This patch breaks out that logic, and extends it to handle default
fg/bg too.

It also fixes a bug where cells with colored underlines were not
dirtied if the underline was the only part of the cell that was
affected by a OSC-4 change.
This commit is contained in:
Daniel Eklöf 2024-07-03 10:53:33 +02:00
parent e5ed387426
commit 22c8637610
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 102 additions and 51 deletions

56
osc.c
View file

@ -651,47 +651,7 @@ osc_dispatch(struct terminal *term)
idx, term->colors.table[idx], color);
term->colors.table[idx] = color;
/* Dirty visible, affected cells */
for (int r = 0; r < term->rows; r++) {
struct row *row = grid_row_in_view(term->grid, r);
struct cell *cell = &row->cells[0];
for (int c = 0; c < term->cols; c++, cell++) {
bool dirty = false;
switch (cell->attrs.fg_src) {
case COLOR_BASE16:
case COLOR_BASE256:
if (cell->attrs.fg == idx)
dirty = true;
break;
case COLOR_DEFAULT:
case COLOR_RGB:
/* Not affected */
break;
}
switch (cell->attrs.bg_src) {
case COLOR_BASE16:
case COLOR_BASE256:
if (cell->attrs.bg == idx)
dirty = true;
break;
case COLOR_DEFAULT:
case COLOR_RGB:
/* Not affected */
break;
}
if (dirty) {
cell->attrs.clean = 0;
row->dirty = true;
}
}
}
term_damage_color(term, COLOR_BASE256, idx);
}
}
@ -772,7 +732,7 @@ osc_dispatch(struct terminal *term)
switch (param) {
case 10:
term->colors.fg = color;
term_damage_view(term);
term_damage_color(term, COLOR_DEFAULT, 0);
break;
case 11:
@ -786,7 +746,7 @@ osc_dispatch(struct terminal *term)
term_font_subpixel_changed(term);
}
}
term_damage_view(term);
term_damage_color(term, COLOR_DEFAULT, 0);
term_damage_margins(term);
break;
@ -798,13 +758,11 @@ osc_dispatch(struct terminal *term)
case 17:
term->colors.selection_bg = color;
term->colors.use_custom_selection = true;
term_damage_view(term);
break;
case 19:
term->colors.selection_fg = color;
term->colors.use_custom_selection = true;
term_damage_view(term);
break;
}
@ -829,6 +787,7 @@ osc_dispatch(struct terminal *term)
LOG_DBG("resetting all colors");
for (size_t i = 0; i < ALEN(term->colors.table); i++)
term->colors.table[i] = term->conf->colors.table[i];
term_damage_view(term);
}
else {
@ -850,11 +809,10 @@ osc_dispatch(struct terminal *term)
LOG_DBG("resetting color #%u", idx);
term->colors.table[idx] = term->conf->colors.table[idx];
term_damage_color(term, COLOR_BASE256, idx);
}
}
term_damage_view(term);
break;
}
@ -864,14 +822,14 @@ osc_dispatch(struct terminal *term)
case 110: /* Reset default text foreground color */
LOG_DBG("resetting foreground color");
term->colors.fg = term->conf->colors.fg;
term_damage_view(term);
term_damage_color(term, COLOR_DEFAULT, 0);
break;
case 111: /* Reset default text background color */
LOG_DBG("resetting background color");
term->colors.bg = term->conf->colors.bg;
term->colors.alpha = term->conf->colors.alpha;
term_damage_view(term);
term_damage_color(term, COLOR_DEFAULT, 0);
term_damage_margins(term);
break;