#!/bin/sh
PANEL=$1

if [ "$PANEL" = "" ]; then
  echo "syntax is `basename $0` <virtual desktop no>"
  exit 0
fi

if [ -f $HOME/.matchbox/mb-panel-orientation ]; then
  MBORIENT=`cat $HOME/.matchbox/mb-panel-orientation`
else
  MBORIENT=" --size 36 --orientation south --bgpixmap /usr/share/pixmaps/Panelbacks/silver.png"
fi

if [ "`which rox`" = "" ] || [ "`grep ROX=false $HOME/Choices/pdaxii13.conf`" != "" ]; then
  DESKTOP=true
  if [ -f $HOME/.matchbox/mb-desktop-background.$PANEL ]; then
    MBBGND=`cat $HOME/.matchbox/mb-desktop-background.$PANEL`
  else
    MBBGND=`cat $HOME/.matchbox/mb-desktop-background`
  fi
else
  DESKTOP=false
fi

if [ "`ps -ef|grep matchbox-panel|grep \"id $PANEL\"`" != "" ]; then
  echo "panel already running on desktop $PANEL"
else
  #CURRENT=`wmctrl -d|grep '*'|cut -d' ' -f1`
  echo "switching to desktop $PANEL"
  wmctrl -s $PANEL 
  if [ $DESKTOP = "true" ]; then
    matchbox-desktop $MBBGND 2>/dev/null >/dev/null &
  fi
  eval matchbox-panel --id $PANEL --no-flip $MBORIENT 2>/dev/null >/dev/null &
  #wmctrl -s $CURRENT
fi

