XRandR – finally, simple monitor configuration for Linux

The most recent Linux distribution releases – Ubuntu 7.10, Fedora 8 and so on – are now shipping with version 1.2 of the XRandR extension for the X server. This allows the user to dynamically change resolutions, refresh rates, and – this is the really impressive thing – switch monitors on and off on the fly. All of this, without ever having to edit xorg.conf, or restart the X server, or reboot. This was one of the major things that the Linux desktop lacked compared to other major operating systems.

Until very recently, using my external monitor with my laptop required several irritating customisations – you can see the details in my earlier post:

  1. To have it switch on, and run in Xinerama mode along with my laptop panel, required fiddling with MetaModes and other fiddly settings of the radeon driver.
  2. To drive it at its native resoution (1440×900) i had to add a custom modeline to xorg.conf (except on Fedora, for some reason).
  3. If the X server originally started without the external monitor attached, then it would have to be restarted to detect the monitor once it was attached. And restarting X means having to log out and lose all my application state.

XRandR 1.2 has removed all three of these irritations. It requires (almost) no preconfiguration, autodetects all resolutions correctly, and detects monitors when they are plugged in without a restart.

Let’s take a brief look at some of what XRandR can do: this is basically what I do with it daily. Note that at the moment graphical tools to control XRandR are still under development and none are really at a releaseable state (in my opinion); but now that the infrastructure exists in the X server and the drivers, tools to control it will come soon. What I use here is the command-line tool, sensibly named xrandr.

Let’s say I boot the computer without the external monitor plugged in. As you would expect, my desktop is automatically set to the native resolution of the laptop panel (in my case, 1024×768). I can see what resolutions and refresh rates are available:

$ xrandr -q
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 2464 x 1024
VGA-0 disconnected (normal left inverted right x axis y axis)
DVI-0 disconnected (normal left inverted right x axis y axis)
LVDS connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768 60.0*+ 60.0
   800x600 60.3
   640x480 59.9
S-video disconnected (normal left inverted right x axis y axis)

This tells me that the only attached monitor is the laptop panel (called LVDS); that it can run at the three different resolutions listed, and at the refresh rates listed next to the resolutions. The “*” indicates the mode that is currently in use, and the “+” indicates which mode is preferred by the monitor.

If i wanted to, I could switch to some other resolution:

$ xrandr --output LVDS --mode 800x600

But that looks horrible, so I switch back to the preferred resolution:

$ xrandr --output LVDS --auto

Now everything’s back to normal. There are various rotation and reflection options as well, but I won’t discuss them because (a) they’re silly, and (b) you can look them up in the man page if you need them.

Here comes the interesting part. Now I plug in my external monitor. Nothing happens immediately; but if I run the query command, there’s some new information:

$ xrandr -q
Screen 0: minimum 320 x 200, current 1024 x 768, maximum 2464 x 1024
VGA-0 connected (normal left inverted right x axis y axis)
   1440x900 59.9 + 75.0 59.9
   1280x1024 75.0 59.9
   1280x960 74.9
   1360x765 59.8
   1152x864 74.8 60.0
   1024x768 75.1 70.1 65.7 60.0
   832x624 74.6
   800x600 72.2 75.0 60.3 56.2
   640x480 75.0 72.8 66.7 60.0
   720x400 70.1
DVI-0 disconnected (normal left inverted right x axis y axis)
LVDS connected 1024x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768 60.0*+ 60.0
   800x600 60.3
   640x480 59.9
S-video disconnected (normal left inverted right x axis y axis)

So I can now see all the modes supported by the external monitor (called VGA-0). I switch the monitor on:

$ xrandr --output VGA-0 --auto

This switches on the monitor in a sort-of clone mode: the output from the laptop panel is duplicated on the external monitor; but because the external monitor is larger, it appears in the top left, and the desktop size expands to the size of the external monitor. (At the moment, GNOME doesn’t handle this too well, and the GNOME panel stays in the same place, meaning that it’s in the middle of what’s visible on the external monitor.) So now I can switch off the laptop panel:

