Szymon Niedźwiedź 2023/11/14

Wireless mouse issues on Libvirt/QEMU based VMs

There are problems with event device (mouse, keyboard) support in Libvirt/QEMU.

  1. Mouse cannot be reconnected
  2. When mouse is not connected, VM won’t start, XML must be modified, this is not practical.

Solution

I created proxydev which is simple Linux C program which allows to pass all event devices at one after configuring single file and allows to add simple keyboard macros. This allows bluetooth mouse hot-plug support.

Libvirt part

  1. Install proxydev from AUR
  2. Configure /etc/proxydev/config.toml
  3. Run systemctl enable --now proxydev.service to start now and enable service on system boot
  4. Configure xml inside vm
<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
  <devices>
    ...
  </devices>
  <!-- start of relevant part -->
  <qemu:commandline>
    <qemu:arg value="-object"/>
    <qemu:arg value="input-linux,id=input1,evdev=/dev/input/by-id/proxydev,grab_all=yes,repeat=on"/>
  </qemu:commandline>
  <!-- end of relevant part-->
</domain>

Give libvirt/QEMU access to input devices.

QEMU needs to access to /dev/input/by-id/proxydev device so it will be added to input group, otherwise machine start-up fails.

# usermod -aG input libvirt-qemu

User Experience

When using Looking Glass usually i had use two key-combinations CTRL+CTRL for QEMU to grab proxydev and NUMLOCK+F to maximize Looking Glass window. In order to make this experience better i added two macros. When user presses F11 - CTRL+CTRL is actually pressed and when user presses F12, then NUMLOCK+F is pressed. I never had to use these keys so i hardcoded them for VM activities.

enable disqus comments