#!/usr/bin/perl # Backgrounds directory (relative path) $bgfolder = "/home/marik/backgrounds/"; # list of current background resolutions @bgModes; # current Resolution $realRes; #--------------------------------------- # Read in current background dirs #--------------------------------------- @bgModes = split /\n/,`find $bgfolder -type d`; # Get rid of the default folder entry of the bgFolder shift(@bgModes); # Sort by width @bgModes = sort(@bgModes); # Remove the preceeding folder definitition and add a folder delimeter for(@bgModes) { $_ =~ s/$bgfolder//; $_ .= "/"; } #--------------------------------------------------------------------------- # Since cron cant read xrandr or xdpyinfo, get the resolution from xorg.conf #--------------------------------------------------------------------------- @grep = split /\n/, `grep -A 1 -i depth /etc/X11/xorg.conf`; for(0..$#grep) { if($grep[$_] =~ /^\s+DefaultDepth\s+(\d+)/) { $depth = $1; } if($grep[$_] =~ /^\s+Depth\s+$depth/) { @Modes = split /\s+/,$grep[$_+1]; $_ = $#grep; } } shift(@Modes); shift(@Modes); $Modes[0] =~ s/\"//g; $realRes = $Modes[0]; #----------------------------------------------- # Pool higher/current resolution background URIs #----------------------------------------------- @bgPool; for(@bgModes) { if($realRes <= $_) { opendir (DH, ($bgfolder . $_)); @curResBgs = readdir DH; shift( @curResBgs); shift( @curResBgs); foreach $bg (@curResBgs) { push(@bgPool, $bgfolder . $_ . $bg);} } } # Choose a random one and do the magic $random = int(rand($#bgPool+1)); system "Esetroot -fit $bgPool[$random]"; # do the magic