#!/usr/bin/env bash # Regenerates GTK3/4 CSS + settings.ini to match the current Quickshell # theme (accent color + dark/light mode). These used to be static, # Nix-rebuild-only files (symlinked straight into the store) — this makes # them live-editable instead, the same way cursor.conf/display.conf work, # so the Theme picker can actually reach GTK apps like Thunar. set -euo pipefail accent="${1:?usage: gtk-theme-set }" bg="${2:?bg required}" bg_alt="${3:?bgAlt required}" fg="${4:?fg required}" fg_dim="${5:?fgDim required}" border="${6:?border required}" dark="${7:?dark required}" dir3="$HOME/.config/gtk-3.0" dir4="$HOME/.config/gtk-4.0" mkdir -p "$dir3" "$dir4" css_file=$(mktemp) cat > "$css_file" < stack, scrolledwindow, viewport { background-color: $bg; color: $fg; } iconview.cell, iconview text { background-color: $bg; color: $fg; } treeview.view:selected, row:selected, iconview:selected { background-color: $accent; color: $bg; } headerbar, .titlebar { background-color: $bg_alt; color: $fg; border-color: $border; box-shadow: none; } button { border-color: $border; } button:hover { background-color: $bg_alt; } selection, *:selected { background-color: $accent; color: $bg; } EOF cp "$css_file" "$dir3/gtk.css" cp "$css_file" "$dir4/gtk.css" rm -f "$css_file" prefer_dark="false" theme_name="Adwaita" icon_theme="Gruvbox-Plus-Light" if [ "$dark" = "1" ]; then prefer_dark="true" theme_name="Adwaita-dark" icon_theme="Gruvbox-Plus-Dark" fi ini_file=$(mktemp) cat > "$ini_file" </dev/null 2>&1; then color_scheme="default" [ "$dark" = "1" ] && color_scheme="prefer-dark" dconf write /org/gnome/desktop/interface/gtk-theme "'$theme_name'" dconf write /org/gnome/desktop/interface/icon-theme "'$icon_theme'" dconf write /org/gnome/desktop/interface/color-scheme "'$color_scheme'" fi # GTK2 compat: separate config format (~/.gtkrc-2.0, not settings.ini), # and no live theme-switching mechanism at all — GTK2 apps only read this # at their own startup. Only icon theme and font actually follow the # current theme; gnome-themes-extra's bundled GTK2 Adwaita engine has no # dark variant to switch to (GTK2 predates that concept), so gtk-theme- # name here is always the one real option, not a broken attempt at dark # mode. cat > "$HOME/.gtkrc-2.0" <