From ed7a0965039fb64a8f935385a7354d3b0b402388 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 8 Jan 2025 10:27:12 +0530 Subject: [PATCH] When reloading configuration fix auto color themes not being re-applied Fixes #8203 --- docs/changelog.rst | 2 ++ kitty/boss.py | 6 +++++- kitty/colors.py | 17 +++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 32effce21..5e07a41ca 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -109,6 +109,8 @@ Detailed list of changes - Fix the :ac:`clear_terminal scrollback ` action also clearing screen, not just the scrollback +- When reloading configuration fix auto color themes not being re-applied (:iss:`8203`) + 0.38.1 [2024-12-26] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index 48761ff60..96ea2023e 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -2670,6 +2670,7 @@ class Boss: def apply_new_options(self, opts: Options) -> None: from .fonts.box_drawing import set_scale + bg_colors_before = {w.id: w.screen.color_profile.default_bg for w in self.all_windows} # Update options storage set_options(opts, is_wayland(), self.args.debug_rendering, self.args.debug_font_fallback) apply_options_update() @@ -2699,8 +2700,11 @@ class Boss: for tm in self.all_tab_managers: tm.apply_options() # Update colors + if theme_colors.applied_theme and theme_colors.refresh(): + theme_colors.apply_theme(theme_colors.applied_theme, notify_on_bg_change=False) for w in self.all_windows: - self.default_bg_changed_for(w.id) + if w.screen.color_profile.default_bg != bg_colors_before.get(w.id): + self.default_bg_changed_for(w.id) w.refresh(reload_all_gpu_data=True) load_shader_programs.recompile_if_needed() diff --git a/kitty/colors.py b/kitty/colors.py index 1b9d4dbea..406a8e3ca 100644 --- a/kitty/colors.py +++ b/kitty/colors.py @@ -118,23 +118,26 @@ class ThemeColors: def on_system_color_scheme_change(self, new_value: ColorSchemes, is_initial_value: bool = False) -> bool: if is_initial_value: return False - from .utils import log_error self.refresh() + return self.apply_theme(new_value) + + def apply_theme(self, new_value: ColorSchemes, notify_on_bg_change: bool = True) -> bool: + from .utils import log_error boss = get_boss() if new_value == 'dark' and self.has_dark_theme: - patch_colors(self.dark_spec, self.dark_tbc, True) + patch_colors(self.dark_spec, self.dark_tbc, True, notify_on_bg_change=notify_on_bg_change) self.applied_theme = new_value if boss.args.debug_rendering: log_error(f'Applied color theme {new_value}') return True if new_value == 'light' and self.has_light_theme: - patch_colors(self.light_spec, self.light_tbc, True) + patch_colors(self.light_spec, self.light_tbc, True, notify_on_bg_change=notify_on_bg_change) self.applied_theme = new_value if boss.args.debug_rendering: log_error(f'Applied color theme {new_value}') return True if new_value == 'no_preference' and self.has_no_preference_theme: - patch_colors(self.no_preference_spec, self.no_preference_tbc, True) + patch_colors(self.no_preference_spec, self.no_preference_tbc, True, notify_on_bg_change=notify_on_bg_change) self.applied_theme = new_value if boss.args.debug_rendering: log_error(f'Applied color theme {new_value}') @@ -183,11 +186,12 @@ def patch_options_with_color_spec(opts: Options, spec: ColorsSpec, transparent_b def patch_colors( spec: ColorsSpec, transparent_background_colors: TransparentBackgroundColors, configured: bool = False, - windows: Optional[Sequence[WindowType]] = None + windows: Optional[Sequence[WindowType]] = None, notify_on_bg_change: bool = True, ) -> None: boss = get_boss() if windows is None: windows = tuple(boss.all_windows) + bg_colors_before = {w.id: w.screen.color_profile.default_bg for w in windows} profiles = tuple(w.screen.color_profile for w in windows if w) patch_color_profiles(spec, transparent_background_colors, profiles, configured) opts = get_options() @@ -203,9 +207,10 @@ def patch_colors( set_os_window_chrome(tm.os_window_id) patch_global_colors(spec, configured) default_bg_changed = 'background' in spec + notify_bg = notify_on_bg_change and default_bg_changed boss = get_boss() for w in windows: if w: - if default_bg_changed: + if notify_bg and w.screen.color_profile.default_bg != bg_colors_before.get(w.id): boss.default_bg_changed_for(w.id) w.refresh()