On The Road with Vicky Lamburn

The murmurings of another voice in the congregation

Output Switcher – Easy Linux Screen Management

with 11 comments

Whew what a productive day.

I’ve written a script to easily switch between LCD, VGA, LCD+VGA Mirror, LCD+VGA Extended Desktop (Dual Screen) on a ThinkPad and other Radeon based laptops; for all systems using Xrandr 1.2 and Xorg 7.3; such as Ubuntu 7.10 Gutsy Gibbon.

It works well and can be bound to the Fn + F7 key combination. It’s not perfect, it’s basic but it does what I need it to do, does it well and it’s minimal. I will develop it further in time with a GUI and complete reconfigurability.

At its simplest, this is the easiest way to make the most of your external VGA screen, easiest way to mirror and the easiest way to to create dual screen setups on a ThinkPad on Ubuntu and Linux. Probably. Well once it’s installed it just sits there and works Read on to find out more…

The inevitable bug reports as comments on this post would be good. As would your feedback. Please be nice :)

Download: OutputSwitcher.zip

Taken from the README

Output Switcher 0.1

Copyright (C) 2007 Victoria J K Lamburn

This script is licensed under GPLv2, see the LICENSE file

INTRODUCTION

This is a simple script (you could easily have written it yourself with some basic scripting knowledge) that switches the output robustly using the new capabilities found in XrandR 1.2 and Xorg 7.3’s hot plugging support.

I’ll admit I’m not the best Bash scripter you will ever see not the geekiest of Linux users (I do maintain interests outside of Computing) but what you have here is something that works. Well I’ve tested it and it does.

FEATURES

The aim of Output Switcher is to be used on a system which can output video to more than one display. In its supplied configuration here is is set up for the ‘radeon’ driver, as it references VGA-0 which might be different on the ‘intel’ and ‘nv’ (nvidia) driver, but you can change this.

If you have a VGA display plugged in, it will cycle through the following screen output settings:

  1. Laptop LCD Only
  2. VGA Only
  3. Laptop LCD + VGA Mirrored
  4. Laptop LCD + VGA displaying Extended Desktop to the right

and then back to (1)

You have to run the script to get it to move on to the next step, there are no command line arguments. So if currently only your VGA display is on (state 2 as per above’s list), the next time you run output.sh it’ll then mirror the desktop on both displays (state 3 on the above list.)

If you unplug the VGA display whilst the LCD is turned off, running the script again will restore the laptop’s LCD display to on regardless of what step you were are at. It is ideal to bind to a keystroke for this reason as you will have to run the script blind without doing this.

The script automatically detects the optimum resolution for the outputs except for when you mirror which should shrink down to the size of the laptop screen.

CONFIGURATION

There is no configuration in this version but you are free to alter the script to specify resolutions, something more advanced, change where the display is extended to, e.g. VGA on the left of the laptop screen etc. Entirely up to you. The supplied configuation here is perfect for my use and most other people with Radeon based laptops, such as the ThinkPad T4x.

If you run your external screen via DVI rather than VGA (such as through a dock) you need to change every instance of VGA-0 to DVI-0.

REQUIREMENTS

Xrandr 1.2 and Xorg 7.3, e.g. Ubuntu 7.10.

You may need to edit this script if you are using an Intel or Nvidia graphics system.

