X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=bin%2Fsetbg;h=c7a9b249b73801a3a3653551499ba247579f19d2;hb=30711801710786c51a071df0e9ff85a649ab7c32;hp=777f6329b12ae5ca87a14de5aa41c71b5820e8dd;hpb=020a4a5ea2be725b155cae3a2cadc9aba3911b9b;p=clearscm.git diff --git a/bin/setbg b/bin/setbg index 777f632..c7a9b24 100755 --- a/bin/setbg +++ b/bin/setbg @@ -57,9 +57,11 @@ use warnings; use FindBin; use Getopt::Long; use Proc::ProcessTable; +use CGI qw/:standard/; use lib "$FindBin::Bin/../lib"; +use DateUtils; use Display; use Utils; @@ -67,6 +69,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 @@ -77,29 +80,45 @@ 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 = $ENV{SETBG_DIR} ? $ENV{SETBG_DIR} : '/web/Pictures'; GetOptions ( - 'usage' => sub { Usage }, - 'verbose' => sub { set_verbose }, - 'debug' => sub { set_debug }, - 'sleep=i' => \$sleep, - 'bgdir=s' => \$imgDir, + 'usage' => sub { Usage }, + 'verbose' => sub { set_verbose }, + 'debug' => sub { set_debug }, + 'sleep=i' => \$sleep, + 'bgdir=s' => \@imgDirs, ) || Usage; -error "$imgDir is not a directory", 1 unless -d $imgDir; +foreach (@imgDirs) { + error "$_ is not a directory", 1 unless -d $_; +} # foreach # Using gsettings -my $setbg = "gsettings"; +my $setbg = "gsettings"; my $setbgOpts = "set org.gnome.desktop.background picture-uri \"file://"; -chomp (my @images = `find $imgDir -type f -name "*.jpg"`); +my @images = fillPictures; +Usage "No images to display. Must specify -imgDir" unless @images; + sub SwitchWallPaper { # We don't need to do anything here, just handle the interrupt and # let the while loop continue. @@ -107,24 +126,38 @@ sub SwitchWallPaper { } # SwitchWallPaper $SIG{USR2} = \&SwitchWallPaper; +$SIG{USR1} = \&fillPictures; my $debugger = $DB::OUT; +my $today; EnterDaemonMode unless defined $DB::OUT; while () { - my $image = $images[int (rand $#images)]; + 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; - display "Current background: $image", $log; + display $image, $log; my $cmd = "$setbg $setbgOpts$image\" 2> /dev/null"; - `$cmd`; + my @output = `$cmd`; + if ($? != 0) { + display "ERROR Trying to set background - command used \"$cmd\"", $log; + display "Output:"; + display join "\n", @output, $log; + } # if + close $log; + $today = YMD; + sleep $sleep; + + if ($today ne YMD){ + @images = fillPictures; + } # if } # while