Publication date: 2022-04-08
Normally, with "spice-vdagent" installed, screen resolution of the guest is automatically adjusted so that it fits the resolution of the SPICE client window. However, since Xfce4 does not handle the resize events triggered when resizing SPICE client window, the screen resolution of the guest system is not adjusted automatically.
Within a terminal window within the guest system, adjustment of screen resolution can be triggered manually like this:
xrandr --output Virtual-1 --auto
This can be automized by listening and reacting on resize events ourselves.
Create an ".xsessionrc" in your home directory in your guest system and start a script that does the job:
#!/bin/sh
if [ -x /usr/bin/spice-vdagent ] ; then
/opt/scripts/observe_resizeevents.sh &
fi
Create the script ("/opt/scripts/observe_resizeevents.sh") like this:
#!/bin/sh
# Uses code from: https://superuser.com/questions/1183834/no-auto-resize-with-sp
ice-and-virt-manager
sleep 10
xrandr --output "$(xrandr | awk '/ connected/{print $1; exit; }')" --auto
xev -root -event randr | \
grep --line-buffered 'subtype XRROutputChangeNotifyEvent' | \
while read foo ; do \
xrandr --output "$(xrandr | awk '/ connected/{print $1; exit; }')" --auto
done
This listens to the events. Whenever a relevant one is received, we trigger "xrandr" to adjust the screen resolution. Note that this is a nice example of the power of piping.