Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Rotate Wallpaper in Gnome 2

by dystrophy (Monk)
on Apr 04, 2003 at 06:51 UTC ( #247987=CUFP: print w/ replies, xml ) Need Help??

Here's a little thing I whipped up to switch my desktop pattern in Gnome 2. I have some images in my wallpaper directory that I didn't want stretched because they were too small, so I check the size with Image::Size. This would be easily modified to center images with odd ratio sides so they won't be stretched.
#!/usr/bin/perl -w # by Darren Patterson # script to rotate bg in gnome 2 # easiest use is to run on startup or put in crontab use strict; use Image::Size; # minimum x and y dimension for image to stretch my $minx = 800; my $miny = 600; # location of backgrounds directory my $image_loc = "/home/darren/diamond/backup/My Documents/My Pictures" +; # debug? my $debug = 0; ################################ # end of configurables ############################### # open and read the image location dir opendir (IMGS, "$image_loc") || die "can't opendir $image_loc: $!"; my @files = grep {/(jpg|gif|bmp|png)$/} readdir (IMGS); closedir IMGS; # perlmonks help on srand ;-) srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); my $random = (int(rand $#files + 1)); # get the appropriate file my $file = $files[$random]; # debug help if ($debug) {print "$random - $file\n";} # Get the size of the file my ($xsize, $ysize) = imgsize("$image_loc/$file"); # set the bg first (otherwise it resizes the previous img before chang +ing) system("gconftool-2 --type=string --set /desktop/gnome/background/pict +ure_filename \"$image_loc/$file\""); # if dimensions are less than 800 x 600, center, else stretch it if ( $xsize < $minx || $ysize < $miny) { system("gconftool-2 --type=string --set /desktop/gnome/backgro +und/picture_options centered"); } else { system("gconftool-2 --type=string --set /desktop/gnome/backgro +und/picture_options stretched"); } exit;

- dystrophy -

Comment on Rotate Wallpaper in Gnome 2
Download Code
Re: Rotate Wallpaper in Gnome 2
by revdiablo (Prior) on Apr 04, 2003 at 23:21 UTC

    This is pretty nice. Though I have some minor niggles with the style -- use of global filehandles versus lexical, and single-arg system() -- it's all pretty much how I'd do something along these lines.

    Also, I like the use of gconftool-2. I didn't know about this little program, and it seems very useful (even if GConf reminds me way too much of the Windows Registry). Thanks for the example. :)

Re: Rotate Wallpaper in Gnome 2
by dws (Chancellor) on Apr 04, 2003 at 23:41 UTC
      srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
    Aside from being overkill, it hasn't been necessary to invoke srand() since 5.004. Any system new enough to be running Gnome2 probably doesn't have a Perl that old. :)

Re: Rotate Wallpaper in Gnome 2
by benizi (Hermit) on Apr 05, 2003 at 04:40 UTC
    Nice job dystrophy. I whipped up an almost identical program just the other day, after stumbling upon GConf in another context.

    In the hope that it may help another user in a similar situation, under RedHat 8.0, my background wasn't controlled by the value of the /desktop/gnome/background keys; I had to stop nautilus from drawing its own background.
    I added the --no-desktop flag to the nautilus command line in ~/.gnome/session, but this can also be done with gconftool-2:

    gconftool-2 --type=bool --set /apps/nautilus/preferences/show_desktop false

    The only side effect is that you can't have any 'desktop' icons.

      It is possible to tell Nautilus not to draw its own wallpaper without stopping it from drawing desktop icons. My Mandrake 9.1 system was configured this way OOTB, but I specifically recall changing the setting in Nautilus under an earlier version of Mandrake. (No, that's not where 9.1 got the setting; I installed it on a blank partition.) Unfortunately, I don't know how to do this from Perl :-(

      Anyway, ++ to dystrophy; formerly I was just doing `ln -s $f ~/images/current-wallpaper` and the new wallpaper would take effect magically whenever X was restarted, but that meant having the same wallpaper for weeks, and I was just wondering the other day how to tell Gnome to reload the wallpaper, so this is a big improvement :-)

      Oh, one thing to add. You just troll a directory tree and look for images, but if you want better control over which images to use as wallpaper and which not, do what I do: create a single directory and fill it with symlinks to just the images you want used. Then @f=<~/images/wallpaper-symlinks/*>; and there's no need for filtering.


      {my$c;$ x=sub{++$c}}map{$ \.=$_->()}map{my$a=$_->[1]; sub{$a++ }}sort{_($a->[0 ])<=>_( $b->[0])}map{my@x=(& $x( ),$ _) ;\ @x} split //, "rPcr t lhuJnhea eretk.as o";print;sub _{ord(shift)*($=-++$^H)%(42-ord("\r"))};

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://247987]
Approved by Coruscate
Front-paged by Coruscate
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-10-25 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls