#!/bin/sh
# Install Darkmatter into ~/.themes.
#
# Copies only what the theme actually ships: the two GTK stylesheets, the
# xfwm4 decorations and their hidpi variants, the shared raster assets, and
# index.theme. Build sources stay behind.
#
# Run from the theme root:  sh src/install.sh

set -e
[ -f index.theme ] || { echo "run me from the theme root" >&2; exit 1; }

dest="${1:-$HOME/.themes}"
name=Darkmatter

install_one() {   # install_one <theme name> <xfwm4 source dir>
    target="$dest/$1"
    rm -rf "$target"
    mkdir -p "$target/xfwm4"
    cp index.theme "$target/index.theme"
    [ "$1" = "$name" ] || sed -i "s/^Name=.*/Name=$1/" "$target/index.theme"
    mkdir -p "$target/assets"
    # only the rasters: the SVGs beside them are build sources GTK never reads
    find assets -maxdepth 1 -name '*.png' -exec cp {} "$target/assets/" \;
    for v in gtk-3.0 gtk-4.0; do
        mkdir -p "$target/$v"
        cp "$v/gtk.css" "$v/gtk-dark.css" "$target/$v/"
        [ -f "$v/thumbnail.png" ] && cp "$v/thumbnail.png" "$target/$v/"
    done
    find "$2" -maxdepth 1 -type f -exec cp {} "$target/xfwm4/" \;
    echo "  $target"
}

install_one "$name"        xfwm4
install_one "$name-hdpi"   xfwm4/Darkmatter-hdpi/xfwm4
install_one "$name-xhdpi"  xfwm4/Darkmatter-xhdpi/xfwm4
