diff --git a/sdata/subcmd-virtmon/0.run.sh b/sdata/subcmd-virtmon/0.run.sh index ea22c1643..f66312204 100644 --- a/sdata/subcmd-virtmon/0.run.sh +++ b/sdata/subcmd-virtmon/0.run.sh @@ -22,11 +22,32 @@ echo "Creating headless monitor..." readarray -t vmons_old < <(hyprctl -j monitors all | jq -r '.[] | select(.name | test("^HEADLESS-")) | .name') x hyprctl output create headless readarray -t vmons_new < <(hyprctl -j monitors all | jq -r '.[] | select(.name | test("^HEADLESS-")) | .name') +declare -A seen +for e in "${vmons_old[@]}"; do + seen["$e"]=1 +done +deltas=() +for e in "${vmons_new[@]}"; do + if [[ -z "${seen[$e]+_}" ]]; then + deltas+=("$e") + fi +done +if (( ${#deltas[@]} == 1 )); then + vmon_tester="${deltas[0]}" + echo "New virtual monitor found: $vmons_tester" +elif (( ${#deltas[@]} == 0 )); then + echo "Error: No new virtual monitor found" + exit 1 +else + echo "Error: multiple new virtual monitor found: ${deltas[*]}" + exit 1 +fi #echo "Setting geometry..." #${vmon_new} echo "Using wayvnc to share monitor..." -wayvnc -o=${vmon_new} --log-level=trace 0.0.0.0 5901 +# TODO: handle port properly +wayvnc -o=${vmon_tester} --log-level=trace 0.0.0.0 5901 echo "Cleaning the new headless monitor..." -x hyprctl output remove "${vmon_new}" +x hyprctl output remove "${vmon_tester}"