#! /bin/sh
# This script configures swm
  
echon(){
  case x`echo -n` in
  *-n*) echo "$*\c" ;;
  *)    echo -n "$@" ;;
  esac
}

echo "// GENERATED BY configure-swm, do not edit if you don't" > swm.conf
echo "// really know what you are doing." >> swm.conf
echo "sWM configuration script for version 1.3.2"
echo

echo "------------------------------------------------------------------------"
echo 'Would you like to use the minimalistic defaults?'
echo 'When in MINIMAL mode sWM will disable ALL features'
echo 'but will only take about 14kb of harddisk space.'
echon 'Would you like to use the mini-configuration? [y/N] '
read answer
if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
 echo "* disabling MINIMAL"
 echo "------------------------------------------------------------------------"
 echon "Do you want to use sWM's default (full) configuration? [y/N]"
 read answer
 if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
  echo "------------------------------------------------------------------------"
  echo 'Would you like sWM to listen for CTRL-C'
  echon 'and other signals? (installed +0.1kb) [Y/n] '
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "#define SIGNALS" >> swm.conf
   echo "* enabling SIGNALS"
  else
   echo "* disabling SIGNALS"
   echo "// #define SIGNALS" >> swm.conf
  fi
  echo "------------------------------------------------------------------------"
  echo 'When resizing/moving windows, swm changes the'
  echo 'mouse cursor. On some X-Terminals this causes'
  echon 'strange behavour. Do you want to enable this? (+0.1kb) [Y/n] ' 
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "#define CURSORS" >> swm.conf
   echo "* enabling CURSORS"
   echo "------------------------------------------------------------------------"
   echo "When you resize windows by right-clicking on the"
   echo "close-box, sWM moves the mouse pointer to the"
   echo "lower-right corner of the window by default to"
   echo "resize. If you use a touch screen unfortunally"
   echo "sWM can't move you hand too. ;-) Do you like to"
   echon "resize at the upper-right corner instead? [y/N] "
   read answer
   if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
    echo "// #define NORESIZEWARP" >> swm.conf
    echo "* disabling NORESIZEWARP"
   else
    echo "#define NORESIZEWARP" >> swm.conf
    echo "* enabling NORESIZEWARP"
   fi
   echo "------------------------------------------------------------------------"
   echon "Do you like to use sWM's default mouse cursors? [Y/n] "
   read answer
   if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
    echo "* using default cursors"
    echo "#define WINDOWCURSOR XC_left_ptr" >> swm.conf
    echo "#define BODYCURSOR XC_X_cursor" >> swm.conf
   else
    echo "You now have the chance to specify cursor shapes. You"
    echo "can enter all shapes used n cursorfont.h, usually to"
    echo "be found in /usr/X11R6/include/X11"
    echo 
    echo "Please specify your favourite normal cursor."
    echo "This mouse cursor is shown when the x-application does"
    echo "ask for a special cursor. Default is XC_left_ptr, the"
    echo "normal up-left arrow. If compilation fails check this again."
    echon "Your normal (WINDOW) cursor: "
    read answer
    if [ x$answer = x ]; then
     echo "#define WINDOWCURSOR XC_left_ptr" >> swm.conf
     echo "* setting XC_left_ptr for your WINDOWCURSOR"
    else
     echo '#define WINDOWCURSOR '$answer >> swm.conf
    fi
    echo "------------------------------------------------------------------------"
    echo "Please specify your favourite titlebar/border cursor."
    echo "This mouse cursor is shown when the mouse cursor is"
    echo "above the windows titlebar or windowborder. Default"
    echo "is X11 statdard cursor (X) If compilation fails check"
    echon "this again. Your normal (BODY) cursor: "
    read answer
    if [ x$answer = x ]; then
     echo "#define BODYCURSOR XC_X_cursor" >> swm.conf
     echo "* setting XC_X_cursor for your BODYCURSOR"
    else
     echo '#define BODYCURSOR '$answer >> swm.conf
    fi
   fi # end else defaultcursor    
  else # else cursors
   echo "// #define CURSORS" >> swm.conf
   echo "* disabling CURSORS"
  fi # endelse cursors
  echo "------------------------------------------------------------------------"
  echo 'Rezing/moving windows in opaqe mode could be very'
  echo 'slow on unaccelerared X displays and ISA-cards'
  echo 'FAST draws only a rectangle to indicate the new'
  echo 'position, but consumes a bit more memory.'
  echon 'Do you want to use FAST mode? (+0.4kb) [y/N] '
  read answer
  if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
   echo "// #define FAST" >> swm.conf
   echo "* disabling FAST"
  else
   echo "#define FAST" >> swm.conf
   echo "* enabling FAST"
  fi
  echo "------------------------------------------------------------------------"
  echo 'X-Terminals with monochrome, 16 or 256 colors need to switch'
  echo 'colormaps when changing to another window to ensure proper display.' 
  echon 'Do you need support for colormaps? [y/N] '
  read answer
  if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
   echo "// #define LOWCOLOR" >> swm.conf
   echo "* disabling COLORMAPS"
  else
   echo "#define LOWCOLOR" >> swm.conf
   echo "* enabling COLORMAPS"
  fi
  echo "------------------------------------------------------------------------"
  echo 'Some older X-Terminals and some buggy X-Servers need some extra'
  echo 'refreshes to react on window changes.' 
  echon 'Do you want sWM to do some extra syncs/refreshes? [y/N] '
  read answer
  if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
   echo "// #define HEAVYSYNC" >> swm.conf
   echo "* disabling HEAVYSYNC"
  else
   echo "#define HEAVYSYNC" >> swm.conf
   echo "* enabling HEAVYSYNC"
  fi
  echo "------------------------------------------------------------------------"
  echo 'Do you want swm to ALWAYS keep your windows in'
  echon 'the viewable screen range? [y/N]'
  read answer
  if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
   echo "// #define MAXRESTRICT" >> swm.conf
   echo "* disabling MAXRESTRICT"
   echo "------------------------------------------------------------------------"
   echo 'Some buggy X application resize themself out of the'
   echo 'screen borders. To keep them on the desktop swm has to'
   echon 'some additional checks? Should swm do that? [y/N] '
   read answer
   if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
    echo "// #define RESTRICTAUTORESIZE" >> swm.conf
    echo "* disabling RESTRICTAUTORESIZE"
   else
    echo "#define RESTRICTAUTORESIZE" >> swm.conf
    echo "* enabling RESTRICTAUTORESIZE"
   fi # endelse autorestrict
  else # else MAXRESTRICT
   echo "#define MAXRESTRICT" >> swm.conf
   echo "* enabling MAXRESTRICT"
  fi # endelse MAXRESTRICT
  echo "------------------------------------------------------------------------"
  echo "GNOME compliance enables virtual desktops and hint-handling,"
  echo "eating up more memory and disk space. It also slows down"
  echo "window handling a bit. (max +7kb)"
  echo "enables also: KEYS, MWM, FONTS, DRAWTITLE, STD_IO"
  echon 'Do you want to enable GNOME compliance? [Y/n] '
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "* enabling GNOME, KEYS, MWM, FONTS, DRAWTITLE, STD_IO"
   echo "#define GNOME" >> swm.conf
   echo "#define KEYS" >> swm.conf
   echo "#define MWM" >> swm.conf
   echo "#define FONTS" >> swm.conf
   echo "#define DRAWTITLE" >> swm.conf
   echo "#define STD_IO" >> swm.conf
   echo "------------------------------------------------------------------------"
   echon "How many virtual desktops do you like? [1-255] (default 4)?"
   read answer
   if [ x$answer = x ]; then
    echo "#define NUMBEROFDESKTOPS 4" >> swm.conf
    echo "setting to 4 desktops"
   else
    echo '#define NUMBEROFDESKTOPS '$answer >> swm.conf
   fi
   echo "#define FONTS" >> swm.conf
   echo "#define TITLEBARFONT \"*monotype-*-12*\" " >> swm.conf
   echo "------------------------------------------------------------------------"
   echo "Layer support enables sWM to do better stacking order"
   echo "management and will allow you to specify 'always ontop'"
   echo "windows and keeps background managers like nautilus"
   echon "behind all windows. Do you want to enable LAYERS? [Y/n] "
   read answer
   if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
    echo "#define LAYERS" >> swm.conf
    echo "* enabling LAYERS support"

    echo "------------------------------------------------------------------------"
    echo "Do you like sWM to show your layer number in the"
    echon "titlebar? [Y/n] "
    read answer
    if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
     echo "#define SHOWLAYERS" >> swm.conf
     echo "* enabling SHOWLAYERS support"
    fi
   else
    echo "// #define LAYERS" >> swm.conf
    echo "* disabling LAYERS support"
   fi
   echo "------------------------------------------------------------------------"
   echon "Do you like to raise windows using Alt-F5? (+0.1kb) [Y/n] "
   read answer
   if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
    echo "#define KEYRAISE" >> swm.conf
    echo "* enabling KEYRAISE"
   fi

  else #else gnome
   echo "* disabling GNOME compliance"
   echo "------------------------------------------------------------------------"
   echo "To hide the titlebar of some kind of panel or use icons"
   echo "on the desktop you have to enable MWM compliance. If enabled"
   echo "you can also toggle the titlebar on/off (with KEYS). This also"
   echon "enables some basic MWM compliant features. Enable it? [Y/n]"
   read answer
   if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
    echo "#define MWM" >> swm.conf
    echo "* enabling MWM compliance"
   else
    echo "// #define MWM" >> swm.conf
    echo "* disabling MWM compliance"
   fi
   echo "------------------------------------------------------------------------"
   echo "If you say YES to this question, you can control some"
   echo "essenial window operation with your keyboard."
   echo "(like ALT-F4 to close windows) and do some other usefull"
   echon "things. Do you want do enable KEYS? (+1.1kb) [Y/n] "
   read answer
   if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
    echo "#define KEYS" >> swm.conf
    echo "* enabling KEYS"
    echo "------------------------------------------------------------------------"
    echon "Do you like to raise windows using Alt-F5? (+0.1kb) [Y/n] "
    read answer
    if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
     echo "#define KEYRAISE" >> swm.conf
     echo "* enabling KEYRAISE"
    fi
   else # KEYS
    echo "// #define KEYS" >> swm.conf
    echo "* disabling KEYS"
   fi
   echo "------------------------------------------------------------------------"
   echo "FONTS/DRAWTITLE shows the window name in the"
   echo "titlebar. You may edit swm.conf to change your"
   echo "favorite font."
   echo "Hint: Enable this in debug mode. Enables also: STD_IO"
   echon "Do you want to enable this? [Y/n] "
   read answer
   if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
    echo "#define FONTS" >> swm.conf
    echo "#define DRAWTITLE" >> swm.conf
    echo "#define TITLEBARFONT \"*monotype-*-12*\" " >> swm.conf
    echo "* enabling FONTS support"
   else
    echo "* disabling FONTS"
    echo "------------------------------------------------------------------------"
    echo "STD_IO is used for all sorts of output of error"
    echon "messages. Do you want to enable this? [Y/n] "
    read answer
    if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
     echo "#define STD_IO" >> swm.conf
     echo "* enabling STD_IO features"
    fi
   fi # end else FONTS
  fi #end else gnome
  echo "------------------------------------------------------------------------"
  echo "MAXIMIZE enables a ([+] no pixmaps mode) box in the"
  echo "titlebar. You can resize windows to full screen and restore"
  echon "their state later. Do you want to enable MAXIMIZE? [Y/n] " 
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "#define MAXIMIZE" >> swm.conf
   echo "* enabling MAXIMIZE"
  else
   echo "// #define MAXIMIZE" >> swm.conf
   echo "* disabling MAXIMIZE"
  fi
  echo "------------------------------------------------------------------------"
  echo "Shading lets you roll up and down windows."
  echon "Do you want to enable shading? [Y/n] "
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "#define SHADE" >> swm.conf
   echo "* enabling SHADE"
   echo "------------------------------------------------------------------------"
   echo "sWM does not allow applications to iconify themselves."
   echo "Do you want to [i]gnore this requests or do you want" 
   echon "to [h]ide it or [s]hade it (default) instead? [i|s|h] "
   read answer
   if [ x$answer = x -o x$answer = xs ]; then
    echo "#define SHADEICONS" >> swm.conf
    echo "* enabling SHADEICONS"
   fi
   if [ x$answer = xi ]; then
    echo "#define NOICONS" >> swm.conf
    echo "* enabling NOICONS"
   fi
  else # SHADE
   echo "// #define SHADE" >> swm.conf
   echo "* disabling SHADE"
   echo "------------------------------------------------------------------------"
   echo "sWM does not allow applications to iconify themselves."
   echo "Do you want to [i]gnore this requests (default) or do" 
   echon "you want to [h]ide it instead (old default) ? [i|h] "
   read answer
   if [ x$answer = x -o x$answer = xi ]; then
    echo "#define NOICONS" >> swm.conf
    echo "* enabling NOICONS"
   else
    echo "* enabling HIDING"
   fi
  fi # end else SHADE
  echo "------------------------------------------------------------------------"
  echo "Most new appearing windows do not know where"
  echo "to pop up. So they normally appear in the upper"
  echo "left corner of the screen. Do you want swm to"
  echon "center them instead? (experimental) [y/N] "
  read answer
  if [ x$answer = x -o x$answer = xn -o x$answer = xN ]; then
   echo "// #define CENTERNEW" >> swm.conf
   echo "* disabling CENTERNEW"
  else
   echo "#define CENTERNEW" >> swm.conf
   echo "* enabling CENTERNEW"
  fi
  echo "------------------------------------------------------------------------"
  echo "Most new appearing windows like dialog boxes"
  echo "want keyboard focus. It is a good idea to focus"
  echo "them automatically. But if you always want to"
  echo "keep input focus in the window under your"
  echo "mouse, you should disable this. Do you want"
  echon "swm to autofocus new windows? [Y/n] "
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "#define FOCUSNEW" >> swm.conf
   echo "* enabling FOCUSNEW"
  else
   echo "// #define FOCUSNEW" >> swm.conf
   echo "* disabling FOCUSNEW"
  fi
  echo "------------------------------------------------------------------------"
  echon 'Would you like pixmap support? (+1.5kb) [Y/n] '
  read answer
  if [ x$answer = x -o x$answer = xy -o x$answer = xY ]; then
   echo "#define PIXMAPS" >> swm.conf
   echo "* enabling PIXMAPS, changed Makefile"
   echo "------------------------------------------------------------------------"
   echo 'Per default pixmaps will be installed at /usr/share/swm.'
   echo 'If you like you can change this directory to something else.'
   echo 'Where do you want swm to look for its pixmaps? Please enter'
   echon 'the location of your pixmap directory: '
   read answer
   if [ x$answer = x ]; then
    echo '#define PIXMAPDIR "/usr/share/swm"' >> swm.conf
    echo '* setting PIXMAPDIR to /usr/share/swm'
    echo 'PIXMAPDIR = /usr/share/swm' > Makefile
    cat Makefile-xpm >> Makefile
   else
    echo "#define PIXMAPDIR \"$answer\"" >> swm.conf
    echo '* setting PIXMAPDIR to '$answer
    echo 'PIXMAPDIR = '$answer > Makefile
    cat Makefile-xpm >> Makefile
   fi
  else # PIXMAPS
   echo "* disabling PIXMAPS"
   echo "// #define PIXMAPS" >> swm.conf
   cp -f Makefile-noxpm Makefile
  fi # end else PIXMAPS
  echo "------------------------------------------------------------------------"
  echo 'The .swm directory includes normally 3 executable files:'
  echo 'button1, button2 and button3 including everything you'
  echo 'like to execute when you click at the root window. You can'
  echo 'now specify the location of this directory.'
  echon '(Default is "$HOME")'
  read answer
  if [ x$answer = x ]; then
   echo '#define CONFDIR "$HOME"' >> swm.conf
   echo '* setting "$HOME" to location of .swm directory'
  else
   echo '#define CONFDIR "'$answer'"' >> swm.conf
   echo 'setting .swm directory to: '$answer
  fi
  echo "------------------------------------------------------------------------"
  echo "Please specify your foreground color (for titlebar)."
  echo "For theme woody try white or yellow. "
  echon "The default color is gold. Your foreground color: "
  read answer
  if [ x$answer = x ]; then
   echo "#define FOREGROUND \"gold\" " >> swm.conf
   echo "* setting black for your foreground color"
  else
   echo '#define FOREGROUND "'$answer'"' >> swm.conf
  fi
 else #end of NON-Default
  echo "* configuring sWM in default mode."
  cp -f swm.conf.default swm.conf
  echo 'PIXMAPDIR = /usr/share/swm' > Makefile
  cat Makefile-xpm >> Makefile
  echo "------------------------------------------------------------------------"
  echo "Please specify your foreground color (for titlebar)."
  echo "For theme woody try white or yellow. "
  echon "The default color is gold. Your foreground color: "
  read answer
  if [ x$answer = x ]; then
   echo "#define FOREGROUND \"gold\" " >> swm.conf
   echo "* setting black for your foreground color"
  else
   echo '#define FOREGROUND "'$answer'"' >> swm.conf
  fi
 fi
