diff --git a/bin/blob-theme-gtk b/bin/blob-theme-gtk new file mode 100755 index 0000000..4a271d4 --- /dev/null +++ b/bin/blob-theme-gtk @@ -0,0 +1,22 @@ +#!/bin/bash + +# blob:summary=Apply the current Blob theme's light or dark preference to GTK apps +# blob:hidden=true + +blob-cmd-present gsettings || exit 0 + +colors_toml=$HOME/.local/state/blob/current/theme/colors.toml +[[ -f $colors_toml ]] || exit 0 + +mode=$(blob-theme-color --file "$colors_toml" mode) + +if [[ $mode == "light" ]]; then + color_scheme="prefer-light" + gtk_theme="Adwaita" +else + color_scheme="prefer-dark" + gtk_theme="Adwaita-dark" +fi + +gsettings set org.gnome.desktop.interface color-scheme "$color_scheme" 2>/dev/null || true +gsettings set org.gnome.desktop.interface gtk-theme "$gtk_theme" 2>/dev/null || true diff --git a/bin/blob-theme-set b/bin/blob-theme-set index f5eb5da..f53f933 100755 --- a/bin/blob-theme-set +++ b/bin/blob-theme-set @@ -321,6 +321,7 @@ post_theme_commands=( blob-restart-btop blob-theme-foot blob-theme-browser + blob-theme-gtk ) if [[ $THEME_HEADLESS != "1" ]]; then diff --git a/default/themed/gtk.css.tpl b/default/themed/gtk.css.tpl new file mode 100644 index 0000000..bfde6bf --- /dev/null +++ b/default/themed/gtk.css.tpl @@ -0,0 +1,41 @@ +@define-color window_bg_color {{ background }}; +@define-color window_fg_color {{ foreground }}; +@define-color view_bg_color {{ background }}; +@define-color view_fg_color {{ foreground }}; +@define-color headerbar_bg_color {{ lighter_background }}; +@define-color headerbar_fg_color {{ foreground }}; +@define-color headerbar_border_color {{ dark_background }}; +@define-color headerbar_backdrop_color {{ background }}; +@define-color sidebar_bg_color {{ lighter_background }}; +@define-color sidebar_fg_color {{ foreground }}; +@define-color sidebar_backdrop_color {{ background }}; +@define-color sidebar_border_color {{ dark_background }}; +@define-color secondary_sidebar_bg_color {{ lighter_background }}; +@define-color secondary_sidebar_fg_color {{ foreground }}; +@define-color secondary_sidebar_backdrop_color {{ background }}; +@define-color secondary_sidebar_border_color {{ dark_background }}; +@define-color card_bg_color {{ lighter_background }}; +@define-color card_fg_color {{ foreground }}; +@define-color dialog_bg_color {{ background }}; +@define-color dialog_fg_color {{ foreground }}; +@define-color popover_bg_color {{ lighter_background }}; +@define-color popover_fg_color {{ foreground }}; +@define-color accent_bg_color {{ accent }}; +@define-color accent_fg_color {{ background }}; +@define-color accent_color {{ accent }}; +@define-color destructive_bg_color {{ red }}; +@define-color destructive_fg_color {{ background }}; +@define-color destructive_color {{ red }}; +@define-color success_color {{ green }}; +@define-color warning_color {{ yellow }}; +@define-color error_color {{ red }}; + +@define-color theme_bg_color {{ background }}; +@define-color theme_fg_color {{ foreground }}; +@define-color theme_base_color {{ background }}; +@define-color theme_text_color {{ foreground }}; +@define-color theme_selected_bg_color {{ accent }}; +@define-color theme_selected_fg_color {{ background }}; +@define-color insensitive_bg_color {{ dark_background }}; +@define-color insensitive_fg_color {{ muted }}; +@define-color borders {{ dark_background }}; diff --git a/docs/themes.md b/docs/themes.md index 1d91379..bc1da8a 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -30,12 +30,12 @@ the shell and the CLI never disagree about what a slot means. Each rendered file is picked up differently: `foot.ini` and `kitty.conf` by an `include` in the shipped terminal config, `hyprland.lua` through Hyprland's Lua module path, `shell.toml` and `chromium.theme` read straight from the state -directory, and `btop.theme` and `neovim.lua` through symlinks the installer -makes into those apps' own config trees. +directory, and `btop.theme`, `neovim.lua` and `gtk.css` through symlinks the +installer makes into those apps' own config trees. `default/themed/*.tpl` are rendered per theme into -`~/.local/state/blob/current/theme/`. Nine ship: foot, kitty, btop, chromium, -hyprland, the screenshare picker, neovim, `shell.toml`, and zen. +`~/.local/state/blob/current/theme/`. Ten ship: foot, kitty, btop, chromium, +hyprland, the screenshare picker, neovim, `shell.toml`, zen, and `gtk.css`. An app picks its colors up in one of two ways. Most include the generated file directly, so nothing has to run: @@ -47,7 +47,20 @@ include ~/.local/state/blob/current/theme/kitty.conf Zen does the same through a CSS import in `userChrome.css`. The rest are pushed by a short applier listed in `post_theme_commands` inside `blob-theme-set`: `blob-theme-foot`, `blob-theme-browser`, `blob-restart-terminal`, -`blob-restart-btop`, `blob-hypr-restart`. +`blob-restart-btop`, `blob-hypr-restart`, `blob-theme-gtk`. + +## GTK apps + +Nautilus and the other GTK apps read two things. The palette comes from +`gtk.css`, linked into both `~/.config/gtk-3.0/gtk.css` and +`~/.config/gtk-4.0/gtk.css`, which redefines the libadwaita named colors +(`window_bg_color`, `headerbar_bg_color`, `accent_bg_color` and the rest) so a +stock Adwaita app is drawn in the theme's own colors. The light or dark +preference comes from `blob-theme-gtk`, which reads the theme's `mode` and sets +`org.gnome.desktop.interface color-scheme` and `gtk-theme` through `gsettings`. + +The preference applies to running apps immediately; the CSS is read at startup, +so an app that was already open keeps its old colors until it is restarted. Adding a template for another app means dropping a `.tpl` in `default/themed/` and, if it cannot include a file, adding an applier to that list. diff --git a/install/steps/theme.sh b/install/steps/theme.sh index 40e1baf..4a1f4dc 100644 --- a/install/steps/theme.sh +++ b/install/steps/theme.sh @@ -131,6 +131,8 @@ link_theme_file() { # creating the tree would be inventing a layout the user has not chosen. link_app_themes() { link_theme_file btop.theme "$config_dir/btop/themes/current.theme" "btop theme" + link_theme_file gtk.css "$config_dir/gtk-3.0/gtk.css" "gtk-3.0 theme" + link_theme_file gtk.css "$config_dir/gtk-4.0/gtk.css" "gtk-4.0 theme" if [[ -d $config_dir/nvim/lua/plugins ]]; then link_theme_file neovim.lua "$config_dir/nvim/lua/plugins/theme.lua" "neovim theme" diff --git a/uninstall.sh b/uninstall.sh index e11799d..66e924a 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -112,6 +112,10 @@ for lua in hyprland.lua monitors.lua input.lua looknfeel.lua bindings.lua autost restore_or_remove "$config_dir/hypr/$lua" "hypr/$lua" done +for gtk in gtk-3.0 gtk-4.0; do + [[ -L $config_dir/$gtk/gtk.css ]] && restore_or_remove "$config_dir/$gtk/gtk.css" "$gtk/gtk.css" +done + if [[ $keep_state == false && -d $HOME/.local/state/blob ]]; then rm -rf "$HOME/.local/state/blob" say "remove ~/.local/state/blob"