Contact Us

If you are interested in our services leave your contact details below and our sales representatives will contact you.

The organization which you represent
Email address we will use to contact you
Longer contact form…
 
  • About

    mFabrik Blog is about mobile and web software development, open source and Linux. We tell exciting tales where business, technology, web and mobile convergence.

    Creative Commons License
    This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Autoconfiguring dual monitors on Ubuntu

Posted on July 14, 2009  by Mikko Ohtamaa
Filed Under technology, ubuntu

The following shell script is a helper script for laptop users who connect an external monitor now and then to their laptop. Since Ubuntu does not provide clever ways to arrange desktop or detect connected displays, you need to run the script from terminal when you change your monitor configuration.

  • detect the numbers of monitors you have attached
  • Activate the second (external) monitor if there are two monitors
  • Use the external monitory as the primary display, otherwise use internal display as a primary display
  • Move your taskbars to the primary display

It is based on disper tool by Willem van Engen. For now (2009), it’s nVidia only. ATI support could be possible.

#!/bin/sh
#
# Detect displays and move panels to the primary display
#
# Copyright 2009 Twinapex Research
#
# Author <mikko.ohtamaa@twinapex.com>
#

# disper command will detect and configure monitors
disper --displays=auto -e

# parse output from disper tool how many displays we have attached
# disper prints 2 lines per displer
lines=`disper -l|wc -l`

display_count=$((lines / 2))

echo $display_count

echo "Detected display count:" $display_count

# Make sure that we move panels to the correct display based
# on the display count
if [ $display_count = 1 ] ; then
   echo "Moving panels to the internal LCD display"
   gconftool-2 \
        --set "/apps/panel/toplevels/bottom_panel_screen0/monitor" \
        --type integer "0"
   gconftool-2 \
        --set "/apps/panel/toplevels/top_panel_screen0/monitor" \
        --type integer "0"
else
   echo "Moving panels to the external display"
   gconftool-2 \
        --set "/apps/panel/toplevels/bottom_panel_screen0/monitor" \
        --type integer "1"
   gconftool-2 \
        --set "/apps/panel/toplevels/top_panel_screen0/monitor" \
        --type integer "1"
fi
 

Other posts by Mikko Ohtamaa

 

Comments

5 Responses to “Autoconfiguring dual monitors on Ubuntu”

  1. wvengen on July 14th, 2009 3:03 pm
    Gravatar

    Thanks! Based on your script it may be a good idea to add this functionality to disper
    http://bugs.launchpad.net/disper/+bug/399257

     
  2. Confluence: Technology on January 24th, 2010 7:48 am
    Gravatar

    Multi Monitor Display Enable…

    The issue Attaching a VGA monitor or projector to the 1201N’s VGA port and then trying to use it via the Nvidia supplied control panel is a disaster. You have to save the new config as root, you have to restart X…….

     
  3. Confluence: Technology on January 24th, 2010 7:57 am
    Gravatar

    VGAOutput…

    The issue Attaching a VGA monitor or projector to the 1201N’s VGA port and then trying to use it via the Nvidia supplied control panel is a disaster. You have to save the new config as root, you have to restart X…….

     
  4. Kenny Schiff on January 25th, 2010 5:38 pm
    Gravatar

    This is brilliant and exactly what I wanted. I have a Lenovo laptop that I use connected to an external LCD via a docking station. I was not using the two displays as it was difficult to properly manage this. Your script solves the problem.

     
  5. ulugeyik on April 8th, 2010 7:12 pm
    Gravatar

    This works great on Asus 1201N for me.

     

Leave a Reply