refactor!: remove --screenpct and simplify use of --width/--height

This commit is contained in:
Martin Wimpress 2024-05-12 12:46:07 +01:00 committed by Martin Wimpress
parent 493bacc318
commit 0b5050511b
1 changed files with 13 additions and 73 deletions

View File

@ -727,45 +727,14 @@ function vm_boot() {
esac esac
# Determine a sane resolution for Linux guests. # Determine a sane resolution for Linux guests.
if [ "${guest_os}" == "linux" ]; then #if [ "${guest_os}" == "linux" ]; then
local X_RES=1152 local X_RES="1280"
local Y_RES=648 local Y_RES="800"
if [ -n "${width}" ] && [ -n "${height}" ]; then
# If the user has specified a resolution, use that via config or command line. local X_RES="${width}"
if [ -n "${WIDTH}" ] && [ -n "${HEIGHT}" ]; then local Y_RES="${height}"
X_RES="${WIDTH}"
Y_RES="${HEIGHT}"
elif [ "${XDG_SESSION_TYPE}" == "x11" ] || [ "${XDG_SESSION_TYPE}" == "wayland" ]; then
if [ -z "${SCREEN}" ]; then
X_RES=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f1 | sort | head -n1)
Y_RES=$(xrandr --listmonitors | grep -v Monitors | cut -d' ' -f4 | cut -d'/' -f2 | cut -d'x' -f2 | sort | head -n1)
else
X_RES=$(xrandr --listmonitors | grep -v Monitors | grep "^ ${SCREEN}:" | cut -d' ' -f4 | cut -d'/' -f1 | head -n1)
Y_RES=$(xrandr --listmonitors | grep -v Monitors | grep "^ ${SCREEN}:" | cut -d' ' -f4 | cut -d'/' -f2 | cut -d'x' -f2 | head -n1)
fi
if [ "${FULLSCREEN}" ]; then
:
elif [ "${SCREENPCT}" ] ; then
X_RES=$(( X_RES*SCREENPCT/100 ))
Y_RES=$(( Y_RES*SCREENPCT/100 ))
elif [ "${X_RES}" -ge 3840 ]; then
X_RES=3200
Y_RES=1800
elif [ "${X_RES}" -ge 2560 ]; then
X_RES=2048
Y_RES=1152
elif [ "${X_RES}" -ge 1920 ]; then
X_RES=1664
Y_RES=936
elif [ "${X_RES}" -ge 1280 ]; then
X_RES=1152
Y_RES=648
else
:
fi
fi
fi fi
#fi
# https://www.kraxel.org/blog/2019/09/display-devices-in-qemu/ # https://www.kraxel.org/blog/2019/09/display-devices-in-qemu/
if [ "${guest_os}" == "linux_old" ]; then if [ "${guest_os}" == "linux_old" ]; then
@ -1431,8 +1400,6 @@ function usage() {
echo " --ignore-msrs-always : Configure KVM to always ignore unhandled machine-specific registers" echo " --ignore-msrs-always : Configure KVM to always ignore unhandled machine-specific registers"
echo " --kill : Kill the VM process if it is running" echo " --kill : Kill the VM process if it is running"
echo " --offline : Override all network settings and start the VM offline" echo " --offline : Override all network settings and start the VM offline"
echo " --screen <screen> : Use specified screen to determine the window size."
echo " --screenpct <percent> : Percent of fullscreen for VM if --fullscreen is not specified."
echo " --shortcut : Create a desktop shortcut" echo " --shortcut : Create a desktop shortcut"
echo " --snapshot apply <tag> : Apply/restore a snapshot." echo " --snapshot apply <tag> : Apply/restore a snapshot."
echo " --snapshot create <tag> : Create a snapshot." echo " --snapshot create <tag> : Create a snapshot."
@ -1440,8 +1407,8 @@ function usage() {
echo " --snapshot info : Show disk/snapshot info." echo " --snapshot info : Show disk/snapshot info."
echo " --status-quo : Do not commit any changes to disk/snapshot." echo " --status-quo : Do not commit any changes to disk/snapshot."
echo " --viewer <viewer> : Choose an alternative viewer. @Options: 'spicy' (default), 'remote-viewer', 'none'" echo " --viewer <viewer> : Choose an alternative viewer. @Options: 'spicy' (default), 'remote-viewer', 'none'"
echo " --width <width> : Set VM screen width. Does nothing without --height" echo " --width <width> : Set VM screen width; requires '--height'"
echo " --height <height> : Set VM screen height. Does nothing without --width" echo " --height <height> : Set VM screen height; requires '--width'"
echo " --ssh-port <port> : Set ssh-port manually" echo " --ssh-port <port> : Set ssh-port manually"
echo " --spice-port <port> : Set spice-port manually" echo " --spice-port <port> : Set spice-port manually"
echo " --public-dir <path> : Expose share directory. @Options: '' (default: xdg-user-dir PUBLICSHARE), '<directory>', 'none'" echo " --public-dir <path> : Expose share directory. @Options: '' (default: xdg-user-dir PUBLICSHARE), '<directory>', 'none'"
@ -1581,8 +1548,8 @@ secureboot="off"
tpm="off" tpm="off"
usb_devices=() usb_devices=()
viewer="spicy" viewer="spicy"
width="" width="${width:-}"
height="" height="${height:-}"
ssh_port="" ssh_port=""
spice_port="" spice_port=""
public_dir="" public_dir=""
@ -1613,8 +1580,6 @@ OUTPUT=""
PUBLIC="" PUBLIC=""
PUBLIC_PERMS="" PUBLIC_PERMS=""
PUBLIC_TAG="" PUBLIC_TAG=""
SCREEN=""
SCREENPCT=""
SHORTCUT=0 SHORTCUT=0
SNAPSHOT_ACTION="" SNAPSHOT_ACTION=""
SNAPSHOT_TAG="" SNAPSHOT_TAG=""
@ -1625,8 +1590,6 @@ VMDIR=""
VMNAME="" VMNAME=""
VMPATH="" VMPATH=""
VIEWER="" VIEWER=""
WIDTH=""
HEIGHT=""
SSH_PORT="" SSH_PORT=""
SPICE_PORT="" SPICE_PORT=""
MONITOR="" MONITOR=""
@ -1702,24 +1665,6 @@ else
-offline|--offline) -offline|--offline)
network="none" network="none"
shift;; shift;;
-screen|--screen)
SCREEN="${2}"
shift
shift;;
-screenpct|--screenpct)
if [ -n "${2##*[!0-9]*}" ] ; then
if [[ ${2} -ge 25 && ${2} -lt 100 ]] ; then
SCREENPCT=${2}
else
echo "screenpct invalid must be 25 <= pct < 100"
usage
fi
else
echo "screenpct needs to be an integer in range 25 <= pct < 100"
usage
fi
shift
shift;;
-snapshot|--snapshot) -snapshot|--snapshot)
SNAPSHOT_ACTION="${2}" SNAPSHOT_ACTION="${2}"
if [ -z "${SNAPSHOT_ACTION}" ]; then if [ -z "${SNAPSHOT_ACTION}" ]; then
@ -1749,11 +1694,11 @@ else
shift shift
shift;; shift;;
-width|--width) -width|--width)
WIDTH="${2}" width="${2}"
shift; shift;
shift;; shift;;
-height|--height) -height|--height)
HEIGHT="${2}" height="${2}"
shift; shift;
shift;; shift;;
-ssh-port|--ssh-port) -ssh-port|--ssh-port)
@ -1877,11 +1822,6 @@ if [ -n "${VM}" ] && [ -e "${VM}" ]; then
fi fi
viewer_param_check viewer_param_check
if [ -z "${WIDTH}" ] || [ -z "${HEIGHT}" ] ; then
WIDTH="${width}"
HEIGHT="${height}"
fi
# Set the default 3D acceleration. # Set the default 3D acceleration.
if [ -z "${gl}" ]; then if [ -z "${gl}" ]; then
if command -v glxinfo &>/dev/null; then if command -v glxinfo &>/dev/null; then