diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-08-04 10:48:05 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-08-04 10:48:05 -0300 |
commit | 9627eb1b00e1c21a4d6d37752193969feea1bf14 (patch) | |
tree | 1f506bbb7804a8bce7d3a096ed45e7c42fe5cbb9 | |
parent | 2a7d2f4443dc81e518bb25750574af2de296b6b2 (diff) | |
download | kvmx-9627eb1b00e1c21a4d6d37752193969feea1bf14.tar.gz kvmx-9627eb1b00e1c21a4d6d37752193969feea1bf14.tar.bz2 |
Fix: improve xandr handling
-rw-r--r-- | TODO.md | 4 | ||||
-rwxr-xr-x | kvmx | 48 |
2 files changed, 28 insertions, 24 deletions
@@ -2,7 +2,9 @@ ## Fixes -* [ ] Support for `virt-viewer` is currently broken (as of 2024-08-04). +* [x] Support for `virt-viewer` is currently broken (as of 2024-08-04). + +* [x] Improve xandr handling. ## Usability @@ -297,8 +297,6 @@ function kvmx_spice { SPICEPID="$!" echo "$SPICEPID" > $SPICEFILE - echo $spicestring - # Fix window title and position if which /usr/bin/xdotool &> /dev/null && [ ! -z "$spicestring" ]; then local spicewait="0" @@ -2343,36 +2341,40 @@ function kvmx_xrandr { # Set screen resolution depending on which screen the spice session is currently located local id="`xdotool search --name $VM`" - # XrandR approach, matches the full screen size, not ideal when using - # multiple monitors/outputs or if the window size is smaller than the - # current screen size - #local screen="`xdotool getwindowgeometry $id | grep screen: | cut -d '(' -f 2 | cut -d : -f 2 | cut -d ')' -f 1 | sed -e 's/ //'`" - #local mode="`xrandr | grep "Screen ${screen}:" | cut -d , -f 2 | sed -e 's/ current //' -e 's/ //g' | tr 'x' ' '`" + if [ ! -z "$id" ]; then + # XrandR approach, matches the full screen size, not ideal when using + # multiple monitors/outputs or if the window size is smaller than the + # current screen size + #local screen="`xdotool getwindowgeometry $id | grep screen: | cut -d '(' -f 2 | cut -d : -f 2 | cut -d ')' -f 1 | sed -e 's/ //'`" + #local mode="`xrandr | grep "Screen ${screen}:" | cut -d , -f 2 | sed -e 's/ current //' -e 's/ //g' | tr 'x' ' '`" - # Pure xdotool approach, matches the current window size - # Better support for multiple monitors/outputs and for windows of arbitrary sizes - local mode="`xdotool getwindowgeometry $id | grep -i geometry: | cut -d : -f 2 | tr 'x' ' '`" + # Pure xdotool approach, matches the current window size + # Better support for multiple monitors/outputs and for windows of arbitrary sizes + local mode="`xdotool getwindowgeometry $id | grep -i geometry: | cut -d : -f 2 | tr 'x' ' '`" - if [ ! -z "$resolution_y_offset" ]; then - local x="`echo $mode | awk '{ print $1 }'`" - local y="`echo $mode | awk '{ print $2 }'`" + if [ ! -z "$resolution_y_offset" ]; then + local x="`echo $mode | awk '{ print $1 }'`" + local y="`echo $mode | awk '{ print $2 }'`" - mode="$x $(($y $resolution_y_offset))" + mode="$x $(($y $resolution_y_offset))" + fi fi fi - if [ -z "$xrandr_device" ]; then - xrandr_device="Virtual-0" - fi + if [ ! -z "$id" ]; then + if [ -z "$xrandr_device" ]; then + xrandr_device="Virtual-0" + fi - local line="`cvt $mode | tail -1 | sed -e 's/^Modeline//'`" - local name="`echo $line | awk '{ print $1 }'`" + local line="`cvt $mode | tail -1 | sed -e 's/^Modeline//'`" + local name="`echo $line | awk '{ print $1 }'`" - echo "Setting Modeline $line..." + echo "Setting Modeline $line..." - echo DISPLAY=:0 xrandr --newmode $line | kvmx_ssh - echo DISPLAY=:0 xrandr --addmode $xrandr_device $name | kvmx_ssh - echo DISPLAY=:0 xrandr --output $xrandr_device --mode $name | kvmx_ssh + echo DISPLAY=:0 xrandr --newmode $line | kvmx_ssh + echo DISPLAY=:0 xrandr --addmode $xrandr_device $name | kvmx_ssh + echo DISPLAY=:0 xrandr --output $xrandr_device --mode $name | kvmx_ssh + fi fi } |