X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=bin%2Fsetbg;h=09311f582ebf069f2b65488942a5879abfea4700;hb=64cb05c445d480f29d266e70db6eb1d021d34456;hp=39ce45bf53eb5506c22ed33ebf1984a433595485;hpb=2ac32f0f6e784bec6229273959dc93baeedc2974;p=clearscm.git diff --git a/bin/setbg b/bin/setbg index 39ce45b..09311f5 100755 --- a/bin/setbg +++ b/bin/setbg @@ -57,10 +57,12 @@ use warnings; use FindBin; use Getopt::Long; use Proc::ProcessTable; +use File::Spec; use CGI qw/:standard/; use lib "$FindBin::Bin/../lib"; +use DateUtils; use Display; use Utils; @@ -68,6 +70,7 @@ my $VERSION = '$Revision: 1.10 $'; ($VERSION) = ($VERSION =~ /\$Revision: (.*) /); my $processes = new Proc::ProcessTable; +my @imgDirs; foreach my $process (@{$processes->table}) { if ($process->cmndline =~ /setbg/ and @@ -78,38 +81,46 @@ foreach my $process (@{$processes->table}) { } # if } # foreach +sub fillPictures () { + my @images; + + foreach (@imgDirs) { + my @pics = `find "$_" -type f -name "*.jpg"`; + + chomp @pics; + push @images, @pics; + } # foreach + + return @images; +} # fillPictures + $0 = "$FindBin::Script " . join ' ', @ARGV; verbose "$FindBin::Script v$VERSION"; my $sleep = 60 * 60; -my @imgDir; GetOptions ( 'usage' => sub { Usage }, 'verbose' => sub { set_verbose }, 'debug' => sub { set_debug }, 'sleep=i' => \$sleep, - 'bgdir=s' => \@imgDir, + 'bgdir=s' => \@imgDirs, ) || Usage; -foreach (@imgDir) { - error "$_ is not a directory", 1 unless -d $_; +for (my $i = 0; $i < scalar @imgDirs; $i++) { + error "$imgDirs[$i] is not a directory", 1 unless -d $imgDirs[$i]; + + $imgDirs[$i] = File::Spec->rel2abs ($imgDirs[$i]); } # foreach # Using gsettings my $setbg = "gsettings"; my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://"; -my @images; +my @images = fillPictures; -foreach (@imgDir) { - my @pics = `find "$_" -type f -name "*.jpg"`; - chomp @pics; - push @images, @pics; -} # foreach - -Usage "No images to display. Must specify -imgDir" unless @images; +Usage "No images to display. Must specify -bgdir" unless @images; sub SwitchWallPaper { # We don't need to do anything here, just handle the interrupt and @@ -118,8 +129,10 @@ sub SwitchWallPaper { } # SwitchWallPaper $SIG{USR2} = \&SwitchWallPaper; +$SIG{USR1} = \&fillPictures; my $debugger = $DB::OUT; +my $today; EnterDaemonMode unless defined $DB::OUT; @@ -127,7 +140,7 @@ while () { my $image = escapeHTML ($images[int (rand $#images)]); open my $log, '>', "$ENV{HOME}/.$FindBin::Script" - or error "Unable to open $ENV{HOME}/.setbg for writing - $!", 1; + or error "Unable to open $ENV{HOME}/.$FindBin::Script for writing - $!", 1; display $image, $log; @@ -143,5 +156,11 @@ while () { close $log; + $today = YMD; + sleep $sleep; + + if ($today ne YMD){ + @images = fillPictures; + } # if } # while