For Radeon users; check your xorg.conf file for:

  1. That you are using the ‘radeon’ open source driver (not ‘ati’ or ‘fglrx’)
  2. That you have specified a Virtual line in the Screen section e.g.

    Section "Screen"
    Identifier "Default Screen"
    Device "ATI Technologies Inc Radeon Mobility M7 LW [Radeon Mob$
    Monitor "Generic Monitor"
    DefaultDepth 24
    SubSection "Display"
    Modes "1024x768"
    Virtual 2304 768
    EndSubSection
    EndSection
    Where the first dimension is the max resolution width of both displays added and the height is the height of the highest vertical resolution out of the two displays. Above is configured for my 1024×768 laptop LCD panel and 1280×768 external VGA display. (i.e. (1024+1280)=2304 768 (as both displays are only 768px tall). For a laptop LCD panel of 1024×768 and an external VGA display of 1680×1050 you would need to enter:

    Virtual 2704 1050Hope this makes sense.

  3. After making the xorg.conf changes, log out or reboot.
  4. Run the script from the command line a few times to see how it cycles through the states 1-4 described in Features.

INSTALLATION

To set up fully with Fn + F7 key binding (that means the script will be called when you press Fn+F7)

  1. Find a suitable place for the script, I put mine in the home folder (/home/vicky/) in my case, giving a full path of /home/vicky/output.sh
  2. Press Alt + F2 and enter: gconf-editor
  3. Press enter to open gconf-editor
  4. Double Click ‘apps’ from the left hand column
  5. Double Click ‘Metacity’ from the list (scroll down)
  6. Click once ‘global_keybindings’ and double click ‘run_command_1′ from the right hand list and enter the value:
    0xd6
  7. Click ‘Ok’ or press enter.
  8. Click once on ‘keybinding_commands’ on the left column, double click ‘command_1′ from the right hand list and enter:gksudo sh <path to>/output.sh
  9. In my case I entered:gksudo sh /home/vicky/output.sh
  10. Click ‘Ok’ or press enter.
  11. Close Gconf-editor
  12. Try it by press Fn + F7 and enter your super user password and watch it work (hopefully)

FUTURE

GUI Configuation options, proper set up script? Intel and Nvidia support out of the box. Configurable DVI/VGA support. Configurable resolutions. Svideo support. Gnome Panel Applet?

Lots of things and too little time :)

CONTACT

If you wish to contact me, my details are:

  • EMail: vicky.lamburn@googlemail.com
  • WWW: http://www.lilserenity.com

Written by lilserenity

October 21, 2007 at 10:36 pm

11 Responses

