#!/bin/sh # ANODE multi-toolkit theme & fractional-DPI synchronizer (strict POSIX sh) # Syncs GTK2, GTK3, GTK4/libadwaita, xsettingsd, Qt5 (qt5ct), Qt6 (qt6ct), and Kvantum. set -eu : "${XDG_CONFIG_HOME:=$HOME/.config}" : "${XDG_DATA_HOME:=$HOME/.local/share}" XRES="${1:-$HOME/.Xresources}" if [ ! -r "$XRES" ]; then exit 0 fi xres_get() { _k="$1" _def="$2" _val="$(awk -v key="$_k" ' { s = $0 gsub(/^[ \t\r]+|[ \t\r]+$/, "", s) if (s == "" || substr(s, 1, 1) == "!" || substr(s, 1, 1) == "#") next p = index(s, ":") if (p > 0) { k = substr(s, 1, p - 1) gsub(/^[ \t]+|[ \t]+$/, "", k) if (k == key) { v = substr(s, p + 1) gsub(/^[ \t]+|[ \t]+$/, "", v) print v exit } } } ' "$XRES" 2>/dev/null || true)" if [ -n "$_val" ]; then printf '%s\n' "$_val" else printf '%s\n' "$_def" fi } resolve_ui_font() { _req="$1" [ -n "$_req" ] || _req="Roboto" if [ "$_req" = "Roboto" ] && command -v fc-list >/dev/null 2>&1; then _resolved="$(fc-list : family 2>/dev/null | awk ' { n = split($0, a, ",") for (i = 1; i <= n; i++) { s = a[i] gsub(/^[ \t\r\n]+|[ \t\r\n]+$/, "", s) ls = tolower(s) if (ls == "roboto") has_rob = 1 else if (ls == "noto sans") has_noto = 1 } } END { if (has_rob) print "Roboto" else if (has_noto) print "Noto Sans" else print "Roboto" } ' || true)" if [ -n "$_resolved" ]; then printf '%s\n' "$_resolved" return 0 fi fi printf '%s\n' "$_req" } TNAME="$(xres_get theme.name "AnodeDefault")" DARK="$(xres_get theme.isDark "")" FONT_FACE="$(xres_get theme.fontFace "Fira Code")" MONO_FONT="$FONT_FACE" UI_FONT="$(resolve_ui_font "$(xres_get theme.uiFontFace "Roboto")")" BASE_SZ="$(xres_get theme.baseFontSize "15")" SCALE="$(xres_get theme.scale "1.00")" CUR_SZ="$(xres_get Xcursor.size "24")" ICON_THEME="$(xres_get theme.iconTheme "Adwaita")" BG_MAIN="$(xres_get theme.bgMain "#0b0e14")" BG_BAR="$(xres_get theme.bgBar "#11161f")" BG_HEADER="$(xres_get theme.bgHeader "#141a24")" BG_FOOTER="$(xres_get theme.bgFooter "#0f141d")" BG_OVERLAY="$(xres_get theme.bgOverlay "#192231")" BG_ALT_EVEN="$(xres_get theme.bgAltEven "#131923")" BG_ALT_ODD="$(xres_get theme.bgAltOdd "#171f2b")" BG_INPUT="$(xres_get theme.bgInput "#1a2330")" BG_INPUT_FOC="$(xres_get theme.bgInputFocus "#202c3d")" BG_BUTTON="$(xres_get theme.bgButton "#1e2838")" BG_SEARCH="$(xres_get theme.bgSearch "#1b2433")" FG_MAIN="$(xres_get theme.fgMain "#e6e1cf")" FG_BRIGHT="$(xres_get theme.fgBright "#ffffff")" FG_MUTED="$(xres_get theme.fgMuted "#8693a6")" SEL_BG="$(xres_get theme.selBg "#2b5278")" SEL_FG="$(xres_get theme.selFg "#ffffff")" ACCENT="$(xres_get theme.accent "#59c2ff")" ACCENT_ALT="$(xres_get theme.accentAlt "#73d0ff")" HIGHLIGHT="$(xres_get theme.highlight "#ffd173")" BORDER="$(xres_get theme.border "#283444")" DIVIDER="$(xres_get theme.divider "#1e2736")" SUCCESS="$(xres_get theme.success "#7fd962")" WARNING="$(xres_get theme.warning "#ffb454")" DANGER="$(xres_get theme.danger "#f07178")" THEME_ID="ANODE-$TNAME" CALC="$(awk -v s="$SCALE" -v bsz="$BASE_SZ" -v dark="$DARK" -v bg="$BG_MAIN" -v cur="$CUR_SZ" ' function hex_byte(h, hi, lo) { hi = index("0123456789abcdef", substr(h, 1, 1)) - 1 lo = index("0123456789abcdef", substr(h, 2, 1)) - 1 if (hi < 0 || lo < 0) return -1 return hi * 16 + lo } function bg_is_dark(bghex, hs, r, g, b, lum) { hs = tolower(bghex) gsub(/^#/, "", hs) if (length(hs) == 6) { r = hex_byte(substr(hs, 1, 2)) g = hex_byte(substr(hs, 3, 2)) b = hex_byte(substr(hs, 5, 2)) if (r >= 0 && g >= 0 && b >= 0) { lum = 0.299 * r + 0.587 * g + 0.114 * b return (lum < 128.0) ? 1 : 0 } } return 1 } BEGIN { sc = s + 0.0 if (sc < 0.50) sc = 0.50 if (sc > 4.00) sc = 4.00 gdk_sc = (sc < 1.75) ? 1 : int(sc + 0.5) logical_px = (bsz + 0.0) / sc pt = int((logical_px * 0.65) + 0.5) if (pt < 7) pt = 7 if (pt > 22) pt = 22 btn_pv = 3 btn_ph = 8 rad = 4 row_h = 24 sb_w = 8 if (dark == "1" || tolower(dark) == "true") is_d = 1 else if (dark == "0" || tolower(dark) == "false") is_d = 0 else is_d = bg_is_dark(bg) gtk_cur = int(((cur + 0.0) / gdk_sc) + 0.5); if (gtk_cur < 16) gtk_cur = 16 printf "%d %d %d %d %d %d %d %d %d\n", gdk_sc, pt, btn_pv, btn_ph, rad, row_h, sb_w, is_d, gtk_cur }')" set -- $CALC GDK_SCALE_VAL="$1" GTK_PT="$2" PAD_V="$3" PAD_H="$4" RAD_PX="$5" ROW_H="$6" SB_W="$7" IS_DARK="$8" GTK_CUR_SZ="$9" GTK_FONT="$UI_FONT $GTK_PT" # 1. GTK-2 theme, metadata, XDG theme symlink & ~/.gtkrc-2.0 THEME_ROOT="$HOME/.themes/$THEME_ID" GTK2_DIR="$THEME_ROOT/gtk-2.0" mkdir -p "$GTK2_DIR" cat > "$THEME_ROOT/index.theme.tmp.$$" < "$GTK2_DIR/gtkrc.tmp.$$" <*" style "anode-menu" widget_class "**" style "anode-menu" EOF mv -f "$GTK2_DIR/gtkrc.tmp.$$" "$GTK2_DIR/gtkrc" cat > "$HOME/.gtkrc-2.0.tmp.$$" < "$_tmp" if [ "$_user_override" = "0" ]; then if [ "$_is4" = "1" ]; then if [ "$_use_dark" = "1" ]; then printf '@import url("resource:///org/gtk/libgtk/theme/Default/Default-dark.css");\n' > "$_tmp" else printf '@import url("resource:///org/gtk/libgtk/theme/Default/Default-light.css");\n' > "$_tmp" fi else if [ "$_use_dark" = "1" ]; then printf '@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained-dark.css");\n' > "$_tmp" else printf '@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained.css");\n' > "$_tmp" fi fi fi cat >> "$_tmp" <> "$_tmp" < contents, popover.menu > arrow, popover.menu.background > contents { background-color: $BG_OVERLAY; color: $FG_MAIN; border-color: $BORDER; } menu menuitem:hover, .menu menuitem:hover, menubar > menuitem:hover, popover modelbutton:hover, popover.menu modelbutton:hover, modelbutton.flat:hover { background-color: $SEL_BG; color: $SEL_FG; } menu separator, .menu separator, .context-menu separator { background-color: $DIVIDER; } button:not(.flat) { background-color: $BG_BUTTON; background-image: none; color: $FG_BRIGHT; border-color: $BORDER; } button:not(.flat):hover { background-color: $BG_OVERLAY; border-color: $ACCENT; } button:not(.flat):checked, button:not(.flat):active, button.suggested-action { background-color: $SEL_BG; background-image: none; color: $SEL_FG; border-color: $ACCENT; } button.flat:not(:hover):not(:checked):not(:active) { background-color: transparent; background-image: none; color: $FG_MAIN; border-color: transparent; } entry, textview, textview text, .view, treeview.view, list, listbox { background-color: $BG_INPUT; color: $FG_BRIGHT; border-color: $BORDER; } entry:focus { background-color: $BG_INPUT_FOC; border-color: $ACCENT; } row:selected, .view:selected, treeview.view:selected, *:selected, selection { background-color: $SEL_BG; color: $SEL_FG; } notebook header, notebook tab { background-color: $BG_HEADER; color: $FG_MAIN; border-color: $DIVIDER; } notebook tab:checked { background-color: $BG_MAIN; color: $FG_BRIGHT; border-color: $ACCENT; } frame > border, scrolledwindow.frame, separator { border-color: $DIVIDER; } scrollbar slider { background-color: $BORDER; } scrollbar slider:hover { background-color: $ACCENT_ALT; } tooltip, .tooltip { background-color: $BG_OVERLAY; color: $FG_BRIGHT; border-color: $ACCENT; } EOF fi if [ "$_is4" = "1" ]; then cat >> "$_tmp" < "$GTK3_CONF_DIR/settings.ini.tmp.$$" < "$GTK4_CONF_DIR/settings.ini.tmp.$$" < "$XSET_DIR/xsettingsd.conf.tmp.$$" < "${_pal}.tmp.$$" < "${_qconf}.tmp.$$" < UI font, monospace -> Fira Code) FC_CONF_DIR="$XDG_CONFIG_HOME/fontconfig/conf.d" mkdir -p "$FC_CONF_DIR" XML_UI_FONT="$(printf '%s' "$UI_FONT" | sed 's/&/\&/g; s//\>/g')" XML_MONO_FONT="$(printf '%s' "$MONO_FONT" | sed 's/&/\&/g; s//\>/g')" FC_FILE="$FC_CONF_DIR/60-anode-fonts.conf" cat > "${FC_FILE}.tmp.$$" < sans-serif $XML_UI_FONT EOF if [ "$UI_FONT" != "Noto Sans" ]; then printf ' Noto Sans\n' >> "${FC_FILE}.tmp.$$" fi cat >> "${FC_FILE}.tmp.$$" < monospace $XML_MONO_FONT EOF if [ "$MONO_FONT" != "Fira Code" ]; then printf ' Fira Code\n' >> "${FC_FILE}.tmp.$$" fi cat >> "${FC_FILE}.tmp.$$" < EOF mv -f "${FC_FILE}.tmp.$$" "$FC_FILE" # 6. Kvantum theme KV_DIR="$XDG_CONFIG_HOME/Kvantum" KV_TDIR="$KV_DIR/$THEME_ID" mkdir -p "$KV_TDIR" cat > "$KV_DIR/kvantum.kvconfig.tmp.$$" < "$KV_TDIR/$THEME_ID.kvconfig.tmp.$$" </dev/null 2>&1; then _cscheme="default" if [ "$IS_DARK" = "1" ]; then _cscheme="prefer-dark" fi gsettings set org.gnome.desktop.interface font-name "$GTK_FONT" >/dev/null 2>&1 || true gsettings set org.gnome.desktop.interface document-font-name "$GTK_FONT" >/dev/null 2>&1 || true gsettings set org.gnome.desktop.interface monospace-font-name "$MONO_FONT $GTK_PT" >/dev/null 2>&1 || true gsettings set org.gnome.desktop.interface gtk-theme "$THEME_ID" >/dev/null 2>&1 || true gsettings set org.gnome.desktop.interface icon-theme "$ICON_THEME" >/dev/null 2>&1 || true gsettings set org.gnome.desktop.interface color-scheme "$_cscheme" >/dev/null 2>&1 || true fi _xpids="$( (ps -eo pid=,comm= 2>/dev/null || ps -ax -o pid=,comm= 2>/dev/null || true) | awk ' { cmd=$2; sub(/^.*\//, "", cmd); if (cmd == "xsettingsd") print $1 } ' )" if [ -n "${_xpids:-}" ]; then for _p in $_xpids; do kill -HUP "$_p" 2>/dev/null || true done fi fi