apprt/gtk: add theme variant in window-theme

this colours the header bar with the config colour.
This commit is contained in:
Paul
2024-09-12 20:36:16 +02:00
committed by Paul Berg
parent 32b3dfed9d
commit ac985937cd
3 changed files with 27 additions and 5 deletions

View File

@ -179,7 +179,7 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
c.adw_style_manager_set_color_scheme(
style_manager,
switch (config.@"window-theme") {
.auto => auto: {
.auto, .ghostty => auto: {
const lum = config.background.toTerminalRGB().perceivedLuminance();
break :auto if (lum > 0.5)
c.ADW_COLOR_SCHEME_PREFER_LIGHT
@ -417,12 +417,20 @@ fn syncActionAccelerator(
}
fn loadRuntimeCss(config: *const Config, provider: *c.GtkCssProvider) !void {
const fill: Config.Color = config.@"unfocused-split-fill" orelse config.background;
const unfocused_fill: Config.Color = config.@"unfocused-split-fill" orelse config.background;
const headerbar_background = config.background;
const headerbar_foreground = config.foreground;
const fmt =
\\widget.unfocused-split {{
\\ opacity: {d:.2};
\\ background-color: rgb({d},{d},{d});
\\}}
\\window.ghostty-theme-inherit headerbar,
\\window.ghostty-theme-inherit toolbarview > revealer > windowhandle {{
\\ background-color: rgb({d},{d},{d});
\\ color: rgb({d},{d},{d});
\\}}
;
// The length required is always less than the length of the pre-formatted string:
// -> '{d:.2}' gets replaced with max 4 bytes (0.00)
@ -434,9 +442,15 @@ fn loadRuntimeCss(config: *const Config, provider: *c.GtkCssProvider) !void {
fmt,
.{
1.0 - config.@"unfocused-split-opacity",
fill.r,
fill.g,
fill.b,
unfocused_fill.r,
unfocused_fill.g,
unfocused_fill.b,
headerbar_background.r,
headerbar_background.g,
headerbar_background.b,
headerbar_foreground.r,
headerbar_foreground.g,
headerbar_foreground.b,
},
);
// Clears any previously loaded CSS from this provider

View File

@ -87,6 +87,11 @@ pub fn init(self: *Window, app: *App) !void {
c.gtk_window_set_icon_name(gtk_window, "com.mitchellh.ghostty");
// Apply class to color headerbar if window-theme is set to `ghostty`.
if (app.config.@"window-theme" == .ghostty) {
c.gtk_widget_add_css_class(@ptrCast(gtk_window), "ghostty-theme-inherit");
}
// 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");

View File

@ -859,6 +859,8 @@ keybind: Keybinds = .{},
/// * `system` - Use the system theme.
/// * `light` - Use the light theme regardless of system theme.
/// * `dark` - Use the dark theme regardless of system theme.
/// * `ghostty` - Use the background and foreground colors specified in the ghostty
/// config file. This value is only supported with `gtk-adwaita` enabled.
///
/// On macOS, if `macos-titlebar-style` is "tabs", the window theme will be
/// automatically set based on the luminosity of the terminal background color.
@ -4048,6 +4050,7 @@ pub const WindowTheme = enum {
system,
light,
dark,
ghostty,
};
/// See window-colorspace