These black edges are so annoying when they don't disappear
Running the master piece. Btw i didn't want to show my username so i ran it as sudo :D
Ahhhh yeeeahhhh!

!! To make a VM automatically resize when changing the size of the window, use Video VGA instead of e.g. Virtio. Also it might be a good idea to give it more vram than only 16 mb. Use sudo virsh edit <my-vm-name> and adjust vram to 65536 / ~64 mb.
Background: I have several Kali VMs running KVM/Qemu with "Auto resize VM with window" enabled, but no way in hell it would just work. Every time i resized the window black edges appeared. But running xrandr --output Virtual-1 --auto within the VM would actually automatically resize the window beautifully. Only problem is i don't have patience doing that every time i resize the window.
I'm therefore introducing this big ass python script that runs the above command within my VM of choise. Now it fixed my problem so I'm not going to prettify it or make it universal meaning it will work for any Qemu VM running Linux.
How does it work?
- Connects to the X11 display and finds the VM window by name/class.
- Subscribes to StructureNotify events and blocks on d.next_event().
- On ConfigureNotify it compares the new width/height to the last known geometry.
- If changed, starts a debounce timer (DELAY_SECONDS) to coalesce rapid resizes.
- When timer fires it calls virsh qemu-agent guest-exec to run xrandr inside the Kali guest.
- Polls guest-exec-status until the guest process finishes.
- Decodes base64 stdout/stderr from the guest and logs output, errors and exit info.
git clone https://github.com/Am0rphous/Automatic-resize-KVM-Qemu-Kali-VM/
cd Automatic-resize-KVM-Qemu-Kali-VM/
python3 kali-auto-resizer.py
#Start a KVM vm named "kali1" with Video Virtio
#Resize the VM window