From 6371af0d8eaa4e78daff30f8fc77cb9f023b5cca Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 22 Nov 2024 10:43:51 -0800 Subject: [PATCH] config: need to apply window-theme for light/dark after loading theme --- src/config/Config.zig | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 3d8faa135..4aa0beb79 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1554,10 +1554,10 @@ keybind: Keybinds = .{}, /// The proxy icon is only visible with the native macOS titlebar style. /// /// Valid values are: -/// +/// /// * `visible` - Show the proxy icon. /// * `hidden` - Hide the proxy icon. -/// +/// /// The default value is `visible`. /// /// This setting can be changed at runtime and will affect all currently @@ -2752,17 +2752,19 @@ pub fn finalize(self: *Config) !void { // We always load the theme first because it may set other fields // in our config. if (self.theme) |theme| { - // If we have different light vs dark mode themes, disable - // window-theme = auto since that breaks it. - if (!std.mem.eql(u8, theme.light, theme.dark)) { - // This setting doesn't make sense with different light/dark themes - // because it'll force the theme based on the Ghostty theme. - if (self.@"window-theme" == .auto) self.@"window-theme" = .system; - } + const different = !std.mem.eql(u8, theme.light, theme.dark); // Warning: loadTheme will deinit our existing config and replace // it so all memory from self prior to this point will be freed. try self.loadTheme(theme); + + // If we have different light vs dark mode themes, disable + // window-theme = auto since that breaks it. + if (different) { + // This setting doesn't make sense with different light/dark themes + // because it'll force the theme based on the Ghostty theme. + if (self.@"window-theme" == .auto) self.@"window-theme" = .system; + } } const alloc = self._arena.?.allocator(); @@ -5380,3 +5382,21 @@ test "theme loading correct light/dark" { }, new.background); } } + +test "theme specifying light/dark changes window-theme from auto" { + const testing = std.testing; + const alloc = testing.allocator; + + { + var cfg = try Config.default(alloc); + defer cfg.deinit(); + var it: TestIterator = .{ .data = &.{ + "--theme=light:foo,dark:bar", + "--window-theme=auto", + } }; + try cfg.loadIter(alloc, &it); + try cfg.finalize(); + + try testing.expect(cfg.@"window-theme" == .system); + } +}