#!/usr/bin/perl -w

# crystal-wallpaper - skrypt sucy do losowej zmiany ta
# Kod wziety ze skryptu 'pjbackground'
# tapety powinny znajdowa si w katalogu ~/Wallpapers
# skrypt powinien by umieszczony w katalogu ~/bin
# standardowo jest podpiety do lewego przycisku myszy
# do ustawienia ta uzywa programu Esetroot

use File::Find; #to get all files under mainDir
use Getopt::Std;  # command line processing

getopts("w:d:")|| die "Invalid argument\n";
@images = ();

sub process_file{
    $filename = $File::Find::name;
    if ( -f $filename ){
	push(@images, $filename);
    }
}

if ( $opt_d ) {
	$basedir = $opt_d;
    }
else{
   $basedir = "$ENV{HOME}/Wallpapers";
} 

find(\&process_file, $basedir);
srand;
$index=int(rand(@images));
print "\n The wallpaper now is $images[$index] \n";
exec '/usr/bin/Esetroot','-scale',$images[$index];
