From 2c1262f76c43081991328f412ed7b5c1add3e064 Mon Sep 17 00:00:00 2001 From: Hassan Raza Date: Sat, 26 Sep 2026 22:05:24 +0500 Subject: [PATCH] Preserve transparency across launch color overrides --- docs/changelog.rst | 2 ++ kitty/colors.py | 4 ++-- kitty_tests/options.py | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a1bddfebf..8d3a5e01f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -202,6 +202,8 @@ Detailed list of changes 0.49.2 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Preserve transparent background colors when applying unrelated launch color overrides + - ssh kitten: Preserve SSH option values following a spaced :code:`--kitten` option - A new option :opt:`detect_url_regex` to detect arbitrary text, such as file diff --git a/kitty/colors.py b/kitty/colors.py index 8c59bf503..1296d2c29 100644 --- a/kitty/colors.py +++ b/kitty/colors.py @@ -215,7 +215,7 @@ def parse_colors( colors: dict[str, Color | None | int] = {} nullable_color_map: dict[str, int | None] = {} special_color_map: dict[str, int] = {} - transparent_background_colors = () + transparent_background_colors: TransparentBackgroundColors = () allowed = all_color_related_conf_keys() for spec in args: conf: dict[str, Any] = {} @@ -230,7 +230,7 @@ def parse_colors( conf = parse_config(f) elif allow_reading_conf_files: conf = parse_config(spec) - transparent_background_colors = conf.pop('transparent_background_colors', ()) + transparent_background_colors = conf.pop('transparent_background_colors', transparent_background_colors) if background_image_options is not None: bio: dict[str, Any] = cast(dict[str, Any], background_image_options) for key in BackgroundImageOptions.__optional_keys__: diff --git a/kitty_tests/options.py b/kitty_tests/options.py index a894a08e6..ce820de6d 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -90,6 +90,25 @@ class TestConfParsing(BaseTest): {'work': seen_path, 'other': os.path.join(config_dir, 'other.kitty-session')}, ) + def test_launch_transparent_color_overrides(self) -> None: + from kitty.launch import apply_colors + from kitty.window import Window + + cases = ( + (('transparent_background_colors=#ffffff@0.5', 'foreground=red'), ((Color(255, 255, 255), 0.5),)), + (('foreground=red', 'transparent_background_colors=#ffffff@0.5'), ((Color(255, 255, 255), 0.5),)), + (('transparent_background_colors=#ffffff@0.5', 'foreground=red', 'transparent_background_colors='), ()), + (('transparent_background_colors=#ffffff@0.5', 'transparent_background_colors=#000000@0.25', 'foreground=red'), ((Color(0, 0, 0), 0.25),)), + ) + for colors, expected in cases: + with self.subTest(colors=colors): + window = Window.__new__(Window) + window.screen = self.create_screen() + apply_colors(window, colors) + actual = window.screen.color_profile.as_dict() + self.ae(actual.get('transparent_background_colors', ()), expected) + self.ae(actual['foreground'], 0xFF0000) + def cli_parsing(self): from kitty.cli import CLIOptions, Options, parse_cmdline, parse_option_spec