#!/usr/local/bin/perl -w # # wmrotator.pl # # Created: Aug 14, 2003 by Andy Harrison # # $Id: wmrotator.pl,v 1.2 2003/08/25 19:29:23 aharriso Exp aharriso $ # # simple background/theme rotator for windowmaker, runs as a daemon # # Usage: # # Add to your $HOME/GNUstep/Library/WindowMaker/autostart script # # Create a file called bg.txt in your GNUstep dir with the filenames # from the Backgrounds directory, one per line. # # Similarly, you can create a file called themes.txt in your GNUstep # Themes dir with the directory name (the directory must contain a # style file) or the name of a style file in GNUstep Themes directory. # # In Window Maker, create a menu item with the command: # kill -USR1 `cat $HOME/GNUstep/rotatebg.pid` # and it will send a signal to rotate the background immediately. use strict; use Tie::File; use Proc::Daemon; my $rotatetime = 1200; my $GNUstep = "$ENV{'HOME'}/GNUstep"; my $bgdir = "$GNUstep/Library/WindowMaker/Backgrounds/"; my $themedir = "$GNUstep/Library/WindowMaker/Themes/"; my $bgfile = "$GNUstep/bg.txt"; my $themefile = "$GNUstep/themes.txt"; # # Add path to the wmsetbg and setstyle commands if necessary # my $bgcmd = "wmsetbg --tile"; my $themecmd = "setstyle"; my @rotate = &init; $SIG{CHLD} = 'IGNORE'; # Get rid of Zombie problems $SIG{USR1} = 'rotate'; # rotate whenever you want $SIG{QUIT} = 'quit'; $SIG{TERM} = 'quit'; Proc::Daemon::Init; # Run as Daemon my $PID = "$GNUstep/rotatebg.pid"; open PID,">$PID" or die ( $! ); print PID $$; close PID; while ( 1 ) { &rotate; } sub rotate { tie my @lines, 'Tie::File', $rotate[0] or die( $! ); # # uses the 1st file in the list, removes, sticks it on the bottom # so it rotates without repeat until it's finished the list. # my $file = $lines[0]; shift @lines; push @lines,$file; print qx( $rotate[2] $rotate[1]$file ); untie @lines; sleep $rotatetime; } sub init { # # don't rotate backgrounds if there's a theme file # if ( -f $bgfile && ! -z $bgfile && ! -f $themefile ) { return ( $bgfile, $bgdir, $bgcmd ); } elsif ( -f $themefile && ! -z $themefile ) { return ( $themefile, $themedir, $themecmd ); } else { die "Neither $bgfile nor $themefile exists\n: $!"; } } sub quit { unlink $PID; exit; }
--
"I just read perlman:perlboot," said Tom, objectively.
naChoZ
UPDATE: added theme support
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Window Maker background rotator
by Red Sonja (Initiate) on Aug 21, 2003 at 22:45 UTC | |
by naChoZ (Curate) on Aug 25, 2003 at 19:33 UTC |