home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / gnome-wm < prev    next >
Encoding:
Text File  |  2007-04-10  |  2.9 KB  |  139 lines

  1. #!/bin/sh
  2.  
  3. # The user can specify his prefered WM by setting the WINDOW_MANAGER
  4. # environment variable or setting the
  5. # /desktop/gnome/applications/window_manager/default gconf key.
  6. #
  7. # If this is not set, we search a list of known windowmanagers and use
  8. # the first one that is found in the users's PATH
  9. #
  10.  
  11. # sm-client-id value
  12. SMID=
  13. # default-wm value
  14. DEFWM=
  15.  
  16. #read in the arguments
  17. GET=
  18. for n in "$@" ; do
  19.   case "$GET" in
  20.     smid)
  21.       SMID=$n
  22.       GET=
  23.       ;;
  24.     defwm)
  25.       DEFWM=$n
  26.       GET=
  27.       ;;
  28.     *)
  29.       case "$n" in
  30.         --sm-client-id)
  31.           GET=smid
  32.           ;;
  33.         --default-wm)
  34.           GET=defwm
  35.           ;;
  36.       esac
  37.       ;;
  38.   esac
  39. done
  40.  
  41. # Get previously set window manager in gconf
  42. if [ ! "$DEFWM" ]; then
  43.   DEFWM=`gconftool-2 -g /desktop/gnome/applications/window_manager/default 2>/dev/null`
  44. fi
  45.  
  46. # If not exist, set to metacity.
  47. if [ ! -x "$DEFWM" ]; then
  48.     gconftool-2 -s /desktop/gnome/applications/window_manager/default /usr/bin/metacity --type string
  49.     DEFWM=/usr/bin/metacity
  50. fi
  51.  
  52. # WINDOW_MANAGER overrides all
  53.  
  54. if [ -z "$WINDOW_MANAGER" ] ; then
  55.   # Create a list of window manager we can handle, trying to only use the
  56.   # compositing ones when it makes sense
  57.  
  58.   xdpyinfo 2> /dev/null | grep -q "^ *Composite$" 2> /dev/null
  59.   IS_X_COMPOSITED=$?
  60.  
  61.   KNOWN_WM="sawfish sawmill enlightenment icewm wmaker fvwm2 qvwm fvwm twm kwm"
  62.   if [ $IS_X_COMPOSITED -eq 0 ] ; then
  63.     KNOWN_WM="compiz $KNOWN_WM"
  64.   fi
  65.   # metacity is still the default wm in GNOME
  66.   KNOWN_WM="metacity $KNOWN_WM"
  67.  
  68.   OLDIFS=$IFS
  69.   if [ -z "$DEFWM" -o "x$DEFWM" = "xgnome-wm" ]; then
  70.     for wm in $KNOWN_WM ; do
  71.       IFS=":"
  72.       for dir in $PATH ; do
  73.     if [ -x "$dir/$wm" ] ; then
  74.       WINDOW_MANAGER="$dir/$wm"
  75.           break 2
  76.     fi
  77.       done
  78.       IFS=$OLDIFS
  79.     done
  80.   else
  81.     WINDOW_MANAGER=$DEFWM
  82.   fi
  83.   IFS=$OLDIFS
  84. fi
  85.  
  86. # If no window manager can be found, we default to xterm
  87.  
  88. if [ -z "$WINDOW_MANAGER" ] ; then
  89.   echo "WARNING: No window manager can be found."
  90.   WINDOW_MANAGER=`readlink /etc/alternatives/x-terminal-emulator 2>/dev/null`
  91. fi
  92.  
  93. # Now create options OPT1, OPT2 and OPT3 based on the windowmanager used
  94. OPT1=
  95. OPT2=
  96. OPT3=
  97. if [ ! -z "$SMID" ] ; then
  98.   case `basename $WINDOW_MANAGER` in
  99.     sawfish|sawmill|metacity)
  100.       OPT1=--sm-client-id=$SMID
  101.       ;;
  102.     openbox|enlightenment|e16)
  103.       OPT1=--sm-client-id
  104.       OPT2=$SMID
  105.       ;;
  106.     twm)
  107.       OPT1=-clientId
  108.       OPT2=$SMID
  109.       ;;
  110.     lwm)
  111.       OPT1=-s
  112.       OPT2=$SMID
  113.       ;;
  114.     fvwm)
  115.       OPT1=-i
  116.       OPT2=$SMID
  117.       ;;
  118.     compiz)
  119.       OPT1=--sm-client-id
  120.       OPT2=$SMID
  121.       ;;
  122.     #FIXME: add all other windowmanagers here with their proper options
  123.   esac
  124. fi
  125.  
  126. case `basename $WINDOW_MANAGER` in
  127.   compiz)
  128.     gtk-window-decorator &
  129.     OPT3=gconf
  130.     ;;
  131. esac
  132.  
  133. # Store the selected WM with gconf
  134. gconftool-2 -t string -s /desktop/gnome/applications/window_manager/current "$WINDOW_MANAGER"
  135.  
  136. exec $WINDOW_MANAGER $OPT1 $OPT2 $OPT3
  137.  
  138. echo "ERROR: No window manager could run!"
  139.