-
-
Save manuuurino/ad96dfbdc5654c7095d28252901763b2 to your computer and use it in GitHub Desktop.
Manual Implementation of Auto Resizing For Non-Gnome Environments (like XFCE) running under Spice/Libvirt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Bash required | |
| # Should be run as root and saved to /usr/local/bin/x-resize | |
| # Requies udev rule: /etc/udev/rules.d/50-x-resize.rules | |
| # udev rule content: | |
| # ACTION=="change",KERNEL=="card0", SUBSYSTEM=="drm", RUN+="/usr/local/bin/x-resize" | |
| # Make sure auto-resize is enabled in virt-viewer/spicy | |
| # Credit for Finding Sessions as Root: https://unix.stackexchange.com/questions/117083/how-to-get-the-list-of-all-active-x-sessions-and-owners-of-them | |
| # Credit for Resizing via udev: https://superuser.com/questions/1183834/no-auto-resize-with-spice-and-virt-manager | |
| ## Ensure Log Directory Exists | |
| LOG_DIR=/var/log/autores; | |
| if [ ! -d $LOG_DIR ]; then | |
| mkdir $LOG_DIR; | |
| fi | |
| LOG_FILE=${LOG_DIR}/autores.log | |
| ## Function to find User Sessions & Resize their display | |
| function x_resize() { | |
| declare -A disps usrs | |
| usrs=() | |
| disps=() | |
| for i in $(users);do | |
| [[ $i = root ]] && continue # skip root | |
| usrs[$i]=1 | |
| done | |
| for u in "${!usrs[@]}"; do | |
| for i in $(sudo ps e -u "$u" | sed -rn 's/.* DISPLAY=(:[0-9]*).*/\1/p');do | |
| disps[$i]=$u | |
| done | |
| done | |
| for d in "${!disps[@]}";do | |
| session_user="${disps[$d]}" | |
| session_display="$d" | |
| session_output=$(sudo -u "$session_user" PATH=/usr/bin DISPLAY="$session_display" xrandr | awk '/ connected/{print $1; exit; }') | |
| echo "Session User: $session_user" | tee -a $LOG_FILE; | |
| echo "Session Display: $session_display" | tee -a $LOG_FILE; | |
| echo "Session Output: $session_output" | tee -a $LOG_FILE; | |
| sudo -u "$session_user" PATH=/usr/bin DISPLAY="$session_display" xrandr --output "$session_output" --auto | tee -a $LOG_FILE; | |
| done | |
| } | |
| echo "Resize Event: $(date)" | tee -a $LOG_FILE | |
| x_resize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment