9 Jun 2009 federico   » (Master)

Tue 2009/Jun/09

  • RANDR and suspending laptops

    Consider this scenario:

    1. You plug an external monitor to your laptop.
    2. You disable the laptop's LCD, enable the external monitor, and close the laptop's lid to work.
    3. You suspend your laptop, unplug the monitor, and take the laptop home.
    4. You open your laptop.

    Until yesterday, you ended up with a black screen, as nothing ever detected that you had unplugged the only active monitor. Fixing this was a bit fun.

    First, the X server needed to re-probe the video outputs when the laptop comes back from suspend. X then sees if the monitors have changed. If so, it sends out the corresponding RANDR events to clients.

    On the GNOME side, gnome-settings-daemon is responsible for handling RANDR events. X just says, "the monitors changed; now do something about that". Gnome-settings-daemon sees if it needs to enable certain video outputs if they got connected, or disable the ones that got disconnected. In the end all of gnome-desktop, gnome-settings-daemon, and gnome-control-center needed changes for this. The randr-hotplug branches for those modules are now merged into master.

    Like many things in X, the RANDR machinery maintains a few timestamps that it uses to avoid race conditions. An X client is not allowed to change the RANDR configuration if its view of the world is out of date — for example, if monitors have been plugged or unplugged since the last time that the X client queried the state of the monitors.

    Also, you can use those timestamps to distinguish between RANDR events that get generated when *you* change the RANDR configuration, from those that happen due to the user plugging/unplugging things. Gnome-settings-daemon uses the RANDR timestamps for that purpose.

    It turns out that X was maintaining the RANDR timestamps incorrectly. Keith kindly fixed this.

    Little bugs have been surfacing from all of this. The Intel video driver didn't detect VGA outputs correctly. XRRSelectInput() doesn't work as advertised. RANDR notifications are probably broken for X clients with byte ordering different from the server's.

    The most important part of this is that gnome-settings-daemon now absolutely requires an X server with the fixes for the RANDR timestamps. Unfortunately, I don't know of a way at runtime to detect whether this is the case. If you have a buggy X server, you'll get lots of RANDR weirdness.

    On the good side, all of this also means that GNOME is ready to receive hotplug events from X whenever that is actually made to work. In the ideal case, you should not need to tell your machine that a monitor got plugged or unplugged; it will just detect it and do the right thing.

Syndicated 2009-06-09 12:21:00 from Federico Mena-Quintero - Activity Log

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!