Two heads are better than one

Jul 1, 2009 • alan


At work, I got a new PC with two monitors, and I have really enjoyed having the extra screen real estate.

When I worked from home this week, I decided that I needed to try hooking an external monitor to my HP laptop. I was happy that, unlike the last time I tried this a few years ago, it “Just Worked” ™ without any special calesthenics on my part.

I wondered why Gnome decided to put the panels (the bars at the top and the bottom) on the external monitor instead of on the laptop display. To me, it seemed more natural to have the “start” menu (actually, the “Applications, Places, System” tri-menu) on the external display instead of right in front of me.

It turns out that this is really easy to fix. Gnome has this configuration tool that is roughly equivalent to the Windows registry… yuck. You can access it using either gconf-editor or gconftool-2. Inside that deep mine of settings, there is one jewel that tells where the panels should go. So I wrote a quick script to move the panels from one monitor to the other and back.

#!/bin/bash

m=$1
if [[ ( ! -z "$m" ) && ( ( $m -eq 1 ) || ( $m -eq 0 ) ) ]]
then
   menu="/apps/panel/toplevels"
   panels=$(gconftool-2 --dump $menu | \
      grep '<key>.*/monitor</key>' | \
      sed -e 's/^.*<key>//g' -e 's/</key>.*$//g')
   for p in $panels
   do
      gconftool-2 --set "$menu/$p" --type integer "$m"
   done
else
   echo "usage --> $0 [ 0 | 1 ]"
   echo "moves gnome panels to monitor 0 (VGA) or 1 (LCD)"
fi
exit 0