Improve virtmon

This commit is contained in:
clsty
2025-11-12 18:55:33 +08:00
parent 9162c24ccd
commit 56c07a514f
4 changed files with 78 additions and 70 deletions
+1 -56
View File
@@ -11,51 +11,6 @@ function vianix-warning(){
printf "${STY_RST}"
pause
}
function install_cmds(){
case $OS_GROUP_ID in
"arch")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
x sudo pacman -Syu
x sudo pacman -S --noconfirm --needed "${pkgs[@]}"
;;
"debian")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
x sudo apt update -y
x sudo apt install -y "${pkgs[@]}"
;;
"fedora")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
x sudo dnf install -y "${pkgs[@]}"
;;
"suse")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
x sudo zypper refresh
x sudo zypper -n install "${pkgs[@]}"
;;
*)
printf "WARNING\n"
printf "No method found to install package providing the commands:\n"
printf " $@\n"
printf "Please install by yourself.\n"
;;
esac
}
function install_nix(){
# https://github.com/NixOS/experimental-nix-installer
local cmd=nix
@@ -110,18 +65,8 @@ function hm_deps(){
vianix-warning
NOT_FOUND_CMDS=()
TEST_CMDS=(curl fish swaylock gnome-keyring)
for cmd in "${TEST_CMDS[@]}"; do
if ! command -v $cmd >/dev/null 2>&1;then
NOT_FOUND_CMDS+=($cmd)
fi
done
if [[ ${#NOT_FOUND_CMDS[@]} -gt 0 ]]; then
echo -e "${STY_YELLOW}[$0]: Not found: ${NOT_FOUND_CMDS[*]}.${STY_RST}"
showfun install_cmds
v install_cmds "${NOT_FOUND_CMDS[@]}"
fi
ensure_cmds "${TEST_CMDS[@]}"
if ! command -v nix >/dev/null 2>&1;then
echo -e "${STY_YELLOW}[$0]: \"nix\" not found.${STY_RST}"
+57
View File
@@ -344,3 +344,60 @@ function backup_clashing_targets(){
x mkdir -p $backup_dir
x rsync -av --progress "${args_includes[@]}" "$target_dir/" "$backup_dir/"
}
function install_cmds(){
case $OS_GROUP_ID in
"arch")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
v sudo pacman -Syu
v sudo pacman -S --noconfirm --needed "${pkgs[@]}"
;;
"debian")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
v sudo apt update -y
v sudo apt install -y "${pkgs[@]}"
;;
"fedora")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
v sudo dnf install -y "${pkgs[@]}"
;;
"suse")
local pkgs=()
for cmd in "$@";do
# For package name which is not cmd name, use "case" syntax to replace
pkgs+=($cmd)
done
v sudo zypper refresh
v sudo zypper -n install "${pkgs[@]}"
;;
*)
printf "WARNING\n"
printf "No method found to install package providing the commands:\n"
printf " $@\n"
printf "Please install by yourself.\n"
;;
esac
}
function ensure_cmds(){
local not_found_cmds=()
for cmd in "$@"; do
if ! command -v $cmd >/dev/null 2>&1;then
not_found_cmds+=($cmd)
fi
done
if [[ ${#not_found_cmds[@]} -gt 0 ]]; then
echo -e "${STY_YELLOW}[$0]: Not found: ${not_found_cmds[*]}.${STY_RST}"
install_cmds "${not_found_cmds[@]}"
fi
}
+16 -6
View File
@@ -5,6 +5,15 @@
readarray -t vmons < <(hyprctl -j monitors all | jq -r '.[] | select(.name | test("^HEADLESS-")) | .name')
ensure_cmds wayvnc lsof jq
if [[ "${CLEAN_VIRTUAL_MONITORS}" = true ]]; then
echo "Cleaning virtual monitors..."
for i in "${vmons[@]}"; do
x hyprctl output remove "$i"
done
exit 0
fi
if [ "${#vmons[@]}" -gt 0 ]; then
echo "headless monitors found:"
printf '%s\n' "${vmons[@]}"
@@ -18,7 +27,7 @@ else
echo "No headless monitors found."
fi
echo "Creating headless monitor..."
echo "Creating tester 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')
@@ -34,12 +43,12 @@ for e in "${vmons_new[@]}"; do
done
if (( ${#deltas[@]} == 1 )); then
vmon_tester="${deltas[0]}"
echo "New virtual monitor found: $vmons_tester"
echo "tester monitor found: $vmons_tester"
elif (( ${#deltas[@]} == 0 )); then
echo "Error: No new virtual monitor found"
echo "Error: No tester monitor found"
exit 1
else
echo "Error: multiple new virtual monitor found: ${deltas[*]}"
echo "Error: multiple tester monitor found: ${deltas[*]}"
exit 1
fi
#echo "Setting geometry..."
@@ -52,10 +61,11 @@ for port in {5900..5999}; do
break
fi
done
# TODO: Allow running in background and implement --stop to stop it
if [ -z "$vnc_port" ];then
echo "No available port for vnc server, aborting..."; exit 1
fi
wayvnc -S -o=${vmon_tester} --log-level=trace 0.0.0.0 $vnc_port
echo "Cleaning the new headless monitor..."
x hyprctl output remove "${vmon_tester}"
echo "Cleaning the tester monitor..."
hyprctl output remove "${vmon_tester}"
+4 -8
View File
@@ -8,13 +8,14 @@ Create virtual monitor for testing multi-monitors.
Options:
-h, --help Show this help message
-c, --clean Clean all virtual monitors and exit
-k, --keep Do not remove virtual monitors
"
}
# `man getopt` to see more
para=$(getopt \
-o hk \
-l help,keep \
-o hck \
-l help,clean,keep \
-n "$0" -- "$@")
[ $? != 0 ] && echo "$0: Error when getopt, please recheck parameters." && exit 1
#####################################################################################
@@ -30,14 +31,9 @@ done
eval set -- "$para"
while true ; do
case "$1" in
-c|--clean) CLEAN_VIRTUAL_MONITORS=true;shift;;
-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
# echo "Wrong path \"$1\" of list file.";exit 1
#fi