This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit ac5089e25d32fab0a78965c0f173c588f82ecd75
Author: Boris Faure <[email protected]>
AuthorDate: Fri Oct 30 15:09:58 2026 +0000
termio: keep palette overrides across configuration updates
OSC 4 will let an application rewrite palette colours. Storing them in
the textgrid alone is not enough: colors_term_init() rewrites both
palettes, and it runs from termio_config_update() on font changes and
on every config sync, and from change_theme(). A font-size change would
silently drop the application's palette.
Keep the overridden colours and a bitmap of which entries the
application overrode in the Termio itself. termio_palette_apply()
rewrites the scheme and then the overrides on top, and
termio_config_update() now calls it instead of colors_term_init().
change_theme() drops the overrides instead: the user picked a new
scheme, and the same code path already drops OSC 10/11/12 overrides.
Mode 2031 reporting, once it lands, tells the application to re-query.
For an entry below 16, colors_palette_color_set() also writes the
standard palette's normal (or bright) slot and the matching faint slot
blended with the scheme's background at 75%, so that SGR text follows
the palette like 38;5;n text does, and faint text stays faint. That
blend is how data/colorschemes/gen_faint.py builds the shipped schemes.
There is no user-visible change yet: nothing sets an override, and
termio_palette_apply() rewrites exactly what colors_term_init() did.
Checked through the tytest_palette_slots unit test for the slot and
blend arithmetic.
---
src/bin/colors.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
src/bin/colors.h | 7 ++++
src/bin/termio.c | 44 ++++++++++++++++++++++-
src/bin/termio.h | 6 ++++
src/bin/termiointernals.h | 6 ++++
src/bin/tytest.c | 1 +
src/bin/tytest_common.c | 83 +++++++++++++++++++++++++++++++++++++++----
src/bin/unit_tests.h | 1 +
src/bin/win.c | 3 +-
9 files changed, 231 insertions(+), 10 deletions(-)
diff --git a/src/bin/colors.c b/src/bin/colors.c
index f0117b4c..b57aa2ac 100644
--- a/src/bin/colors.c
+++ b/src/bin/colors.c
@@ -576,6 +576,63 @@ colors_term_init(Evas_Object *textgrid,
#undef CS_SET
}
+/* faint text is the colour blended with the background at 75%, as
+ * data/colorschemes/gen_faint.py builds the shipped schemes */
+static int
+_colors_faint(int bg, int c)
+{
+ return bg + ((c - bg) * 75) / 100;
+}
+
+/* the standard palette slots an ANSI colour 0-15 is served through: the
+ * normal (or bright) one and the matching faint one, -1 when idx is out
+ * of the range the standard palette serves */
+static void
+_colors_palette_slots(int idx, int *normal, int *faint)
+{
+ int set, slot;
+
+ if ((idx < 0) || (idx > 15))
+ {
+ *normal = -1;
+ *faint = -1;
+ return;
+ }
+ set = (idx < 8) ? 0 : 1;
+ slot = 1 + (idx % 8);
+ *normal = set * 12 + slot;
+ *faint = (set + 2) * 12 + slot;
+}
+
+void
+colors_palette_color_set(Evas_Object *textgrid,
+ const Color_Scheme *cs,
+ int idx,
+ const Color *c)
+{
+ int normal, faint;
+
+ if (!cs)
+ cs = &default_colorscheme;
+ if ((idx < 0) || (idx > 255))
+ return;
+ evas_object_textgrid_palette_set(textgrid,
+ EVAS_TEXTGRID_PALETTE_EXTENDED, idx,
+ c->r, c->g, c->b, 0xff);
+ _colors_palette_slots(idx, &normal, &faint);
+ if (normal < 0)
+ return;
+ evas_object_textgrid_palette_set(textgrid,
+ EVAS_TEXTGRID_PALETTE_STANDARD, normal,
+ c->r, c->g, c->b, 0xff);
+ evas_object_textgrid_palette_set(textgrid,
+ EVAS_TEXTGRID_PALETTE_STANDARD, faint,
+ _colors_faint(cs->bg.r, c->r),
+ _colors_faint(cs->bg.g, c->g),
+ _colors_faint(cs->bg.b, c->b),
+ 0xff);
+}
+
void
colors_standard_get(int set, int col,
unsigned char *r,
@@ -1247,4 +1304,37 @@ tytest_colors_is_dark(void)
return 0;
}
+
+int
+tytest_palette_slots(void)
+{
+ static const struct {
+ int idx;
+ int normal;
+ int faint;
+ } table[] = {
+ { 0, 1, 25 },
+ { 7, 8, 32 },
+ { 8, 13, 37 },
+ { 15, 20, 44 },
+ { 16, -1, -1 },
+ { 255, -1, -1 },
+ { -1, -1, -1 },
+ };
+ size_t i;
+ int normal, faint;
+
+ for (i = 0; i < sizeof(table) / sizeof(table[0]); i++)
+ {
+ _colors_palette_slots(table[i].idx, &normal, &faint);
+ assert(normal == table[i].normal);
+ assert(faint == table[i].faint);
+ }
+
+ /* the blend of Default.ini's [Normal] red with bg #202020, as
+ * gen_faint.py computes it */
+ assert(_colors_faint(0x20, 0xcc) == 0xa1);
+
+ return 0;
+}
#endif
diff --git a/src/bin/colors.h b/src/bin/colors.h
index ceda43ad..ab45ea3b 100644
--- a/src/bin/colors.h
+++ b/src/bin/colors.h
@@ -56,6 +56,13 @@ void
colors_term_init(Evas_Object *textgrid,
const Color_Scheme *cs);
+/* write @idx's colour into the textgrid, and its faint slots for 0-15 */
+void
+colors_palette_color_set(Evas_Object *textgrid,
+ const Color_Scheme *cs,
+ int idx,
+ const Color *c);
+
/* Approximate an RGB colour by the closest entry of @textgrid's extended
* 256-colour palette, weighted redmean distance, with a small cache of
* recent results. Under tyfuzz this always returns COL_DEF. */
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 872e6ad9..3a3ba133 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -217,6 +217,48 @@ termio_palette_color_get(const Evas_Object *obj, int idx,
return EINA_TRUE;
}
+void
+termio_palette_color_set(Evas_Object *obj, int idx, int r, int g, int b)
+{
+ Termio *sd = evas_object_smart_data_get(obj);
+ Color c = { .r = r, .g = g, .b = b, .a = 0xff };
+
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+ if ((idx < 0) || (idx > 255))
+ return;
+ sd->palette.colors[idx] = c;
+ sd->palette.overridden[idx / 32] |= 1u << (idx % 32);
+ colors_palette_color_set(sd->grid.obj, sd->config->color_scheme,
+ idx, &c);
+}
+
+/* rewrites the scheme, then the application's palette overrides on top */
+void
+termio_palette_apply(Evas_Object *obj)
+{
+ Termio *sd = evas_object_smart_data_get(obj);
+ int i;
+
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+ colors_term_init(sd->grid.obj, sd->config->color_scheme);
+ for (i = 0; i < 256; i++)
+ {
+ if (sd->palette.overridden[i / 32] & (1u << (i % 32)))
+ colors_palette_color_set(sd->grid.obj, sd->config->color_scheme,
+ i, &sd->palette.colors[i]);
+ }
+}
+
+void
+termio_palette_reset(Evas_Object *obj)
+{
+ Termio *sd = evas_object_smart_data_get(obj);
+
+ EINA_SAFETY_ON_NULL_RETURN(sd);
+ memset(sd->palette.overridden, 0, sizeof(sd->palette.overridden));
+ termio_palette_apply(obj);
+}
+
void
termio_fg_color_get(const Evas_Object *obj, int *r, int *g, int *b)
{
@@ -680,7 +722,7 @@ termio_config_update(Evas_Object *obj)
termpty_config_update(sd->pty, sd->config);
sd->scroll = 0;
- colors_term_init(sd->grid.obj, sd->config->color_scheme);
+ termio_palette_apply(obj);
evas_object_textgrid_font_set(sd->grid.obj, sd->font.name, sd->font.size);
_termio_ligatures_update(sd);
diff --git a/src/bin/termio.h b/src/bin/termio.h
index adbffbf2..b1222aac 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -112,4 +112,10 @@ termio_reset_main_colors(Evas_Object *termio);
Eina_Bool
termio_palette_color_get(const Evas_Object *obj, int idx,
int *r, int *g, int *b);
+void
+termio_palette_color_set(Evas_Object *obj, int idx, int r, int g, int b);
+void
+termio_palette_reset(Evas_Object *obj);
+void
+termio_palette_apply(Evas_Object *obj);
#endif
diff --git a/src/bin/termiointernals.h b/src/bin/termiointernals.h
index 7d2ee824..19ac552b 100644
--- a/src/bin/termiointernals.h
+++ b/src/bin/termiointernals.h
@@ -91,6 +91,12 @@ struct tag_Termio
int b;
int a;
} saved_bg, saved_fg, saved_cursor;
+ /* palette colours set by the application with OSC 4, re-applied when
+ * the scheme is re-written */
+ struct {
+ Color colors[256];
+ uint32_t overridden[256 / 32];
+ } palette;
Evas_Object *ctxpopup;
int zoom_fontsize_start;
int scroll;
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index c2995bea..d98969e2 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -100,6 +100,7 @@ static struct {
{ "osc_color_reset", tytest_osc_color_reset},
{ "osc_color_name", tytest_osc_color_name},
{ "xterm_parse_color", tytest_xterm_parse_color},
+ { "palette_slots", tytest_palette_slots},
{ NULL, NULL},
};
diff --git a/src/bin/tytest_common.c b/src/bin/tytest_common.c
index 7bed22bb..d2fdec8f 100644
--- a/src/bin/tytest_common.c
+++ b/src/bin/tytest_common.c
@@ -452,21 +452,83 @@ termio_reset_main_colors(Evas_Object *termio)
termio_reset_fg_color(termio);
}
+/* the palette the application sets with OSC 4, on top of the default
+ * colours; the real textgrid would hold it, but there is none here */
+static Color _palette[256];
+static uint32_t _palette_overridden[256 / 32];
+static Eina_Bool _palette_ready = EINA_FALSE;
+
+static void
+_palette_init_defaults(void)
+{
+ int i;
+
+ for (i = 0; i < 256; i++)
+ colors_256_get(i, &_palette[i].r, &_palette[i].g, &_palette[i].b,
+ &_palette[i].a);
+ _palette_ready = EINA_TRUE;
+}
+
Eina_Bool
termio_palette_color_get(const Evas_Object *obj EINA_UNUSED, int idx,
int *r, int *g, int *b)
{
- unsigned char cr, cg, cb, ca;
-
if ((idx < 0) || (idx > 255))
return EINA_FALSE;
- colors_256_get(idx, &cr, &cg, &cb, &ca);
- *r = cr;
- *g = cg;
- *b = cb;
+ if (!_palette_ready)
+ _palette_init_defaults();
+ *r = _palette[idx].r;
+ *g = _palette[idx].g;
+ *b = _palette[idx].b;
return EINA_TRUE;
}
+void
+termio_palette_color_set(Evas_Object *obj EINA_UNUSED, int idx,
+ int r, int g, int b)
+{
+ if ((idx < 0) || (idx > 255))
+ return;
+ if (!_palette_ready)
+ _palette_init_defaults();
+ _palette[idx].r = r;
+ _palette[idx].g = g;
+ _palette[idx].b = b;
+ _palette[idx].a = 0xff;
+ _palette_overridden[idx / 32] |= 1u << (idx % 32);
+}
+
+/* a scheme rewrite restores the entries the application did not override */
+void
+termio_palette_apply(Evas_Object *obj EINA_UNUSED)
+{
+ int i;
+
+ if (!_palette_ready)
+ _palette_init_defaults();
+ for (i = 0; i < 256; i++)
+ {
+ if (!(_palette_overridden[i / 32] & (1u << (i % 32))))
+ colors_256_get(i, &_palette[i].r, &_palette[i].g, &_palette[i].b,
+ &_palette[i].a);
+ }
+}
+
+void
+termio_palette_color_override_clear(Evas_Object *obj EINA_UNUSED, int idx)
+{
+ if ((idx < 0) || (idx > 255))
+ return;
+ _palette_overridden[idx / 32] &= ~(1u << (idx % 32));
+}
+
+void
+termio_palette_reset(Evas_Object *obj EINA_UNUSED)
+{
+ memset(_palette_overridden, 0, sizeof(_palette_overridden));
+ termio_palette_apply(obj);
+}
+
Eina_Bool
termio_bg_is_dark(const Evas_Object *obj EINA_UNUSED)
{
@@ -579,7 +641,14 @@ test_textgrid_palette_get(const Evas_Object *obj EINA_UNUSED,
if (pal == EVAS_TEXTGRID_PALETTE_EXTENDED)
{
- colors_256_get(idx, &cr, &cg, &cb, &ca);
+ /* the live palette, so that OSC 4 sets are seen the way the
+ * real textgrid would show them */
+ if (!_palette_ready)
+ _palette_init_defaults();
+ cr = _palette[idx].r;
+ cg = _palette[idx].g;
+ cb = _palette[idx].b;
+ ca = _palette[idx].a;
}
else
{
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 819de35f..2100f4a9 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -69,6 +69,7 @@ int tytest_osc_arg_get(void);
int tytest_osc_color_reset(void);
int tytest_osc_color_name(void);
int tytest_xterm_parse_color(void);
+int tytest_palette_slots(void);
#endif
int tytest_keyin_legacy(void);
diff --git a/src/bin/win.c b/src/bin/win.c
index a79ebdb6..a790511d 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -5954,8 +5954,7 @@ void change_theme(Evas_Object *win, Config *config)
if (!theme_apply(term->bg, config, "terminology/background",
NULL, NULL, EINA_TRUE))
ERR("Couldn't find terminology theme!");
- colors_term_init(termio_textgrid_get(term->termio),
- config->color_scheme);
+ termio_palette_reset(term->termio);
termio_config_set(term->termio, config);
termio_theme_set(term->termio, term->bg_edj);
termio_color_scheme_changed(term->termio);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.