Hardware

Manipulate monitor displays easily with the xrandr extension

Vincent Danen explains how to use the xrandr extension, which allows you to adjust resolutions on-the-fly, reposition or rotate screens, and more without once touching the xorg.conf configuration file.

Being able to easily manipulate your monitor display can be very useful, particularly when you have more than one monitor connected to a computer. Being able to easily configure screen placement and rotation, on the command-line, can easily solve GUI problems that perhaps are not solvable using GUI tools.

Recent versions of the X Window System include support for RandR -- the X Resize and Rotate Extension. This protocol includes a set of extensions to the X server to allow for the dynamic changing and reconfiguration of screens. This is something that may not be too common on immobile desktop systems, but may be very common on laptop systems that connect and re-connect to docking stations, or switch between dual monitor and built-in screen configurations.

To determine if your X server has support for RandR, you can easily check the X.org output:

$ grep -i randr /var/log/Xorg.0.log

If RandR is available and enabled, the output will indicate so. To manipulate screens using the RandR protocol, use the xrandr tool.

To determine display properties and connections, use:

$ xrandr -q
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
DVI-I-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080      60.0*+   50.0
...
DVI-D-0 disconnected (normal left inverted right x axis y axis)
VGA-0 disconnected (normal left inverted right x axis y axis)

This will list available resolutions and whether or not a display port is active or not. For instance, the above indicates three video output modes, only one of which is connected (the HDMI and VGA outputs are not connected).

The moment a second monitor is plugged in and turned on, xrandr displays:

$ xrandr -q
Screen 0: minimum 320 x 200, current 3600 x 1080, maximum 8192 x 8192
DVI-I-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080      60.0*+   50.0
...
DVI-D-0 disconnected (normal left inverted right x axis y axis)
VGA-0 connected 1680x1050+1920+0 (normal left inverted right x axis y axis) 434mm x 270mm
   1680x1050      60.0*+
...

Unfortunately, the new monitor is physically positioned to the left of the pre-existing monitor but is not reflected by the screen layout. With xrandr, this is easy to fix:

$ xrandr --auto --output VGA-0 --left-of DVI-I-0

Instantly the screen configuration changes and the placement is correct. With some distributions you may need to re-execute this command each time you re-start X; with Fedora 12 at least, this is not required. The monitors may be reversed at the gdm login screen, but once you log in, your xrandr preferences will be restored.

The nice thing about xrandr is you can adjust resolutions on-the-fly, reposition or rotate screens on-the-fly, and more. These changes can all be accomplished without once touching the xorg.conf configuration file.

Get the PDF version of this file here.

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

0 comments

Editor's Picks