#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Usage: mangohud-position-matrix.sh [app] [output_dir] [profile_dir] Examples: mangohud-position-matrix.sh vkcube /tmp/mh-matrix DISPLAY=:1 XAUTHORITY=/root/.Xauthority mangohud-position-matrix.sh glxgears /tmp/mh-matrix /home/aaron/mangotune-test-profiles What it does: - finds the standard MangoTune right-alignment test profiles - generates margin-on and margin-off variants - runs MangoHud directly for each case using mangohud-position-lab.sh - stores generated configs and capture artifacts under the output dir EOF } if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then usage exit 0 fi APP="${1:-vkcube}" OUTPUT_DIR="${2:-/tmp/mangohud-position-matrix}" PROFILE_DIR="${3:-$HOME/.config/mangotune/profiles}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LAB_SCRIPT="$SCRIPT_DIR/mangohud-position-lab.sh" if [[ ! -x "$LAB_SCRIPT" ]]; then chmod +x "$LAB_SCRIPT" 2>/dev/null || true fi mkdir -p "$OUTPUT_DIR/generated" profiles=( "zz_test_right_full_top" "zz_test_right_full_middle" "zz_test_right_sparse_top" "zz_test_right_sparse_middle" "zz_test_right_sparse_compact_top" "zz_test_right_sparse_compact_middle" ) ensure_flag_state() { local input_file="$1" local output_file="$2" local flag="$3" local enabled="$4" awk -v flag="$flag" -v enabled="$enabled" ' BEGIN { saw = 0 } { trimmed = $0 gsub(/^[[:space:]]+/, "", trimmed) if (trimmed == flag || trimmed == "# " flag || trimmed == "#" flag) { if (enabled == "1") { print flag } else { print "# " flag } saw = 1 next } print $0 } END { if (!saw && enabled == "1") { print flag } } ' "$input_file" >"$output_file" } for profile in "${profiles[@]}"; do base="$PROFILE_DIR/$profile.conf" [[ -f "$base" ]] || continue for margin_state in margin_on margin_off; do generated="$OUTPUT_DIR/generated/${profile}_${margin_state}.conf" case "$margin_state" in margin_on) ensure_flag_state "$base" "$generated" "hud_no_margin" 0 ;; margin_off) ensure_flag_state "$base" "$generated" "hud_no_margin" 1 ;; esac case_out="$OUTPUT_DIR/${profile}_${margin_state}_${APP}" "$LAB_SCRIPT" "$generated" "$APP" "$case_out" done done echo "Matrix artifacts written to $OUTPUT_DIR"