diff --git a/sdata/subcmd-virtmon/0.run.sh b/sdata/subcmd-virtmon/0.run.sh index efcd53b21..ea22c1643 100644 --- a/sdata/subcmd-virtmon/0.run.sh +++ b/sdata/subcmd-virtmon/0.run.sh @@ -3,11 +3,30 @@ # shellcheck shell=bash -readarray -t vmon < <(hyprctl -j monitors all | jq -r '.[] | select(.name | test("^HEADLESS-")) | .name') +readarray -t vmons < <(hyprctl -j monitors all | jq -r '.[] | select(.name | test("^HEADLESS-")) | .name') -if [ "${#vmon[@]}" -gt 0 ]; then - printf '%s\n' "${vmon[@]}" +if [ "${#vmons[@]}" -gt 0 ]; then + echo "headless monitors found:" + printf '%s\n' "${vmons[@]}" + if [[ ! "${KEEP_VIRTUAL_MONITORS}" = true ]]; then + echo "Cleaning..." + for i in "${vmons[@]}"; do + x hyprctl output remove "$i" + done + fi else - echo "no headless monitors found" >&2 - exit 1 + echo "No headless monitors found." fi + +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') +#echo "Setting geometry..." +#${vmon_new} + +echo "Using wayvnc to share monitor..." +wayvnc -o=${vmon_new} --log-level=trace 0.0.0.0 5901 + +echo "Cleaning the new headless monitor..." +x hyprctl output remove "${vmon_new}" diff --git a/sdata/subcmd-virtmon/options.sh b/sdata/subcmd-virtmon/options.sh index be001ea39..d1e25219a 100644 --- a/sdata/subcmd-virtmon/options.sh +++ b/sdata/subcmd-virtmon/options.sh @@ -8,12 +8,13 @@ Create virtual monitor for testing multi-monitors. Options: -h, --help Show this help message + -k, --keep Do not remove virtual monitors " } # `man getopt` to see more para=$(getopt \ - -o h \ - -l help \ + -o hk \ + -l help,keep \ -n "$0" -- "$@") [ $? != 0 ] && echo "$0: Error when getopt, please recheck parameters." && exit 1 ##################################################################################### @@ -26,6 +27,15 @@ while true ; do esac done +eval set -- "$para" +while true ; do + case "$1" in + -k|--keep) KEEP_VIRTUAL_MONITORS=true;shift;; + --) shift;break ;; + *) sleep 0 ;; + esac +done + #if [[ -f "$1" ]]; then # echo "Using list file \"$1\".";LIST_FILE_PATH="$1";shift 1 #else