fix(gtk): adjust background CSS class dynamically on config reload

Currently the `background` CSS class is added once on startup and never removed
or re-added. This is problematic as that if Ghostty was started with an opaque
window but then its config was reloaded with a `background-opacity` less than 1,
the window won't actually become translucent, and it would only appear as if the
background colors had become faded (because the window is still styled to be
opaque).
This commit is contained in:
Leah Amelia Chen
2025-01-02 21:44:16 +08:00
committed by Mitchell Hashimoto
parent 9184395cba
commit cd90821b93

View File

@ -119,11 +119,6 @@ pub fn init(self: *Window, app: *App) !void {
c.gtk_widget_add_css_class(@ptrCast(gtk_window), "window-theme-ghostty"); c.gtk_widget_add_css_class(@ptrCast(gtk_window), "window-theme-ghostty");
} }
// Remove the window's background if any of the widgets need to be transparent
if (app.config.@"background-opacity" < 1) {
c.gtk_widget_remove_css_class(@ptrCast(window), "background");
}
// Create our box which will hold our widgets in the main content area. // Create our box which will hold our widgets in the main content area.
const box = c.gtk_box_new(c.GTK_ORIENTATION_VERTICAL, 0); const box = c.gtk_box_new(c.GTK_ORIENTATION_VERTICAL, 0);
@ -398,6 +393,12 @@ pub fn init(self: *Window, app: *App) !void {
/// TODO: Many of the initial style settings in `create` could possibly be made /// TODO: Many of the initial style settings in `create` could possibly be made
/// reactive by moving them here. /// reactive by moving them here.
pub fn syncAppearance(self: *Window, config: *const configpkg.Config) !void { pub fn syncAppearance(self: *Window, config: *const configpkg.Config) !void {
if (config.@"background-opacity" < 1) {
c.gtk_widget_remove_css_class(@ptrCast(self.window), "background");
} else {
c.gtk_widget_add_css_class(@ptrCast(self.window), "background");
}
if (self.wayland) |*wl| { if (self.wayland) |*wl| {
try wl.setBlur(config.@"background-blur-radius" > 0); try wl.setBlur(config.@"background-blur-radius" > 0);
} }