refactor(gui): set background color to match theme

This commit is contained in:
CJ van den Berg 2026-04-10 12:16:24 +02:00
parent 872f8cdcb8
commit 76ed87f87b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 23 additions and 1 deletions

View file

@ -55,6 +55,11 @@ var font_backend: gpu.RasterizerBackend = .freetype;
var font_dirty: std.atomic.Value(bool) = .init(true);
var stop_requested: std.atomic.Value(bool) = .init(false);
// Background color (written from TUI thread, applied by wio thread on each paint).
// Stored as packed RGBA u32 to allow atomic reads/writes.
var background_color: std.atomic.Value(u32) = .init(0x131313ff); // matches gpu.zig default
var background_dirty: std.atomic.Value(bool) = .init(false);
var config_arena_instance: std.heap.ArenaAllocator = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const config_arena = config_arena_instance.allocator();
@ -311,6 +316,13 @@ fn saveConfig() void {
log.err("failed to write gui config file", .{});
}
pub fn setBackground(color: gpu.Color) void {
const color_u32: u32 = (@as(u32, color.r) << 24) | (@as(u32, color.g) << 16) | (@as(u32, color.b) << 8) | color.a;
background_color.store(color_u32, .release);
background_dirty.store(true, .release);
wio.cancelWait();
}
pub fn requestAttention() void {
attention_pending.store(true, .release);
wio.cancelWait();
@ -635,6 +647,16 @@ fn wioLoop() void {
state.size = .{ .x = win_size.width, .y = win_size.height };
const font = wio_font;
if (background_dirty.swap(false, .acq_rel)) {
const color_u32 = background_color.load(.acquire);
gpu.setBackground(.{
.r = @truncate(color_u32 >> 24),
.g = @truncate(color_u32 >> 16),
.b = @truncate(color_u32 >> 8),
.a = @truncate(color_u32),
});
}
// Regenerate glyph indices using the GPU state.
// For double-wide characters vaxis emits width=2 for the left
// cell and width=0 (continuation) for the right cell. The

View file

@ -409,7 +409,7 @@ pub fn set_terminal_title(self: *Self, text: []const u8) void {
pub fn set_terminal_style(self: *Self, style_: Style) void {
_ = self;
_ = style_;
if (style_.bg) |bg| app.setBackground(themeColorToGpu(bg));
}
pub fn adjust_fontsize(self: *Self, amount: f32) void {