Qemu: Mouse cursor offset

 · 2 min · torgeir

For the longest time I have been troubled by a mouse cursor offset when running Windows in a VM with qemu. The -usbdevice tablet option fixes it.

Linux Vm Qemu Mouse

Wine has come a long way the later years. Even so, a few apps I rely on still needs a Windows VM. One such app is HX Edit, the editor software for the Helix Floor guitar processor.

For the longest time I have been troubled by a mouse cursor offset with this setup, that occur sometimes when you move the mouse in and out of the Windows VM window and the host OS a few times. The only “fix” to reset it has been moving the cursor around the VM window and in again from the other side, which gets pretty annoying in the long run. I have never been able to figure out the cause or fix for this.

Until today, when I read this comment from Meow-ops about noVNC on a similar issue.

… Even when “-usbdevice tablet” option is used when starting qemu

And I don’t use noVNC, I experience this using tigervnc as well, but what do you know - adding the option -usbdevice tablet alongside all the other qemu options needed for this VM to work with HX edit, the problem goes away!

Here’s the whole of the command

qemu-system-x86_64 \
    -m 4G \
    -cpu host \
    -enable-kvm \
    -drive file=$HOME/virtualization/windows_10_x64.qcow2,if=ide \
    -device qemu-xhci \
    -usb -device usb-host,hostbus=1,hostport= \
    -usbdevice tablet \
    -net nic \
    -net user,smb=/home/torgeir/virtualization/shared/ \
    -vnc :0

The docs state that the -usbdevice tablet option changes the way coordinates are resolved.

Pointer device that uses absolute coordinates (like a touchscreen). This means QEMU is able to report the mouse position without having to grab the mouse. Also overrides the PS/2 mouse emulation when activated.

In short, this conglomerate of options do the following:

  • run a vm from the .cow2 image
  • forwards the usb device that is my audiofuse sound card to the vm (found using lsusb -t)
  • your user needs access to the usb device, or you need to run it with sudo
  • gives it internet access
  • shares a folder over smb with the host so I can move files to and from it
  • make it listen for vnc connections on display :0

I created the image using this

qemu-img create -f qcow2 windows_10_x64.qcow2 100G

I ran it using with the option -cdrom Win10_21H1_EnglishInternational_x64.iso the first time around to install windows in the VM from the .iso image in the same folder.