$ xrandr --output LVDS --off

(GNOME handles this correctly and moves the panel.)

Now, if you look at the query output above, you’ll see that the monitor claims that its preferred mode has a refresh rate of 59.9Hz, although it also supports a 75Hz mode at the same resolution. I find the latter mode more friendly on my eyes, so I switch to it:

$ xrandr --output VGA-0 --mode 1440x900 --rate 75.0

I want to use the extra desktop space available on my laptop panel; but by default it would just be cloning the output of the external monitor, which wouldn’t help. So I use another option to position the outputs:

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

This places the panel to the left of the external monitor. There are corresponding --right-of, --above and --below options.

Finally, I want to switch off the external monitor so that I can take my laptop away from the desk:

$ xrandr --output VGA-0 --off

Now I’m back where I started.

This is all very cool, but there are a couple of cautionary notes. The necessary drivers are only included in very recent distro releases (Ubuntu 7.10 and Fedora 8 in particular). Currently only the open-source Intel, Radeon and NV drivers support XRandR 1.2; neither the ATi nor the NVIDIA proprietary drivers support it. For now, you pretty much have to use the command-line tool – though that will change quickly. Finally, you sometimes have to set the Virtual option in xorg.conf to indicate the largest possible size of your desktop – but this is a one-off setting, and I hope that distros will start setting it to a sensible default automatically.

Tags: , , , ,

2 Responses to “XRandR – finally, simple monitor configuration for Linux”

  1. Joe says:

    Hi,

    Nice post you’ve got there, and agreed about how badly-needed xrandr was. I’d like to note a couple of things, firstly, Ubuntu comes with displayconfig (or displayconfig-gtk, depending on your choice of window manager); in my experience I’ve found that this tool works decently and fairly reliable. For some reason though, I prefer to work at the command line, maybe it’s just me.

    The second thing I’d like to point out is one of your closing comments, “I hope that distros will start setting it [the screen size] to a sensible default automatically.” This is kind of dilemma for distro developers, as X cannot support direct rendering on screens that are larger than 2048×2048. In my experience, I’ve found that most of the newer distros tend to use 2048×2048 as the screen size, which is a sort of compromise, considering that going any larger would mean forcing any users who wanted to game or do anything serious with their video cards to manually edit their xorg.conf file. It’s not great, but I guess we’ll just have to live with it.

  2. Hrvoje Vencl says:

    Hello. I have been reading the text above. For some time now I have not been able to turn on the S-video out on my ATI RADEON 9200SE. I just recently installed the Ubuntu 8.10 and I am totally new to the world of Linux. I do not use the FGLRX drivers from ATI (it all stops when I install them) but the drivers that came with the Ubuntu installation. So, can you explain me in a simple way how to turn on the S-video out on my card (it used to work fine under Windows but now with Linux i don’t). If it helps here is the report after typing the xrandr command in terminal:
    hrvoje@hv-desk:~$ xrandr
    Screen 0: minimum 320 x 200, current 1024 x 768, maximum 1680 x 1200
    VGA-0 connected 1024×768+0+0 (normal left inverted right x axis y axis) 310mm x 230mm
    1024×768 85.0*+ 85.0* 85.0 75.1 75.0 70.1 60.0
    1680×1050 60.0
    1600×1024 60.2
    1400×1050 60.0
    1280×1024 60.0 60.0
    1440×900 59.9
    1280×960 60.0
    1360×768 59.8
    1152×864 75.0 75.0 70.0 60.0
    832×624 74.6
    800×600 85.0 85.1 72.2 75.0 60.3
    640×480 85.0 85.0 75.0 72.8 75.0 60.0 59.9
    720×400 85.0
    640×400 85.1
    640×360 70.0
    640×350 85.1
    DVI-0 disconnected (normal left inverted right x axis y axis)
    S-video disconnected (normal left inverted right x axis y axis)

Leave a Reply