| 1 | #!/usr/bin/env bash |
| 2 | # Usage: scripts/layout-sweep.sh [OUT_DIR] |
| 3 | # Screenshots every main screen at the minimum and a large window size. Run `cargo build -p app` first. |
| 4 | # Output: OUT_DIR/<size>-<screen>.png (default target/layout-sweep) |
| 5 | set -euo pipefail |
| 6 | |
| 7 | out_dir=${1:-target/layout-sweep} |
| 8 | script_dir=$(cd "$(dirname "$0")" && pwd) |
| 9 | sizes=(640x480 1920x1080) |
| 10 | status_avatar_offset_from_right=${STATUS_AVATAR_OFFSET:-34} |
| 11 | status_avatar_y=20 |
| 12 | mkdir -p "$out_dir" |
| 13 | |
| 14 | for window_size in "${sizes[@]}"; do |
| 15 | width=${window_size%x*} |
| 16 | height=${window_size#*x} |
| 17 | screen_size="$((width + 480))x$((height > 900 ? height : 900))" |
| 18 | focus=("mousemove $((width / 2)) 3" "click 1" "sleep 1.5") |
| 19 | captured=() |
| 20 | capture() { |
| 21 | local screen=$1 |
| 22 | local target="$out_dir/$window_size-$screen.png" |
| 23 | shift |
| 24 | for attempt in 1 2 3; do |
| 25 | "$script_dir/headless-shot.sh" "$target" --size "$screen_size" --window "$window_size" --wait 15 --settle 3 -- "${focus[@]}" "$@" >/dev/null |
| 26 | local checksum |
| 27 | checksum=$(convert "$target" -crop "${width}x100+0+0" +repage png:- | md5sum) |
| 28 | [[ " ${captured[*]:-} " != *" $checksum "* ]] && break |
| 29 | echo "$target repeats an earlier screen, input dropped (attempt $attempt)" >&2 |
| 30 | done |
| 31 | captured+=("$checksum") |
| 32 | } |
| 33 | capture chats |
| 34 | capture activity "key ctrl+1" "key ctrl+1" |
| 35 | capture channels "key ctrl+3" "key ctrl+3" |
| 36 | capture saved "key ctrl+4" "key ctrl+4" |
| 37 | capture calls "key ctrl+5" "key ctrl+5" |
| 38 | capture status-menu "mousemove $((width - status_avatar_offset_from_right)) $status_avatar_y" "click 1" |
| 39 | capture switcher "key ctrl+k" |
| 40 | capture shortcuts "key ctrl+period" |
| 41 | done |
| 42 | |
| 43 | ls "$out_dir"/*.png |
| 44 | duplicates=$(for target in "$out_dir"/*.png; do |
| 45 | width=$(identify -format %w "$target") |
| 46 | echo "$(convert "$target" -crop "${width}x100+0+0" +repage png:- | md5sum | cut -c1-32) $target" |
| 47 | done | sort | uniq -D -w32) |
| 48 | [[ -z $duplicates ]] || { echo "identical screenshots, an input was dropped, rerun:" >&2; echo "$duplicates" >&2; exit 1; } |