#!/bin/sh
#Barry Kauler 2005,2006 GPL www.pupweb.org

PARAM1="$1"

if [ ! -f /etc/xlockscreenparams ];then
 echo -n ' -mousemotion -grabserver -echokeys -echokey X -mode goop'  > /etc/xlockscreenparams
fi
if [ ! -f /etc/xlockrootparams ];then
 echo -n ' -bg white -inroot -mode goop'  > /etc/xlockrootparams
fi
if [ "$PARAM1" = "-inroot" ];then
 CURRMODE="`cat /etc/xlockrootparams | tr -s ' ' | tr ' ' "\n" | tail -n 1`"
else
 CURRMODE="`cat /etc/xlockscreenparams | tr -s ' ' | tr ' ' "\n" | tail -n 1`"
fi
if [ "$CURRMODE" = "-mode" ];then
 CURRMODE=""
fi

if [ "$PARAM1" = "-password" ];then
 MAINDIALOG='<wtitle>Clear xlock password</wtitle>
  <vbox>
   <text><label>"The first time Xlock runs, it will ask for a key, meaning a
password. To change the password, you need to delete the
file /root/.xlockrc, which is all that this button does..."</label>
   </text>
   <button>
    <label>Click to clear password</label>
    <action>rm -f /root/.xlockrc</action>
    <action>exit:PASSWD</action>
   </button>
  </vbox>
'
 echo "$MAINDIALOG" | gtkdialog2 --stdin
 exit
fi

if [ "$PARAM1" = "-configure" ];then
 PRETEXT="\"This window is for configuring Xlock as a screen locker.
Puppy also has a screensaver, configurable via the menu:
 Control Panel --> Gxset X settings
which will blank the screen after a period of inactivity.
However, there is also a need for a privacy system that you
invoke manually and with a password to unlock -- this is
what Xlock will do, with bonus pretty pictures when locked.

After previewing, click the OK button for one you want...\""
 KILLBOX=""
else
 PRETEXT="\"This window is to choose a desktop background animated
image. Note there is also a xlock icon on the desktop that
will lock the screen, with only the animation displaying.

After previewing, click the OK button for one you want...\""
 KILLBOX="
 <hbox>
  <text><label>Kill any currently running animation:</label></text>
  <button>
   <label>KILL</label>
   <action>exit:KILLED</action>
  </button>
 </hbox>
"
fi

if [ ! "`echo "$PARAM1" | grep --extended-regexp "configure|inroot"`" = "" ];then
 #configure xlock...
 MAINDIALOG="<wtitle>Xlock: current mode is $CURRMODE</wtitle>
 <vbox>
  <text><label>$PRETEXT</label>
  </text>
  $KILLBOX
  <hbox>
   <text><label>Ball: shows bouncing balls</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode ball</action>
   </button>
   <button ok><action>exit:ball</action></button>
  </hbox>
  <hbox>
   <text><label>Blank: a black screen</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode blank</action>
   </button>
   <button ok><action>exit:blank</action></button>
  </hbox>
  <hbox>
   <text><label>Dclock: shows a floating digital clock</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode dclock</action>
   </button>
   <button ok><action>exit:dclock</action></button>
  </hbox>
  <hbox>
   <text><label>Goop: shows goop from a lava lamp</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode goop</action>
   </button>
   <button ok><action>exit:goop</action></button>
  </hbox>
  <hbox>
   <text><label>Lyapunov: shows lyapunov space</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode lyapunov</action>
   </button>
   <button ok><action>exit:lyapunov</action></button>
  </hbox>
  <hbox>
   <text><label>Mandelbrot: shows mandelbrot sets</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode mandelbrot</action>
   </button>
   <button ok><action>exit:mandelbrot</action></button>
  </hbox>
  <hbox>
   <text><label>Matrix: shows the matrix (the movie)</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode matrix</action>
   </button>
   <button ok><action>exit:matrix</action></button>
  </hbox>
  <hbox>
   <text><label>Penrose: shows quasiperiodic tilings</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode penrose</action>
   </button>
   <button ok><action>exit:penrose</action></button>
  </hbox>
  <hbox>
   <text><label>Solitare: shows a game of solitare</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode solitare</action>
   </button>
   <button ok><action>exit:solitare</action></button>
  </hbox>
  <hbox>
   <text><label>Spiral: shows a helical locus of points</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode spiral</action>
   </button>
   <button ok><action>exit:spiral</action></button>
  </hbox>
  <hbox>
   <text><label>Swirl: shows animated swirling patterns</label></text>
   <button>
    <label>Preview</label>
    <action>xlock -inwindow -mode swirl</action>
   </button>
   <button ok><action>exit:swirl</action></button>
  </hbox>
 </vbox>
"

 RETVAL="`echo "$MAINDIALOG" | gtkdialog2 --stdin`"

 if [ ! "`echo "$RETVAL" | grep "KILLED"`" = "" ];then
  killall xlock
  exit
 fi

 MYCHOICE="`echo "$RETVAL" | grep "EXIT:" | cut -f 2 -d ':'`"

 #extra params chosen here...
 # -delay microseconds  --time between batch repeats
 # -count number        --number of things to do per batch
 # -size number         --size of an object
 # -erasemode           --random_lines, random_squares, venetian, triple_wipe, quad_wipe, circle_wipe, three_circle_wipe, squaretate,  fizzle,   spiral,   slide_lines,   losira, no_fade
 # -erasedelay microseconds --time of each step of erase

 #paranoid precaution...
 if [ "`echo "$MYCHOICE" | grep --extended-regexp "solitare|mandelbrot|swirl|spiral|penrose|matrix|lyapunov|goop|dclock|ball|blank"`" = "" ];then
  MYCHOICE="goop"
 fi

 if [ "$PARAM1" = "-inroot" ];then
  echo -n " -inroot -mode $MYCHOICE" > /etc/xlockrootparams
  XLOCKPARAMS="`cat /etc/xlockrootparams`"
  killall xlock
  xlock $XLOCKPARAMS &
  exit
 else
  echo -n " -grabserver -echokeys -echokey X -mode $MYCHOICE" > /etc/xlockscreenparams
  exit
 fi
fi


if [ ! -f /root/.xlockrc ];then
 XLOCKPARAMS="`cat /etc/xlockscreenparams`"
 rxvt -bg orange -g 36x1 -title "Create key (password)" -e xlock $XLOCKPARAMS
else
 xlock `cat /etc/xlockscreenparams`
fi

###end###
