Last active
July 31, 2022 08:00
-
-
Save ivan/9e1bf24c1b6ae4f1fe9587b55d3f9544 to your computer and use it in GitHub Desktop.
fix-qemu-guest-resolution
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 | |
# SPICE clipboard sharing is not safe to use: | |
# https://bugzilla.redhat.com/show_bug.cgi?id=1320263 | |
# but guests that have <clipboard copypaste='no'/> can't fix their screen | |
# resolution with `xrandr --output Virtual-0 --auto`, so use this program | |
# to fix the screen resolution for a qemu guest over ssh. This should be | |
# run on the host machine, not the guest. | |
set -eu -o pipefail | |
set-qemu-guest-resolution() { | |
width=$1 | |
height=$2 | |
# 2> /dev/null to ignore cryptic complaint about mode already existing | |
xrandr --newmode ${width}x${height} $(gtf ${width} ${height} 60 | grep -o 'Modeline .*' | cut -f 3- -d ' ') 2> /dev/null | |
xrandr --addmode Virtual-0 ${width}x${height} | |
xrandr --output Virtual-0 --mode ${width}x${height} | |
} | |
get-spice-window-resolution() { | |
host=$1 | |
window=$(wmctrl -l | grep -- "$host on QEMU/KVM$" | cut -f 1 -d ' ') | |
width=$(xwininfo -id "$window" | grep -P -o 'Width: \d+$' | cut -f 2 -d ' ') | |
height=$(xwininfo -id "$window" | grep -P -o 'Height: \d+$' | cut -f 2 -d ' ') | |
echo "$width $height" | |
} | |
# Adjust these numbers for your machine | |
spice_ui_height=91 | |
spice_ui_width=2 | |
host=$1 | |
res=($(get-spice-window-resolution "$host")) | |
guest_width=$((${res[0]} - $spice_ui_width)) | |
guest_height=$((${res[1]} - $spice_ui_height)) | |
typeset -f set-qemu-guest-resolution | ssh -- "$host" "$(cat); DISPLAY=:0.0 set-qemu-guest-resolution $guest_width $guest_height" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Linked from https://unix.stackexchange.com/questions/341881/virt-manager-copy-and-paste-is-possible-to-disable-it