else # end of NON-MINIMAL
 echo "* enabling MINIMAL"
 echo "#define MINIMAL" >> swm.conf
 cp -f Makefile-noxpm Makefile
fi
echo "------------------------------------------------------------------------"
echo "Please specify your background color (for titlebar)."
echo "If you use PIXMAPS this value doesn't matter"
echo "otherwise default color would be blue. Your background"
echon "color: "
read answer
if [ x$answer = x ]; then
 echo "#define BACKGROUND \"blue\" " >> swm.conf
 echo "* setting gold for your background color"
else
 echo '#define BACKGROUND "'$answer'"' >> swm.conf
fi
echo "------------------------------------------------------------------------"
echo "Please specify your border color. The default"
echon "color is black. Your border color: "
read answer
if [ x$answer = x ]; then
 echo "#define BORDERCOLOR \"black\" " >> swm.conf
 echo "* setting black for your border color"
else
 echo '#define BORDERCOLOR "'$answer'"' >> swm.conf
fi
echo "------------------------------------------------------------------------"
echo "#define TITLEBARHEIGHT 17" >> swm.conf
echo "#define MINWINDOWWIDTH 20" >> swm.conf
echo " " >> swm.conf
make clean
echo "------------------------------------------------------------------------"
echo "Configuration is now finished."
echo "Run >make< and >make install< to compile swm and"
echo "install it. If you want to try swm without pixmaps,"
echo "you don't have to install pixmaps. To compile with"
echo "pixmap support you need XPM-lib development packages."
echo "Also take a look at the swmswitch and swmbg utility."
echo "-- :-) -- :-) -- enjoy sWM!"
