Changing VNC Session’s Geometry on the fly

By Yashwant
In howto
Jun 29th, 2012
1 Comment

vncA lot of developers in IT industry including me use VNC sessions to work on our remote machines. One thing which was kind of irritating for me was the size and resolution of VNC session. While working in office we use the bigger displays provided to each of us and from home if we need to connect we use our laptops. Laptop screens are much smaller as compared to the monitors we have in office. So if we keep the VNC session resolution according to office monitors, we get scroll bars on laptops and if we keep it according to laptop size we waste a lot of space on office monitors. It is advisable to keep the resolution as higher as possible as it helps while working with IDEs.

One solution to this issue was to keep two separate sessions for office and home for eg :2 for office and :3 for home with suitable resolutions. It makes sense when you don’t need to continue the work from office to home or viceversa. Suppose you are debugging a flow in office and want to continue the same from home, it would be painful to setup IDE, debug points and other environment settings again in the new vnc session. It would be awesome if we could change the vnc session resolution/size on the fly.  I will explain procedure for the same in this post.

We can use a utility called xrandr to reset vnc session size/resolution on the fly. Let’s have a look how to use it. Open the terminal and enter following command

$ xrandr

Sample Output

Screen 0: minimum 640 x 480, current 1640 x 970, maximum 1920 x 1200

default connected 1640×970+0+0 0mm x 0mm

1920×1200      60.0

1920×1080      60.0

1400×1050      60.0

1360×768       60.0

1280×1024      60.0

1280×960       60.0

1280×800       60.0

1280×720       60.0

1024×768       60.0

800×600        60.0

640×480        60.0

1640×970       60.0*

In above output * shows the current resolution. Output will differ on different machines. As per my trials, I have found that 1640×970 works good on my desktop monitor and 1370×830 works nicely on my laptop. (It might differ depending upon your screen size). If you want to try from available sizes, simply use following command with one of the available sizes from above output.

$ xrandr -s 1360×768

You will see the size getting updated instantly. Above command works only with default available modes. It won’t work with custom size directly. The available size option might not be best according to our needs so lets try to add a new custom size which matches our requirements. We will create a new size 1370×830.

Run following command

$ cvt 1370 830

Sample Output

# 1370×830 59.83 Hz (CVT) hsync: 51.58 kHz; pclk: 93.25 MHz

Modeline “1376x830_60.00”   93.25  1376 1456 1592 1808  830 833 843 862 -hsync +vsync

Now we need to create a new modeline

$ xrandr -newmode modeline

Value of modeline can be copied from output of previous command

$ xrandr –newmode “1370x830_60.00”   93.25  1376 1456 1592 1808  830 833 843 862 -hsync +vsync

Now add this newly create mode

$ xrandr -addmode default 1370x830_60.00

(First parameter is name of display which we got from output of xrandr command initially. Second is name of mode which we are adding which we can get from modeline)

Now use this mode for your display

$ xrandr –output default –mode 1370x830_60.00

After running above commands your vnc session would have been resized but this is temporary. Now we need to make it permanent.

Edit Default file

$ sudo vi /etc/gdm/Init/Default

Search for following lines



Add following lines after above lines

xrandr –newmode “1370x830_60.00”   93.25  1376 1456 1592 1808  830 833 843 862 -hsync +vsync

xrandr –addmode default 1370x830_60.00

randr –output default –mode 1370x830_60.00

Save and Exit

Now you are done. You can follow the same steps to create any other size according to your displays.

Next time whenever you open your vnc session from any machine, you can reset the size with just one command.

$ xrandr -s 1370x830_60.00

You can replace 1370x830_60.00 with name of other modes you created.

I hope this will help in improving productivity while working from different machines.

About the Author

- An avid reader and a big time comics fan. A software engineer by profession who loves writing code and make things work.

One Response to “Changing VNC Session’s Geometry on the fly”

  1. Krishna Prasad says:

    What is the version of Xrandr that you are using?
    The 1.3 doesnt support addmode / newmode.
    Only one custom size can be provided while creating vncserver session.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

facebook comments: