Skip to content

Script to autoresize display in SPICE session (X11 and Wayland Sway)

License

Notifications You must be signed in to change notification settings

Nikolai2038/display-autoresize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

display-autoresize

EN | RU

1. Description

Script to autoresize display in SPICE session. Tested on Arch Linux with:

  • X11: i3 windows manager;
  • Wayland: sddm login manager, sway wayland compositor.

Preview:

preview.gif

2. Requirements

2.1. Guest

  1. 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 - for xrandr command to get and modify display outputs;
      • screen - to run script for sway in background;
      • jq - to parse swaymsg output;
      • spice-vdagent and xf86-video-qxl - SPICE guest tools.
  2. Install drm_info:

    • Arch-based:

      yay --sync --refresh --needed --sudoloop drm_info
  3. 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).
  4. 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
  5. Make sure spice-vdagentd is loaded and running fine.

2.1.1. [UNSTABLE] Login Manager (SDDM)

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 and wayland for DisplayServer setting for some time, and found out, that they are a lot more unstable, than the default x11 setting. Specifically, x11-user will cause user session (after you logged in) to crash after some time. As for wayland - it has freeze problems when connected via aSPICE Android app. I don't test all this properly, but will stick to default x11 for now.

2.2. Host

Just make sure that auto-resize is enabled when you are connecting via virt-viewer/spicy.

3. Debugging

  • 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.

4. Credits

5. Contribution

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!