Using Autorandr for Undocking Goodness in Linux

[Note: this post has been migrated from its original home at http://rockycode.com/blog/using-autorandr-undocking-goodness/, posted 09 Feb 2011.  It is outdated, but perhaps still useful.]

If you, like me, are sick of having to restart the XServer when you undock/dock your laptop in order to get the display to reconfigure (ok, so I've only undocked once since I installed Linux; still, I was bugged), your days of wo are numbered.

X RandR is a command line tool allowing the XServer to dynamically change the configuration. To save you from writing your own shell script utilizing xrandr, two tools have been created:
  • Disper: http://willem.engen.nl/projects/disper/
  • autorandr: https://github.com/wertarbyte/autorandr
Disclaimer: I am new to Linux, not a seasoned veteran like many of you, so I can't tell you exactly what these tools do, just how I use them. But they work.

In Ubuntu you should already have xrandr installed. Install Disper using the Debian package above (or build it from source, if you'd like). Update: The version above is 0.2.3, which has worked great for me, even in Ubuntu 11.04. The newer disper, 0.3.0, does not work for me. Disper sounds like it is geared towards NVidia cards. While it (or the plain autorandr alone) may work fine for ATI cards, you may want to take a look at this page (http://www.thinkwiki.org/wiki/Script_for_Dynamic_Display_Management_with_fglrx) if you have an ATI card.

Once xrandr and Disper are both in place, download the autorandr script from the link above, and place it where you'd like to run it from. The most documentation I've found for it is within the comments of the script, so read through those. It is suggested on this issue page (https://github.com/wertarbyte/auto-disper/issues/issue/5) to use the auto-disper symlink if you have an NVidia card. The basic usage is:

auto-disper --save <profile_name>

Then to toggle profiles:

auto-disper --change

Again, the comments in the script explain this and a bit more, so read through those. Set up your typical docked display configuration and save that as something like 'docked'. Then do what you need to to set up your typical undocked configuration and save that as something like 'undocked'. The names are arbitrary unless you call them with `--load docked`, which I do not.

Finally, I have added a global keyboard shortcut in gnome so that Shift+Ctrl+F7 calls `auto-disper --change`. I have tried to get the FN+F7 switch display button to work for this (per these instructions: http://www.thinkwiki.org/wiki/Sample_Fn-F7_script), but haven't yet succeeded. The ACPI event is triggered and arbitrary scripts I write are called, but for some reason calling auto-disper in that way still doesn't work.

Update: When saving a profile you may get the error: `could not get scaling for screen CRT-0, reverting to "default"`. Something out there lead me to believe that was irrelevant, but in any case I have thus far ignored it with no noticeable issues.

Using Ubuntu PPA Repositories Behind a Firewall

[Note: this post has been migrated from its original home at http://rockycode.com/blog/using-ubuntu-ppa-repositories-behind-firewall/, posted 24 May 2011.  It is outdated, but perhaps still useful.]

This post describes a quick and dirty way to configure apt-add-repository to use port 80 instead of port 11371.

Ubuntu Personal Package Archives (PPA) are an easy way for developers to make their source packages available to the common user (like myself) through APT, Debian's great package manager. Packages from the default repositories are often out of date, where the developer has published newer versions that may have fixed serious bugs. In order to ensure that the ppa is trusted, an encrypted connection over gpg is used. However, apt by default connects via port 11371, likely to be blocked if you are behind a corporate firewall. When you try to add the ppa you're likely to see the following error:

gpg: requesting key 34EF4A35 from hkp server keyserver.ubuntu.com

?: keyserver.ubuntu.com: Connection refused

gpgkeys: HTTP fetch error 7: couldn't connect: Connection refused

gpg: no valid OpenPGP data found.

gpg: Total number processed: 0

The simplest way I found to configure apt to use port 80 instead of the default was found in this launchpad bug, post #9:
 To make add-apt-repository use port 80 by default, the /usr/share/pyshared/softwareproperties/ppa.py file used by add-apt-repository can be modified to use port 80. Edit the file /usr/share/pyshared/softwareproperties/ppa.py Search for "keyserver.ubuntu.com" Replace it [with] "hkp://keyserver.ubuntu.com:80" and save the file. add-apt-repository should work behind a proxy now.
The downside to a code change, like we're doing here to `ppa.py`, is that a typical upgrade would overwrite our changes. However, according to the thread referenced above, this change has already been made in Ubuntu 11.04 and up.