Switching Displays via Keyboard Shortcuts

When I’m at my desk I use an external LCD monitor with my netbook. I’m glad that switching displays finally works on Linux, but even on Ubuntu it takes a lot of clicks in the Monitors menu. Fortunately, I found a way to map this to keyboard shortcuts.

The following worked on my Eee PC 1000HE running Ubuntu Lucid but may work on other systems, too.

First of all, attach the external display and turn it on. Then run the xrandr tool without command line arguments:

$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 4096 x 4096
VGA1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080      60.0*+
   1600x1200      60.0
   1680x1050      60.0
   1280x1024      60.0
   1440x900       59.9
   1280x960       60.0
   1280x800       59.8
   1024x768       60.0
   800x600        60.3     56.2
   640x480        60.0
LVDS1 connected 1024x600+1920+0 (normal left inverted right x axis y axis) 220mm x 129mm
   1024x600       60.0*+
   640x480        59.9

The output on my system indicates that there are two displays: The external VGA1 display and the internal laptop screen, LVDS1. To enable both displays, I use the following command (the laptop display is positioned left of the external one):

$ xrandr --output LVDS1 --auto --left-of VGA1 --auto

To enable the external monitor only:

$ xrandr --output VGA1 --auto --output LVDS1 --off

And finally to switch back to the internal display:

$ xrandr --output LVDS1 --auto --output VGA1 --off

On my Gnome desktop, I assigned some of these configurations to keyboard shortcuts via the System > Preferences > Keyboard shortcuts menu. Just click Add to create a custom command which consists of a name and the shell command to run. Then record a shortcut to the new command and you’re done.

This entry was posted in linux and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s