Using xrandr to ensure that your rdesktop session will always be 90% of the smallest screen

rdesktop is an open source client for Windows NT Terminal Server and Windows 2000 & 2003 Terminal Services, capable of natively speaking Remote Desktop Protocol (RDP) in order to present the user’s NT desktop. Unlike Citrix ICA, no server extensions are required” at least according to yum info rdesktop.

I’ve been using it for years to connect to windows servers and pc’s. So useful is it that I use a version of the script below to automate the connections. The first line allows me to create a symlink in my ~/bin directory to the rdesktop.bash file, such that the name of the symlink itself is used as the server name.

I was using a -g of 90% which works out to having a remote desktop that fits nicely on whatever computer I happen to be using.
-g Desktop geometry (WxH). If geometry is the special word "workarea", the geometry will be fetched from the extended window manager hints property _NET_WORKAREA, from the root window. The geometry can also be specified as a percentage of the whole screen, e.g. "-g 80%".

However for the last while I have been using a dual monitor and this presented me with an issue as the 90% value gives me a screen spanning 90% of the combined area of both monitors. This is not what I want and so I have been overriding the setting with rdesktop.bash -g 800x600. This is less than ideal̀‡ as I need to calculate the values based on the systems I was working at.

Today I used the magic of xrandr to give me the horizontal and vertical sizes of the smallest screen and then used bc to calculate what 90% of the smallest screen is.

Pretty it aint but you might find the idea useful.

#!/bin/bash
SERVER=`basename $0`
h=$(echo "scale=0;(($(xrandr | grep " connected " |  awk '{print $3}' | awk -F '+' '{print $1}' | awk -F 'x' '{print $1}' | sort -n | head -1 )/100)*90)" | bc)
v=$(echo "scale=0;(($(xrandr | grep " connected " |  awk '{print $3}' | awk -F '+' '{print $1}' | awk -F 'x' '{print $2}' | sort -n | head -1 )/100)*90)" | bc)
SIZE=${h}x${v}
PASSWORD='-p mypassword'
USERNAME="myusername"
for var in "$@"
do
    varparam=$(echo ${var}|awk -F '=' '{print $1}')
    if [ "${varparam}" == "-g" ];then 
      SIZE=$(echo ${var}|awk -F '=' '{print $2}')
      shift
    fi
done
rdesktop -d workgroup -u ${USERNAME} ${PASSWORD} -g ${SIZE} ${SERVER} -T "${SERVER}" -r disk:mypc=/ $1 -k en-us&
This entry was posted in General. Bookmark the permalink.

1 Response to Using xrandr to ensure that your rdesktop session will always be 90% of the smallest screen

  1. Lee Ball says:

    Thanks for this, it doesn’t quite work for me in it’s current format, however it’s enough for me to be getting on with.

    Unless I missed something, I was getting two lines output from the xrandr commands, one with primary and the second line with the resolution.

    I presumed that’s what the head -1 was supposed to limit, but rather then do that, I added a pipe to grep -v “primary” which removes the first line.

    I’ve not finished with it yet, but it’s certainly something for me to get my teeth into, thanks for the suggestion.

Leave a Reply

Your email address will not be published. Required fields are marked *