Hooray for XRandR

Submitted by hrm on 31 March, 2008 - 15:11

For years, it's been a major failing of Linux (and X11 in general) that it's not been possible just to plug in a new monitor and be able to extend your desktop on the fly. This is just about OK for desktop machines, which don't tend to change their configuration very often. It really, really sucks for laptops, though. It's really quite painful (and potentially quite embarrassing) to have to kill X and restart it before you can plug your laptop into a data projector at a conference.

But... X now has a thing called XRandR, that allows you to reconfigure your X display on the fly without restarting anything. I've got a couple of talks coming up shortly, so I thought I'd have a play.

It turns out to be really quite snazzy, although the point-and-drool tooling isn't up to much at the moment. (I tried grandr, but I couldn't get it to do very much).

The tool to use is called xrandr. Just run it without any options to see your current configuration. This will show you the outputs (i.e. what could be connected to a monitor) you have available, and what resolutions they currently understand:

hrm@willow:~$ xrandr
Screen 0: minimum 320 x 200, current 1680 x 1050, maximum 2960 x 1050
VGA disconnected (normal left inverted right)
   1280x800       60.0  
   1280x768       60.0  
   1024x768       60.0  
   800x600        60.3  
   640x480        59.9  
LVDS connected 1680x1050+0+0 (normal left inverted right) 331mm x 207mm
   1680x1050      59.9*+
   1280x800       60.0  
   1280x768       60.0  
   1024x768       60.0  
   800x600        60.3  
   640x480        59.9  
   1280x1024      60.0  
TMDS-1 disconnected (normal left inverted right)
TV disconnected (normal left inverted right)

All well and good... but you can do other, more funky things with it now. For example, plug in an external monitor, and you can stick it to the right of your current screen:

xrandr --output VGA --auto --mode 1280x1024 --right-of LVDS

or resize your main display, and mirror it on the second monitor:

xrandr --addmode LVDS 1280x1024
xrandr --output LVDS --mode 1280x1024
xrandr --output VGA --auto --mode 1280x1024 --same-as LVDS

or... well, there's lots of options. Change the refresh rate, change the DPI settings, move a monitor around on your desktop, reflection, rotation...

The only thing you have to keep an eye on is the size of the available framebuffer. If you get an error about the screen being too small, you will probably need to supply the --fb option to give it an upper bound on the size of the available screen. Or do what I did, and add

Virtual         2960 1050

to the "Display" subsection of the "Screen" section(s) in your xorg.conf file. That tells X how large a framebuffer to allocate for your whole desktop, and will allow you to extend your display across to additional monitors.

Armed with my new-found powers of control over X11, I wrote a script that will flip between the three main configurations I want for my laptop (stand-alone; desktop with extension screen; presentation mode). That's attached at the bottom of this post, if you want to take a look.

AttachmentSize
set-display1.01 KB

No attachment.

Hi, we're just discussing xrandr on #dorset so you post helped quite a bit. Couldn't see any attachment when viewing http://carfax.org.uk/comment/reply/18 though. The RSS feed had an "Enclosure: http://carfax.org.uk/sites/default/files/set-display." and the URL http://carfax.org.uk/sites/default/files/set-display. does work, note the required trailing dot. Cheers, Ralph.

Fixed

Should be fixed now. The trailing dot seems to be a peculiarity of Drupal's upload, I think.