Skip to content

Commit fbb2960

Browse files
committed
feat(quickemu): enable SPICE display reconnection for running VMs
Fixes #1370 Signed-off-by: Martin Wimpress <martin@wimpress.org>
1 parent 3c16de4 commit fbb2960

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

quickemu

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ function kill_vm() {
165165
if [ -z "${VM_PID}" ]; then
166166
echo " - ${VMNAME} is not running."
167167
rm -f "${VMDIR}/${VMNAME}.pid"
168+
rm -f "${VMDIR}/${VMNAME}.spice"
168169
elif [ -n "${VM_PID}" ]; then
169170
if kill -9 "${VM_PID}" > /dev/null 2>&1; then
170171
echo " - ${VMNAME} (${VM_PID}) killed."
171172
rm -f "${VMDIR}/${VMNAME}.pid"
173+
rm -f "${VMDIR}/${VMNAME}.spice"
172174
else
173175
echo " - ${VMNAME} (${VM_PID}) was not killed."
174176
fi
@@ -1409,6 +1411,7 @@ function configure_audio() {
14091411

14101412
function configure_ports() {
14111413
echo -n "" > "${VMDIR}/${VMNAME}.ports"
1414+
rm -f "${VMDIR}/${VMNAME}.spice"
14121415

14131416
if [ -z "${ssh_port}" ]; then
14141417
# Find a free port to expose ssh to the guest
@@ -1472,6 +1475,7 @@ function configure_ports() {
14721475
echo " - SPICE: Enabled"
14731476
else
14741477
echo "spice,${spice_port}" >> "${VMDIR}/${VMNAME}.ports"
1478+
echo "${spice_port}" > "${VMDIR}/${VMNAME}.spice"
14751479
echo -n " - SPICE: On host: spicy --title \"${VMNAME}\" --port ${spice_port}"
14761480
if [ "${guest_os}" != "macos" ] && [ -n "${PUBLIC}" ]; then
14771481
echo -n " --spice-shared-dir ${PUBLIC}"
@@ -2115,6 +2119,7 @@ function vm_boot() {
21152119
else
21162120
echo " - Process: ERROR! Failed to start ${VM} as ${VMNAME}"
21172121
rm -f "${VMDIR}/${VMNAME}.pid"
2122+
rm -f "${VMDIR}/${VMNAME}.spice"
21182123
echo && cat "${VMDIR}/${VMNAME}.log"
21192124
exit 1
21202125
fi
@@ -2732,6 +2737,7 @@ if [ -n "${VM}" ] && [ -e "${VM}" ]; then
27322737
#VM is not running, cleaning up.
27332738
VM_PID=""
27342739
rm -f "${VMDIR}/${VMNAME}.pid"
2740+
rm -f "${VMDIR}/${VMNAME}.spice"
27352741
fi
27362742
fi
27372743

@@ -2795,6 +2801,13 @@ else
27952801
echo "${VMNAME}"
27962802
echo " - Process: Already running ${VM} as ${VMNAME} (${VM_PID})"
27972803
parse_ports_from_file
2804+
# Auto-detect SPICE if .spice file exists and display is a default GUI type
2805+
if [ -r "${VMDIR}/${VMNAME}.spice" ]; then
2806+
if [ "${display}" == "sdl" ] || [ "${display}" == "cocoa" ] || [ "${display}" == "gtk" ]; then
2807+
display="spice"
2808+
spice_port=$(cat "${VMDIR}/${VMNAME}.spice")
2809+
fi
2810+
fi
27982811
start_viewer
27992812
fi
28002813

0 commit comments

Comments
 (0)