feat(quickemu): enable SPICE display reconnection for running VMs

Fixes #1370

Signed-off-by: Martin Wimpress <martin@wimpress.org>
This commit is contained in:
Martin Wimpress 2026-01-26 11:47:59 +00:00 committed by Martin Wimpress
parent 3c16de4de3
commit fbb2960ce5
1 changed files with 13 additions and 0 deletions

View File

@ -165,10 +165,12 @@ function kill_vm() {
if [ -z "${VM_PID}" ]; then if [ -z "${VM_PID}" ]; then
echo " - ${VMNAME} is not running." echo " - ${VMNAME} is not running."
rm -f "${VMDIR}/${VMNAME}.pid" rm -f "${VMDIR}/${VMNAME}.pid"
rm -f "${VMDIR}/${VMNAME}.spice"
elif [ -n "${VM_PID}" ]; then elif [ -n "${VM_PID}" ]; then
if kill -9 "${VM_PID}" > /dev/null 2>&1; then if kill -9 "${VM_PID}" > /dev/null 2>&1; then
echo " - ${VMNAME} (${VM_PID}) killed." echo " - ${VMNAME} (${VM_PID}) killed."
rm -f "${VMDIR}/${VMNAME}.pid" rm -f "${VMDIR}/${VMNAME}.pid"
rm -f "${VMDIR}/${VMNAME}.spice"
else else
echo " - ${VMNAME} (${VM_PID}) was not killed." echo " - ${VMNAME} (${VM_PID}) was not killed."
fi fi
@ -1409,6 +1411,7 @@ function configure_audio() {
function configure_ports() { function configure_ports() {
echo -n "" > "${VMDIR}/${VMNAME}.ports" echo -n "" > "${VMDIR}/${VMNAME}.ports"
rm -f "${VMDIR}/${VMNAME}.spice"
if [ -z "${ssh_port}" ]; then if [ -z "${ssh_port}" ]; then
# Find a free port to expose ssh to the guest # Find a free port to expose ssh to the guest
@ -1472,6 +1475,7 @@ function configure_ports() {
echo " - SPICE: Enabled" echo " - SPICE: Enabled"
else else
echo "spice,${spice_port}" >> "${VMDIR}/${VMNAME}.ports" echo "spice,${spice_port}" >> "${VMDIR}/${VMNAME}.ports"
echo "${spice_port}" > "${VMDIR}/${VMNAME}.spice"
echo -n " - SPICE: On host: spicy --title \"${VMNAME}\" --port ${spice_port}" echo -n " - SPICE: On host: spicy --title \"${VMNAME}\" --port ${spice_port}"
if [ "${guest_os}" != "macos" ] && [ -n "${PUBLIC}" ]; then if [ "${guest_os}" != "macos" ] && [ -n "${PUBLIC}" ]; then
echo -n " --spice-shared-dir ${PUBLIC}" echo -n " --spice-shared-dir ${PUBLIC}"
@ -2115,6 +2119,7 @@ function vm_boot() {
else else
echo " - Process: ERROR! Failed to start ${VM} as ${VMNAME}" echo " - Process: ERROR! Failed to start ${VM} as ${VMNAME}"
rm -f "${VMDIR}/${VMNAME}.pid" rm -f "${VMDIR}/${VMNAME}.pid"
rm -f "${VMDIR}/${VMNAME}.spice"
echo && cat "${VMDIR}/${VMNAME}.log" echo && cat "${VMDIR}/${VMNAME}.log"
exit 1 exit 1
fi fi
@ -2732,6 +2737,7 @@ if [ -n "${VM}" ] && [ -e "${VM}" ]; then
#VM is not running, cleaning up. #VM is not running, cleaning up.
VM_PID="" VM_PID=""
rm -f "${VMDIR}/${VMNAME}.pid" rm -f "${VMDIR}/${VMNAME}.pid"
rm -f "${VMDIR}/${VMNAME}.spice"
fi fi
fi fi
@ -2795,6 +2801,13 @@ else
echo "${VMNAME}" echo "${VMNAME}"
echo " - Process: Already running ${VM} as ${VMNAME} (${VM_PID})" echo " - Process: Already running ${VM} as ${VMNAME} (${VM_PID})"
parse_ports_from_file parse_ports_from_file
# Auto-detect SPICE if .spice file exists and display is a default GUI type
if [ -r "${VMDIR}/${VMNAME}.spice" ]; then
if [ "${display}" == "sdl" ] || [ "${display}" == "cocoa" ] || [ "${display}" == "gtk" ]; then
display="spice"
spice_port=$(cat "${VMDIR}/${VMNAME}.spice")
fi
fi
start_viewer start_viewer
fi fi