From 3459adc4fc5b9751b597a28de8ce0ce23760476f Mon Sep 17 00:00:00 2001 From: Vitor Araujo Boufleur Date: Wed, 28 Oct 2026 16:23:18 -0300 Subject: [PATCH] Fix live text-marker colour slot indexing --- docs/changelog.rst | 3 +++ kitty/colors.c | 15 ++++++++++++++- kitty/fast_data_types.pyi | 1 + kitty_tests/screen.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4187f6bff..81e3e79be 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -231,6 +231,9 @@ Detailed list of changes 0.50.0 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Fix live text-marker color updates applying each foreground/background pair + to the next marker instead of its own marker. + - Allow docking kitty windows to the edges of other windows or of the tab, for status bars, file trees, etc. Create them with :code:`launch --type=window-dock` or :code:`launch --type=tab-dock`, see :ref:`docks` diff --git a/kitty/colors.c b/kitty/colors.c index 1dd818626..db175f6d8 100644 --- a/kitty/colors.c +++ b/kitty/colors.c @@ -576,7 +576,7 @@ patch_color_profiles(PyObject *module UNUSED, PyObject *args) { for (size_t i = 1; i <= MARK_MASK; i++) { #define S(which, i) \ snprintf(key, sizeof(key) - 1, "mark%zu_" #which, i); \ - patch_mark_color(key, profiles, spec, mark_##which##s, i) + patch_mark_color(key, profiles, spec, mark_##which##s, i - 1) S(background, i); S(foreground, i); #undef S @@ -1140,12 +1140,25 @@ set_transparent_background_color(ColorProfile *self, PyObject *const *args, Py_s Py_RETURN_NONE; } +// Test the same marker slots consumed by the renderer without clearing pending uploads. +static PyObject * +test_mark_colors(ColorProfile *self, PyObject *unused UNUSED) { + color_type buf[arraysz(self->color_table) + arraysz(self->mark_backgrounds) + arraysz(self->mark_foregrounds) + NUM_INDEXED_IMAGE_SPECIAL_COLORS]; + bool dirty = self->dirty; + copy_color_table_to_buffer(self, buf, 0, 1); + self->dirty = dirty; + const color_type *bg = buf + arraysz(self->color_table); + const color_type *fg = bg + arraysz(self->mark_backgrounds); + return Py_BuildValue("((II)(II)(II))", fg[0], bg[0], fg[1], bg[1], fg[2], bg[2]); +} + static PyMethodDef cp_methods[] = { METHOD(reset_color_table, METH_NOARGS) METHOD(as_dict, METH_NOARGS) METHOD(basic_colors, METH_NOARGS) METHOD(color_table_address, METH_NOARGS) METHOD(as_color, METH_O) METHOD(reset_color, METH_O) METHOD(set_color, METH_VARARGS) METHODB(palette_color_is_generated, METH_O), METHODB(get_transparent_background_color, METH_O), METHODB(reset_layer, METH_O), METHODB(color_stack_depth, METH_NOARGS), + METHODB(test_mark_colors, METH_NOARGS), {"reload_from_opts", (PyCFunction)(void (*)(void))(reload_from_opts), METH_VARARGS | METH_KEYWORDS, NULL}, {"set_transparent_background_color", (PyCFunction)(void (*)(void))set_transparent_background_color, METH_FASTCALL, ""}, {NULL} /* Sentinel */ diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 5d4acb811..b0cb9978f 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -823,6 +823,7 @@ class ColorProfile: def set_transparent_background_color(self, index: int, color: Color | None = None, opacity: float | None = None) -> None: ... def reset_layer(self, layer: int) -> None: ... def color_stack_depth(self) -> int: ... + def test_mark_colors(self) -> tuple[tuple[int, int], tuple[int, int], tuple[int, int]]: ... def patch_color_profiles( spec: Dict[str, Optional[int]], diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 041201506..bfe511442 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -2368,6 +2368,35 @@ class TestScreen(BaseTest): for i, row in enumerate(rows): self.assertEqual('continued' in row, which_screen == 0 and i == 1, row) + def test_live_mark_colors(self): + from kitty.fast_data_types import COLOR_LAYER_GLOBAL, patch_color_profiles + + opts = self.set_options({'palette_generate': 'fixed'}) + profiles = tuple(ColorProfile(opts) for _ in range(3)) + + def configured(): + return tuple(tuple(int(getattr(opts, f'mark{i}_{channel}')) for channel in ('foreground', 'background')) for i in range(1, 4)) + + expected = configured() + for cp in profiles: + self.ae(cp.test_mark_colors(), expected) + for base in (0x123400, 0x567800): + spec = {f'mark{i}_{channel}': base + 2 * i + j for i in range(1, 4) for j, channel in enumerate(('foreground', 'background'))} + patch_color_profiles(spec, None, profiles[:2], COLOR_LAYER_GLOBAL) + expected = tuple((spec[f'mark{i}_foreground'], spec[f'mark{i}_background']) for i in range(1, 4)) + for cp in profiles[:2]: + self.ae(cp.test_mark_colors(), expected) + self.ae(profiles[2].test_mark_colors(), configured()) + for i in range(3): + for j, channel in enumerate(('foreground', 'background')): + value = 0xABCD00 + 2 * i + j + patch_color_profiles({f'mark{i + 1}_{channel}': value}, None, profiles[:1], COLOR_LAYER_GLOBAL) + expected = tuple(tuple(value if (r, c) == (i, j) else v for c, v in enumerate(pair)) for r, pair in enumerate(expected)) + self.ae(profiles[0].test_mark_colors(), expected) + for reset in (False, True): + profiles[0].reload_from_opts(opts, reset_overriden_colors=reset) + self.ae(profiles[0].test_mark_colors(), configured()) + def test_color_profile(self): from kitty.fast_data_types import patch_color_profiles