Automatically Configuring Multiple Heads with x.org

| Comments

I just upgraded to a (way too) shiny HP Pavilion dv8t laptop and a pair of inexpensive Sceptre 1080p LCD panels. The laptop seems to work pretty well with Linux. I'm running Ubuntu 9.10 with a 2.6.34-rc1 kernel, before the laptop got here I read that the latest kernels have better support for Turbo Boost. I don't know for sure if the kernel is helping me, but nearly every piece of hardware is working fine without any tweaking. So far I am unable to control bass/treble (the sub woofer makes it pretty loud this way), it does not report how fast the battery is being drained, and I'm unable to connect to my 802.11a access point.

These Sceptre LCD panels are WAY too red. I read warnings in the comments on Newegg before I bought them but I figured they couldn't be that bad. They are. Reds and oranges are quite bright. I've tried to tone them down and I'm not very happy with any of my results. I got exactly what I paid for.

What is All This Really About?

Enough about the new hardware! My goal was to be able to plug the laptop into the monitors and have everything just work without any manual intervention. If the two Sceptres are plugged in, I want the desktop to automatically expand across them and shut off the laptop display. When they're unplugged I want it to revert to the laptop display.

Using Two Monitors with an Nvidia Card

I started with the open source driver and xrandr. Using the VGA port was not a problem. For some reason, the open source driver was unable to detect when a device was plugged into the HDMI port. The proprietary Nvidia drivers did not have this problem. My hardware is able to drive any two out of the three displays. Unfortunately, it is not even able to use the third as a mirror of one of the other two.

Controlling the Outputs from the Command Line

I found an application called disper that makes it very easy to control the active outputs from the command line. First I used the nvidia-settings application to set up the two external displays the way I wanted them. Then I exported the settings with disper:

1
disper --export > ~/.disper-sceptre

Then I used nvidia-settings to set up the single laptop display and ran:

1
disper --export > ~/.disper-single

disper can list the displays that are connected:

1
2
3
4
5
6
7
wonko@zaphod:~$ disper --list
display DFP-0: CMO
 resolutions: 320x175, 320x200, 360x200, 320x240, 400x300, 416x312, 512x384, 640x350, 576x432, 640x400, 680x384, 720x400, 640x480, 720x450, 640x512, 700x525, 800x512, 840x525, 800x600, 960x540, 832x624, 960x600, 896x672, 928x696, 960x720, 1024x768, 1152x864, 1360x768, 1280x960, 1440x900, 1280x1024, 1400x1050, 1600x1024, 1680x1050, 1920x1080
display CRT-0: Sceptre X226W-1920
 resolutions: 320x240, 400x300, 512x384, 680x384, 640x480, 720x450, 700x525, 840x525, 800x600, 960x540, 832x624, 960x600, 1024x768, 1152x864, 1360x768, 1280x960, 1440x900, 1280x1024, 1400x1050, 1680x1050, 1920x1080
display DFP-1: Sceptre X226W-1920
 resolutions: 320x175, 320x200, 360x200, 320x240, 400x300, 416x312, 512x384, 640x350, 576x432, 640x400, 680x384, 720x400, 640x480, 720x450, 640x512, 700x525, 800x512, 840x525, 800x600, 960x540, 832x624, 960x600, 896x672, 928x696, 960x720, 1024x768, 1152x864, 1360x768, 1280x960, 1440x900, 1280x1024, 1400x1050, 1600x1024, 1680x1050, 1920x1080

I wrote a short daemon-style shell script that periodically checks the connected displays and passes the correct settings to disper:

1
2
3
4
5
6
7
8
9
10
11
12
13
#! /bin/bash
sleep 8  # The script crashes my X server if it ran too early

while [ 1 ]; do
  if [ `disper -l | grep -c X226W-1920` == 2 ]; then
    disper -i < ~/.disper-sceptre-dual
  else
    disper -i < ~/.disper-single
    sleep 2;
    xset dpms force on  # laptop display won't wake up without this
  fi
  sleep 10
done

I needed to add the xset dpms force on line or else my display would never wake up on its own. I don't know how specific that is to my hardware.

Xinerama and Xrandr

I don’t see any reason why this couldn't be adapted to work with Xinerama and xrandr. xrandr can easily be used to detect and configure the displays. I know xrandr sometimes caused the screens to briefly go blank on my old laptop when it was detecting displays. That would be a bit problematic…

Comments