#!/bin/sh # square-xfwm4-corners.sh (v2) # Makes ~/.themes/Default-Square: an exact copy of the xfwm4 "Default" theme # with square top corners, keeping the thin dark outline and highlight. # Usage: ./square-xfwm4-corners.sh [ACTIVE_TITLE_COLOR] # e.g. ./square-xfwm4-corners.sh '#ff9900' (or a name like orange) # no argument = keep the theme's normal title colour set -eu ACTIVE_TITLE_COLOR="${1:-}" case "$ACTIVE_TITLE_COLOR" in ''|\#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]|\#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]) ;; *[!a-zA-Z]*) echo "Colour must be #rgb, #rrggbb or a plain name like orange"; exit 1 ;; esac SRC=/usr/share/themes/Default/xfwm4 DST_THEME="$HOME/.themes/Default-Square" DST="$DST_THEME/xfwm4" [ -d "$SRC" ] || { echo "Missing $SRC"; exit 1; } # Warn if the installed theme differs from the version these overlays were made from want=349096e386ab06feddff55aa404bed0a have=$(md5sum "$SRC/top-left-active.png" 2>/dev/null | cut -d' ' -f1 || true) [ "$have" = "$want" ] || echo "Warning: your Default theme differs from the expected version; result may be slightly off." # Fresh copy (also cleans up the result of the first version of this script) rm -rf "$DST_THEME" mkdir -p "$DST_THEME" cp -r "$SRC" "$DST" # 1) Base layer (XPM): make the transparent corner pixels use the frame colour for f in "$DST"/top-left-*.xpm "$DST"/top-right-*.xpm; do awk ' /"[^"]*"/ && !hdr { hdr = 1; split(substr($0, index($0,"\"")+1), a, /[ \t"]+/); nc = a[3]; cpp = a[4]; print; next } hdr && seen < nc && /"/ { seen++; s = substr($0, index($0,"\"")+1); s = substr(s, 1, index(s,"\"")-1) key[seen] = substr(s, 1, cpp); spec[seen] = substr(s, cpp+1); pre[seen] = substr($0, 1, index($0,"\"")-1) isnone[seen] = (tolower(spec[seen]) ~ /c[ \t]+none/) if (!isnone[seen] && fill == "") fill = spec[seen] if (seen == nc) for (i = 1; i <= nc; i++) print pre[i] "\"" key[i] (isnone[i] ? fill : spec[i]) "\"," next } { print }' "$f" > "$f.tmp" && mv "$f.tmp" "$f" done # 2) Overlay (PNG): square versions of the outline/highlight images write_png() { printf '%s' "$2" | base64 -d > "$DST/$1"; } write_png top-left-active.png 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAdCAYAAACXFC2jAAAASklEQVR42mNkYGBoYMADWLi5udm+fPnShlPB/////zMwMPzHqQBK41TAxEAAsPz79+8/ZSYQcgMdrBj1JpIbGBkZ/5FtwqgCCAAAJ9onK5/spQ0AAAAASUVORK5CYII=' write_png top-left-inactive.png 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAdCAYAAACXFC2jAAAASklEQVR42mNkYGBoYMADWLi5udm+fPnShlPB/////zMwMPzHqQBK41TAxEAAsPz79+8/ZSYQcgMdrBj1JpIbGBkZ/5FtwqgCCAAAJ9onK5/spQ0AAAAASUVORK5CYII=' write_png top-right-active.png 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAdCAYAAACXFC2jAAAAR0lEQVR42u2PMQ7AIAwDz6hjXszEy+MOZSUMlZi41dY5ETAokO1YhRHRH8Crgm2XBYDGhtKQmf5nODRx35wGSVnk+xtu4eMFmCwkTAAQh0MAAAAASUVORK5CYII=' write_png top-right-inactive.png 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAdCAYAAACXFC2jAAAAR0lEQVR42u2PMQ7AIAwDz6hjXszEy+MOZSUMlZi41dY5ETAokO1YhRHRH8Crgm2XBYDGhtKQmf5nODRx35wGSVnk+xtu4eMFmCwkTAAQh0MAAAAASUVORK5CYII=' # 3) Optional: colour of the focused window's title text if [ -n "$ACTIVE_TITLE_COLOR" ]; then rc="$DST/themerc" if grep -q '^active_text_color=' "$rc"; then sed -i "s|^active_text_color=.*|active_text_color=$ACTIVE_TITLE_COLOR|" "$rc" else echo "active_text_color=$ACTIVE_TITLE_COLOR" >> "$rc" fi echo "Active title colour: $ACTIVE_TITLE_COLOR" fi echo "Created $DST_THEME" xfconf-query -c xfwm4 -p /general/theme -s Default 2>/dev/null || true xfconf-query -c xfwm4 -p /general/theme -s Default-Square 2>/dev/null \ && echo "Applied theme 'Default-Square'." \ || echo "Select 'Default-Square' in Settings > Window Manager > Style."