Subscribe to comments with RSS.

  1. Using T60 with x1400 this did not work. When radeon driver is used, failsafe resolution is used by system and there is no way to change. Still no way to use a projector with Gutsy…

    Robert Heard

    October 26, 2007 at 9:48 pm

  2. Sadly as you’ve found out it won’t :( The Radeon driver doesn’t support the ATI X1400, or many other modern ATI chips, partially due to ATI not releasing until now any hardware specs or open sourcing their drivers. This should change soon and bring either an ATI blessed or open source ATI driver for more modern ATI chips with xrandr 1.2 support which this script relies on.

    If you plug in the projector when you boot the machine, is the display not mirrored by default? Certainly Fn+F7 not working as it should in Gutsy is an issue.

    For others, here is the ThinkWiki entry for the Radeon driver and what is supports:

    http://www.thinkwiki.org/wiki/Radeon

    Which is basically:

    Radeon 7000 (X31, X32 and A30, A30p too as well I think)
    Radeon 7500 (T30, T40, T41, T42)
    Radeon FireGL 7800 (based on R7500) (A31p)
    Radeon 9000 (T40, T41, T42) and Radeon FireGL 9000 (T40p)
    Radeon 9600 (T42, T42p) and Radeon FireGL T2 (T41p, T42p)
    Radeon X300 (T43)
    Radeon X600/FireGL V3200 (T43p)

    Not sure how the R series figures into this.

    Unfortunately the changes made to the video drivers in the Gutsy release have not been as well publicised as they should have been, or even explained.

    I hope you can find some resolution in the meantime with the proprietary driver; wish I could help more at this stage.

    Vicky

    lilserenity

    October 26, 2007 at 10:22 pm

  3. I’ve just upgraded to Kubuntu 7.10 on a T40 with a video adapter lspci reports to be a “Radeon RV250 [Mobility FireGL 9000] (rev 02)”, a 1024×768 internal screen and a 1280×1024 external (Samsung 710N). Your script works perfectly on this hardware. Thank you very much for sharing it!

    D. Michael McFarland

    October 28, 2007 at 7:40 pm

  4. I’m in the same boat as ‘Robert Heard’ above – T60 with x1400, and this problem is driving me crazy. After many, many hours of futzing around with my xorg.conf file under Feisty, I was finally able to get a Big Desktop setting with 1400×1050 on the laptop and 1280×1024 on the external monitor. Now, the best I can do is get mirrored 1280×1024 on both screens.

    I’m really disappointed that ATI hasn’t made these issues more of a priority, but also very disappointed in the displayconfig app; it doesn’t ‘just work,’ and I have yet to do a single thing with it that worked at all. Sheesh, Windows and Mac had this figured out so long ago, why is it still such a challenge in Linux?

    Anyway, thanks for your efforts.

    Aaron

    October 30, 2007 at 3:06 am

  5. D. Michael McFarland,

    Very glad that this is now working for you, sounds like you have a T40p if that’s what lspci is responding but regardless, great news that this works :) I have a lot more ideas in the pipeline but I just might be slower than folks want it to be. I’ll write a post up of what I would like to do soon; eventually anyway! Glad to be of help,

    Vicky

    lilserenity

    October 30, 2007 at 8:16 am

  6. Aaron,

    I couldn’t agree more with you. The only good news is that I believe ATI/AMD have release a preliminary driver (a beta I suppose) that supports xorg 7.3; now I don’t know if the driver also supports xrandr 1.2 but that should mean the latest driver supports hot plugging displays. That said I wouldn’t even try it just yet until it’s been released; especially on a production system.

    I think ATI as you say can only shoulder some of the blame here; I think it’s disappointing that they haven’t been more open in the past with their driver development. On the same count; The Display and Graphics panel in 7.10 has in my experience also been — well akin to a Chocolate Teapot. Of course it is limited by what the driver X is running on but most Linux users would assume something was broken, I did when I reported it as a bug that it wouldn’t work on my Radeon 7500 until i was told it was in fact the driver dropping Xinerama support! Also, as you say you’ve only got to look at how Windows and Mac OS X handle this to see that it can work just like that. Windows’ configuration is a little cumbersome but it does work.

    Mac OS has always been the benchmark for dual screen support since 1991 with System 7 and now Mac OS X as it makes it a doddle. Apple is lucky that they have a closed ecosystem to support but none the less this is just one of the things Linux needs to ‘get right’ before it starts to get any real traction on the desktop.

    I think the major step will be all driver supporting hot plugging provided with xorg 7.3 and supporting xrandr 1.2–I think then we would be very close to the desired goal; of screen management ‘just working.’

    I only wish this work worked on the later Radeons like yours. Now to figure out why Fn+F5 no longer works in Gutsy… *sigh*

    Vicky

    lilserenity

    October 30, 2007 at 8:25 am

  7. After much head scratching and searching for a solution for my intel GMA950 based laptop I stumbled onto your script and I want to say THANK YOU VERY MUCH! This is awesome. I had to change a few things to get it working with the intel driver and compiz, but now it’s 100%.

    Info for others who might try this on an intel based laptop, I changed the following.
    1) in xorg.conf: Virtual 2048 800 (since the intel driver does not support 3D rendering above 2048 on an extended desktop.
    2) Because of “1)” and since my native resolution is 1280×800 I had to alter the script to change the LVDS resolution when using the extended desktop. Like this:

    echo + Mirrored Displays
    echo + Switching to Extended Desktop on VGA

    #Intel driver only support max 2048 3D virtual desktop
    xrandr –output LVDS –mode 1024×768 –pos 0×0
    xrandr –output VGA –right-of LVDS
    The rest stays the same.

    With it set like this my laptop screen resolution changes to 1024×768 when the extended desktop is selected and then reverts back to the default 1280×800 on all other options.

    Thanks again for a very useful script!

    Paul

    December 10, 2007 at 9:04 am

  8. Hi,

    Thanks so much for publishing the script and howto. I now have this all working on my Thinkpad T40 and it has transformed my day to day work life – having the extended screen space. I’m also really glad to be able to confidently use Ubuntu again for presentations to a projector. Thanks again.

    Peter H

    January 10, 2008 at 2:10 pm

  9. Woot! Very nice. I’m typing this on my Thinkpad r51 (http://www.charlescurley.com/Lenovo.R51.html) running Ubuntu 7.10. Your script ran out of the box. I haven’t linked into the keyboard yet, but that should be (ahem) a detail. Thank you!

    I have both emacs and xmutt set to position themselves relative to the right side of the screen once. So once I have the display the way I want it, I can launch them, and they show up in the correct place, on the external display if I’m in state 4, on the right side of the display in any of the other states.

    Charles Curley

    February 17, 2008 at 12:42 am

  10. Hi Vicky,

    This looks great. Don’t suppose I could pester you to post your xorg.conf as well?

    Thanks . . .

    John H Woods

    March 4, 2008 at 7:47 pm

  11. [...] problems: it required root permissions to run, and it has "kludge" written all over it. (Output Switcher – Easy Linux Screen Management « On the Road : Victoria J.K. Lamburn’s Blog) In addition, it required me to manually map Fn-F8 to run the script, which seems to be a problem [...]


Leave a Reply