Hooray for XRandR

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:

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:

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

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.