Controlling monitors & video projectors with RandR

Dual Image


The RandR X server extension gives users more intuitive control over video projectors and multi-head installations.

By Daniel Gultsch

Anneke Schrama, 123RF

Not so long ago, a speaker had to worry whether the video projector on site would support Linux. In many cases, projectors and other presentation equipment had limited Linux support, and the ensuing issues sometimes led to nerve-wracking and time-consuming reboots until the X server finally conjured up an image on the big screen. Conference organizers now typically ask speakers to determine in advance whether the video projector controls work with Linux, which has put an end to some of the last-minute train wrecks. But even if you don't speak at big events, you probably have experienced occasional difficulties when configuring your display settings.

Many Linux users breathed a sigh of relief when the RandR ("X Resize and Rotate" [1]) X server extension put an end to many of the most common display configuration issues. RandR easily allows you to resize and rotate (including support for the pivot function offered by many displays or tablet PCs). Additionally, it includes advanced features; for example, RandR can support multiple displays on a single computer, and it can do this either in clone mode or as a desktop extension.

Drivers

Whether RandR will work on your system or not depends on your graphics card driver support. The manufacturers of the most popular and widespread closed source drivers, nVidia and AMD/ATI, refuse to support RandR. Instead, they prefer to offer their own RandR-incompatible solutions. However, the free X.org drivers intel, radeon (for ATI boards), and nv (for nVidia graphics adapters) have now reached a stage at which they are suitable for production use. However, if you prefer to use proprietary drivers - because you need 3D support, for example - the best idea is to install both driver variants and toggle between them, depending on the application.

Everything Under Control

Various front ends are available for controlling RandR. The simplest front end - and the one that supports all of RandR's features [2] - is the xrandr command-line program. Most distributions install xrandr out of the box. Where this is not the case, the tool is available from a repository and is installed easily via the package manager. After installing, you can use xrandr straight away. The following command:

$ xrandr --query

outputs your graphics adapter's output status. This report provides details about the output ports you are using (DVI, VGA, HDMI, or LVDS), as well as what resolutions the output devices support. The xrandr output highlights the resolution and refresh rate with an asterisk; the plus sign points to the native resolution (Figure 1).

Figure 1: The "xrandr - -query" command reveals the details of the displays attached to your system.

To gain a feeling for RandR, temporarily change the display resolution by entering:

$ xrandr --output LVDS --mode 800x600

You need to replace LVDS with the connected port revealed by xrandr - -query and change 800x600 to one of the resolutions listed as available for your system.

To revert to the previous resolution, you can either repeat the command line, replacing 800x600 with your previous resolution, or you can use the following command:

xrandr --output LVDS --auto

This command resets the display to its native resolution and refresh rate. Use the following command to set the refresh rate

$ xrandr --output LVDS --rate 60

where, again, 60 must be a refresh rate available for your system.

Connecting a Projector

RandR connects a video projector to your computer so that the projector displays the same image as your monitor. You don't even need to restart the X server. This feature also works with normal displays or TVs. Connect the video projector to your DVI or VGA port and run xrandr - -query again. You should see both output devices listed as connected.

To allow clone mode to work properly, you need to find a resolution that both devices support. For a video projector, the typical resolution will be 1024x768, or maybe just 800x600. These settings might distort the display on a 16:10 notebook, but your audience won't notice! The following command

$ xrandr --output VGA --mode 102
4x768 --same-as LVDS --output LV
DS --mode 1024x768

sets the VGA and LVDS outputs to clone mode with a resolution of 1024x768. To switch off the video projector, enter:

$ xrandr --output VGA --off
$ xrandr --output LVDS --auto

Similar commands also let you disable the internal display and just use an external display:

xrandr --output LVDS --off --out
put VGA --auto

As you have probably already noticed, each of these commands starts with an - -output parameter, followed by further (optional) parameters. You can split the last of these commands into two separate commands:

$ xrandr --output LVDS --off
$ xrandr --output VGA --auto

The first command gives you a blank screen, forcing you to enter the second command without seeing what you are entering, which is why XRandR lets you combine command lines.

Multi-Head

RandR replaces most legacy options for combining multiple displays, such as TwinView, MergedFB, and more prominently, Xinerama. What RandR actually does is combine two displays to give you a single large display. For example, RandR will combine two displays with a resolution of 1280x1024 to give you a large screen with 2560x1024 pixels. If the vertical resolutions of the two displays are different, RandR will select the larger of the two when determining the vertical resolution of the virtual display. This approach creates an invisible area below the bottom edge of the smaller of the two displays (Figure 2).

Figure 2: RandR combining two displays of different sizes to create a single virtual display. An invisible area is underneath the smaller of the two displays.

A - -query to XRandR tells you the minimum, current, and maximum resolutions that the virtual display supports. Depending on your distribution, the maximum resolution might be too small to run two monitors at full resolution. If so, you can correct the value then restart the X server. To do this, take the highest summed value for the resolution of the two displays and add a line to your /etc/X11/xorg.conf file "Display" subsection, such as Virtual 2560 1024. After setting the maximum size of the virtual display and running xrandr - -query to make sure that the mode is available, use the following command to link the two displays

$ xrandr --output LVDS --auto --
left-of VGA --output VGA --auto

replacing LVDS and VGA with your physical output ports - for example, HDMI-1, HDMI-2, DVI, or VGA. If the first of the two displays listed (LVDS in this example) is located on the right physically, replace --left-of with --right-of, or change the order of the ports in the command. Instead of --auto for native resolution, add a - -mode option to specify a different resolution.

RandR and Windows

If you fear that a large virtual display will stretch your windows (or the kicker) over two screens, fear not. The window manager (KWin for KDE, Metacity for Gnome) prevents this behavior. RandR uses the Xinerama protocol to tell the window manager where the borders of the physical displays are located within the virtual display. What the window manager actually does with this information depends on your current configuration.

The desktop, including the wallpaper, will normally cover both screens, and you can move windows between the two displays. If you maximize a window, it will be restricted to the size of one of the displays (Figure 3). The kicker also appears on just one of the two screens - in many cases you can't specify which one. The developers need to put some more work into this issue.

Figure 3: The window manager controls how windows are maximized and where the kicker appears.

Rotation

If you use a single-head display that you can pivot through 90 degrees, the following command will rotate the output:

$ xrandr --output LVDS --rotate
left

This command also works on tablet PCs or similar devices (Figure 4). Note that the vertical resolution of the virtual display must match the horizontal resolution of the monitor and vice versa.

Figure 4: Rotating a display through 90 degrees gives you a better overview, especially when surfing the web.

Conclusion

The X RandR extension gives Linux users better control over projectors and multi-headed installations, and the simple xrandr command-line tool offers a convenient interface for managing the RandR configuration. Although many proprietary drivers still don't support RandR, the RandR option works well with free X.org drivers for Intel, ATI, and nVidia graphics cards.

INFO
[1] RandR basics: http://keithp.com/~keithp/talks/randr/
[2] XRandR: http://www.x.org/wiki/Projects/XRandR