http://ftp.x.org/contrib/applications/xscreensaver-3.20.tar.gz
[xscreensaver] / hacks / vidwhacker
index a27e0c2b3e1db152626be23c60f6fdf0dcca1e5e..a82da03ef9b1803856424d1a3e80c8a7e5c5439d 100755 (executable)
@@ -12,9 +12,9 @@
 #
 #
 # This script grabs a frame of video, then uses various pbm filters to
-# munge the image in random nefarious ways, then uses xv to put it on
-# the root window.  This works out really nicely if you just feed some
-# random TV station into it...
+# munge the image in random nefarious ways, then uses xloadimage, xli, or xv
+# to put it on the root window.  This works out really nicely if you just
+# feed some random TV station into it...
 #
 # The video grabbing part is SGI-specific -- if you want to use this on
 # another system, add a new clause to the grab() procedure.
@@ -42,6 +42,39 @@ tmp_ppm4=$tmp-4.ppm
 tmp_ppmS=$tmp-S.ppm
 
 
+# Figure out whether to use xloadimage, xli, or xv.
+pick_displayer() {
+  displayer=
+  for prog in xloadimage xli xv ; do
+    IFS=:
+    for p in $PATH; do
+      IFS=
+      if [ "$p" = "" ]; then p=. ; fi
+      if [ -x $p/$prog ]; then
+        displayer=$prog
+        break 2
+      fi
+    done
+  done
+
+  if [ "$displayer" = "xloadimage" ]; then
+    displayer_args="-quiet"
+    displayer_win_args=""
+    displayer_root_args="-onroot"
+  elif [ "$displayer" = "xli" ]; then
+    displayer_args="-quiet"
+    displayer_win_args=""
+    displayer_root_args="-onroot -center -border black"
+  elif [ "$displayer" = "xv" ]; then
+    displayer_args="-quick24"
+    displayer_win_args="-geom +0+0"
+    displayer_root_args="-root -rmode 5 -noresetroot -rfg black -rbg black -viewonly"
+  else
+    echo "$0: neither xli nor xv found on \$PATH"
+    exit -1
+  fi
+}
+
 # Process command-line args
 getargs() {
 
@@ -83,12 +116,12 @@ getargs() {
     shift
   done
 
-  xvargs="-quick24"
+  pick_displayer
 
   if [ "$onroot" = true ]; then
-    xvargs="$xvargs -root -rmode 5 -noresetroot -rfg black -rbg black -viewonly"
+    displayer_args="$displayer_args $displayer_root_args"
   else
-    xvargs="$xvargs -geom +0+0"
+    displayer_args="$displayer_args $displayer_win_args"
   fi
 
 
@@ -300,7 +333,7 @@ whack() {
 }
 
 
-# Kill off the xv subprocess, if it's running
+# Kill off the xli or xv subprocess, if it's running
 #
 kill_pid() {
   if [ "$pid" != "" ]; then
@@ -345,11 +378,12 @@ main() {
 
     # Loop grabbing and frobbing images.
     #
-    # If we're running on the root, run xv in the foreground (with -exit)
-    # and then wait.
+    # If we're running on the root, run xv or xli in the foreground
+    # (with -exit, if xv) and then wait.
     #
-    # If we're running in a window, spawn xv in the background; then when
-    # it's time to put up the new image, kill off the currently-running xv.
+    # If we're running in a window, spawn xv or xli in the background; then
+    # when it's time to put up the new image, kill off the currently-running
+    # xv or xli.
 
     if [ "$verbose" = true ]; then
       whack
@@ -370,23 +404,24 @@ main() {
 
     else
 
-      pnmtosgi < $tmp_ppm3 > $tmp_ppm2
-      rm -f $tmp_ppm3
+#      pnmtosgi < $tmp_ppm3 > $tmp_ppm2
+#      rm -f $tmp_ppm3
+       mv $tmp_ppm3 $tmp_ppm2
 
       if [ -s $tmp_ppm2 ]; then
         if [ "$verbose" = true ]; then
-          echo "launching xv $xvargs $tmp_ppm2" >&2
+          echo "launching $displayer $displayer_args $tmp_ppm2" >&2
          ls -lF $tmp_ppm2
         fi
 
        mv $tmp_ppm2 $tmp_ppm0
-        xv $xvargs $tmp_ppm0 &
+        eval "$displayer $displayer_args $tmp_ppm0 &"
 
 # this doesn't work -- leaves xv processes around, instead of stray xset
 # data.  Sigh.
 #
 #      # cat the file so that we can nuke it without racing against xv.
-#        cat $tmp_ppm2 | xv $xvargs - &
+#        cat $tmp_ppm2 | $displayer $displayer_args - &
 
         pid=$!
       fi