config: need to apply window-theme for light/dark after loading theme

This commit is contained in:
Mitchell Hashimoto
2024-11-22 10:43:51 -08:00
parent ddde68d1f4
commit 6371af0d8e

View File

@ -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);
}
}