This script will detect the active VM based on the currently focused window and redirect mouse events from DOM0 to the VM until the script is ran again.
This works for games or anything that uses your mouse.
This is basically doing the reverse of how sys-usb makes your mouse available to your entire system.
- QubesOS/qubes-issues#4986
- qubes-app-linux-input-proxy
- qubes-i3-sensible-terminal (VM detection code)
-
Install
qubes-input-proxy-receiver
in the VMs you want to use this in.Ideally, you'll install qubes-input-proxy-receiver in a template VM and restart your qubes.
Fedora based qubes:
sudo dnf install qubes-input-proxy-receiver
-
Copy the script below to DOM0 and make it executable
In a networked VM:
curl -o /home/user/toggle-mouse.sh https://gist.githubusercontent.com/e9x/f505cf11d42f9470570c9de0b61e15e9/raw/b8ce3f1ca4a2fff1c358d14b4811789a58d0a4eb/toggle-mouse.sh
In DOM0:
qvm-run --pass-io your-vm "cat /home/user/toggle-mouse.sh" > /home/user/toggle-mouse.sh chmod +x /home/user/toggle-mouse.sh
Make sure to review the script and make sure it's safe.
cat /home/user/toggle-mouse.sh
-
Configure the script
Identify your mouse event ID in /dev/input/by-id/
Make sure your mouse is connected directly to DOM0 and is not in a USB VM
In DOM0:
ls /dev/input/by-id/*-event-mouse
Modify the script to use this mouse
nano /home/user/toggle-mouse.sh
Modify this line accordingly.
local mouse=/dev/input/by-id/usb-Logitech_G203_LIGHTSYNC_Gaming_Mouse-event-mouse
-
Add a keybind to run this script when a key is pressed
Qubes by default comes with XFCE which you can configure keyboard shortcuts on.
In DOM0:
xfce4-keyboard-settings
Go to "Application Shortcuts", click on "Add"
Command:
/home/user/toggle-mouse.sh
Press "Ok", then press the key you want to bind it to.
You should now be able to open an application that you want to redirect your mouse to, then press the key you binded the script to, then all your mouse events should go directly to the VM instead of DOM0.
Your cursor icon won't be visible, but this could be fixed in the future by spawning swcursor inside the VM while mouse events are being redirected to simulate the cursor icon.
TODO
line 43
qvm-run ...
for me fails with:open: Permission denied
I assigned my only mouse to
mouse
var 🫤I have no USB qube
As a side note, you should always use
set -euo pipefail
in Bash scripts to catch errors and stop execution of the rest of the script.