xrandr and the X Window System
For those of us who have traveled outside of the world of Microsoft Windows and into UNIX-like operating systems, we should already be somewhat familiar with the X Window System. Some of us even understand its full potential and use it in ways that most have never dreamed of. Through this very environment, it was the first “remote desktop” I became familiar with and before the concept flooded into the mainstream. I spent a lot of time learning about and playing with the whole X Server/X Client interface across multiple nodes within a network. Through this environment I understood what it was like to have multiple desktops running multiple tasks in each while still be able to easily toggle and manage them all. Through this environment I learned that it is a blessing to have the ability to choose whatever desktop environment strike me as the most efficient for my needs; desktop environments such as GNOME, KDE, Xfce, etc. What I enjoy the most of the X Window System though is the ability to tune it exactly to my liking. A wealth of tools exists to define the display resolution apart from the EDID information that was read from the CRT/LCD panel; to rotate, resize, mirror and span the desktop environment; and many more. What else can I say except for the fact that X is great.
Over the years, I have grown really fond of one specific command line utility and that is xrandr. Taken from the manual page:
Xrandr is used to set the size, orientation and/or reflection of the outputs of the screen. It can also set the screen size. |
When you type xrandr in the terminal (only when the X server is loaded) with no arguments you will get a similar output displaying all of the host’s video ports and if connected, additional display information:
VGA disconnected (normal left inverted right x axis y axis) |
Notice how the output generated displays a list of supported orientation options followed by another list of supported display resolutions which are read from the panel’s EDID information. Right now, the display is set to 1280×800 @ 60 Hz which is also the LVDS (laptop LCD) panel’s native resolution.
It becomes useful knowing this in those situations where you might want to manually adjust your display or quickly automate something for when you need it. Such as spanning across multiple display monitors to even mirroring an image across those same set of monitors. It becomes extremely beneficial when you need to hook up to a projector for a presentation. I know how frustrating it can be when you attempt to press the Fn + <VGA> hotkeys and then realize that the laptop was designed around Microsoft Windows and that Windows was tuned to respond to those keys. Understanding xrandr can fix that.
But let us first start with the basics. To change a display resolution, the command is simple. Just specify the output and the mode:
xrandr --output LVDS --mode 1024x768 |
Let us say we want to turn off one port and enable the display on another (be careful when you turn off a port because if the one you are trying to enable fails, it would be difficult to recover when your primary port is disabled):
xrandr --output VGA --mode 1024x768 --output LVDS --off |
If we want to mirror the same image output onto two different displays:
xrandr --output LVDS --mode 1024x768 --output VGA --mode 1024x768 |
Note that it would be most appropriate to pull up xrandr with no arguments and make sure that the display resolution that you are attempting to mirror is supported by both connected panels.
Spanning a display can be accomplished in the following way:
xrandr --output LVDS --mode 1024x768 --output VGA --mode 1024x768 --right-of LVDS |
It is that simple. Now set up some automated bash shell scripts to do a little error checking and recover from unwanted scenarios when needed and you are good to go. It may even help by separating some of the xrandr functions to help problem detection even more. Have one xrandr function enable an output and have a second disable another. That way you can make sure that one returned appropriately before initiating the next. You can even further the use of this script by assigning a hot key sequence to execute it. For example, in GNOME you can set it in the Configuration Editor. Again, thank goodness for the flexibility of X.

The bane of X Windows systems (IMHO) is static configuration file xorg.conf. When trying to setup multi-head desktop, one has to go back and add Virtual (x x y – resolution of Monitor A, y x Y – resolution of Monitor B) so that the display can span multiple monitors.
Until then, xrandr will force me to use an additional step to get multiple monitors setup as one large desktop.
Sorry the line should read: one has to go back and add “Virtual x+X y+Y” under SubSection “Display” (x x y – ….)
@Kanwar: It is a shame that you have to do that I know. Apart from that, I find xrandr always works perfectly for me. Why can’t they sort this one little thing out? >=( (couldn’t they just make xrandr add that line in for you or something?)
You may also be interested in this article about automatic xrandr display setup on X start: http://linux-tipps.blogspot.com/2009/03/automatically-switch-to-connected.html