EN | RU
Script to autoresize display in SPICE session. Tested on Arch Linux with:
- X11:
i3
windows manager; - Wayland:
sddm
login manager,sway
wayland compositor.
Preview:
-
Install required packages:
-
Arch-based:
sudo pacman --sync --refresh --needed bash xorg-xrandr screen jq spice-vdagent xf86-video-qxl
bash
- for script execution;xorg-xrandr
- forxrandr
command to get and modify display outputs;screen
- to run script for sway in background;jq
- to parseswaymsg
output;spice-vdagent
andxf86-video-qxl
- SPICE guest tools.
-
-
Install
drm_info
:-
Arch-based:
yay --sync --refresh --needed --sudoloop drm_info
-
-
Download script
display-autoresize
from this repository and make it executable:sudo wget -O /usr/local/bin/display-autoresize https://raw.githubusercontent.com/Nikolai2038/display-autoresize/refs/heads/main/display-autoresize && \ sudo chmod +x /usr/local/bin/display-autoresize
- You can put script not in
/usr/local/bin/display-autoresize
, but make sure to change path to it in udev rule too (see below).
- You can put script not in
-
Create udev rule:
echo 'ACTION=="change", KERNEL=="card[0-9]*", SUBSYSTEM=="drm", RUN+="/usr/local/bin/display-autoresize"' | sudo tee /etc/udev/rules.d/50-display-autoresize.rules && \ sudo udevadm control --reload-rules
-
Make sure
spice-vdagentd
is loaded and running fine.
Additionally, if you want this script to work for login manager you are using (SDDM for example) - make sure to start login manager from unprivileged user.
As I tested with SDDM, if it is running from root, udev
events does not occur so script to autoresize is not called.
To start SDDM as unprivileged user:
sudo mkdir --parents /etc/sddm.conf.d && \
echo '[General]
DisplayServer=x11-user' | sudo tee /etc/sddm.conf.d/set_compositor.conf && \
echo 'allowed_users = anybody
needs_root_rights = no' | sudo tee --append /etc/X11/Xwrapper.config && \
sudo systemctl restart sddm.service
For more info, check:
man sddm.conf
man Xorg.wrap
Update 2025-01-13:
- I tried
x11-user
andwayland
forDisplayServer
setting for some time, and found out, that they are a lot more unstable, than the defaultx11
setting. Specifically,x11-user
will cause user session (after you logged in) to crash after some time. As forwayland
- it has freeze problems when connected viaaSPICE
Android app. I don't test all this properly, but will stick to defaultx11
for now.
Just make sure that auto-resize is enabled when you are connecting via virt-viewer
/spicy
.
- Watch udev events on resize with
udevadm monitor
; - Watch
dmesg -w
(may not be super useful); - Watch logs with
tail -f /var/log/display-autoresize.log
.
- "Forked" from gist but with
XAUTHORITY
and Sway (Wayland) support; - Credit for finding sessions as root;
- Credit for resizing via udev;
- Credit for
drm_info
solution to get current window resolution in Wayland.
You can help me with:
- Testing in other distributions (Debian, Fedora, etc.) and update instructions for them;
- Testing on other Window Managers and Wayland compositors;
- Maybe optimizing code and finding more elegant and fast solutions for parsing;
- Translate
README.md
to other languages.
Feel free to contribute via pull requests or issues!