External monitors

By | May 1, 2011

When I first started using Linux over a decade ago, dual screen was a pain to set up. When I got my first laptop four years ago, setting up an external monitor was also painful. Then came xrandr and life was good. Now there are nifty little monitor switching GTK apps that allow you to drag screens around just like in Windows or MacOS.

But that’s a lot of fiddling around. For the longest time, my use case has always been either:
a) I am using only my laptop
b) I am using my laptop with my 1920×1080 external monitor connected via VGA (It’s an old laptop)

To accommodate these two use cases, I had connected my “Switch Display” (fn+F7 on my thinkpad) key to the following simple script:

Succinctly, if the external monitor is connected, enable it as “above” my laptop, otherwise, just enable the laptop monitor. All I have to do is plug in or unplug my monitor, hit Fn+F7, and my display would automatically adjust itself.

For the record, I used xbindkeys to connect the button to the script with the following .xbindkeysrc:

This served me well until I bought myself a new television that only operates at 1360×768 on the VGA port. Further, when I’m connecting my laptop to the tv, the television is usually below the laptop monitor rather than above, as my monitor is.

So now, my check_external script looks thusly:

This is Python 3 code, and works delightfully on my Arch Linux running awesome setup. I still have to do custom xrandr commands if I ever connect to someone else’s projector or monitor (this happens so rarely that I don’t think I’ve done it since Archcon last year), but normally I can get away with a quick “xrandr –auto” in those cases, which usually just clones the display. There are dozens of ways to set up monitors, but this works great for me, and I can normally have my display up and running the way I want it with a couple keystrokes.

6 thoughts on “External monitors

  1. PiX

    You should check disper: http://willem.engen.nl/projects/disper/ and auto-disper.

    auto-disper is a script that adds profile management to disper, including auto-detection. So you can have a bunch of setups that are chooser according to the names of the monitors.

  2. roentgen

    In KDE one gets a dialog to configure the external device. Haven’t seen easier than that.

    1. dusty Post author

      Why would I want to go to the trouble of opening a dialog, performing several drag and click sequences inside that dialog, and close it, when I can much more easily press a single key combination and be done with it?

      1. Berseker

        well a normal OS simply could let the user associate a key combination to an action via the same GUI.. but sadly, in 2011 for doing so the user often is asked to learn “alien” language to do the easiest things 😉

  3. Peter

    This is fantastic! Thanks for sharing, I’m going to try this out on my new thinkpad

  4. Aaron Griffin

    The problem that I am still unable to solve is the “Virtual Size” part. You need to manually specify a virtual size large enough to cover both screens in order to use xrandr successfully. This cannot be changed at runtime, and as far as I know, cannot be detected outside of X.


Leave a Reply

Your email address will not be published. Required fields are marked *