Seperate menu-selected wallpaper on each desktop

I know this is a very basic function, and far from original, but I’m putting it here for the benefit of newcomers, and to help fill out the forum with more examples of simple but effective configuration ideas. I hope it will be helpful.

The purpose is to have a “wallpaper” menu, which will display automatically generated thumbnails from the relevant folder. The selected wallpaper should be shown on the current desktop only, and automatically reproduced on that desktop the next time FVWM is started.

First, create the location for the wallpaper menu, in another menu:[code]DestroyMenu MenuConfig
AddToMenu MenuConfig

  • “FVWM Help” Popup MenuFvwmHelp
  • “Wallpaper” Popup MenuWallpaper
    …[/code]

Then create the wallpaper menu. Since menu changes depending on the contents of the wallpaper folder, it must be dynamic:[code]DestroyMenu MenuWallpaper
AddToMenu MenuWallpaper foo title

  • DynamicPopupAction Function WallpaperBrowser[/code]

Define the WallpaperBrowser function, which will be run each time the wallpaper menu is selected, and will generate the wallpaper menu:[code]DestroyFunc WallpaperBrowser
AddToFunc WallpaperBrowser

  • I DestroyMenu recreate MenuWallpaper
  • I AddToMenu MenuWallpaper “Wallpaper - desk $[DESK.N]” title
  • I PipeRead ‘$[HOME]/.fvwm/scripts/wallpaper.sh $[HOME]/wallpaper $[DESK.N]’[/code]
    The menu will have title Wallpaper - desk X where X is the current desktop number. The script “wallpaper.sh” should be something like the following:#!/bin/sh [ -d $1/.thumbs ] || mkdir $1/.thumbs for pic in `find $1/* -exec basename {} .jpg \;`; do [ -f $1/.thumbs/$pic.png ] || convert -quality 0 -resize 48 $1/$pic.jpg $1/.thumbs/$pic.png echo "+ %$1/.thumbs/$pic.png%\"$pic\" exec exec \`ln -sf $1/$pic.jpg $1/.current-$2-fvwm && xloadimage -fullscreen -onroot $1/$pic.jpg\`" done

This first creates any missing thumbnails in a folder called ~/wallpapers/.thumbs, then generates the menu entries, complete with thumbnails, and echos them back to the WallpaperBrowser function to display on your menu.

The action for the selected menu is to create a link to “current-X-fvwm” where X is the desktop number. So now, simply use the FvwmBacker function to load the wallpaper pointed to by the link relevant for each desktop. Add + I Module FvwmBacker to your start function, and the following configuration for FvwmBacker to your configuration:[code]DestroyModuleConfig FvwmBacker: *

*FvwmBacker: Command (Desk 0, Page * *)
Exec exec xloadimage -onroot -fullscreen $[HOME]/wallpaper/.current-0-fvwm

*FvwmBacker: Command (Desk 1, Page * *)
Exec exec xloadimage -onroot -fullscreen $[HOME]/wallpaper/.current-1-fvwm

[/code]
This uses xloadimage to load the wallpapers. Many other programs can also do this, and everyone has their favourite.

Here’s a screenshot:

Please do add comments, point out inaccuracies/improvements etc…

Just a few things that I’ve been meaning to say for a while…

Probably easier, but Fvwm automatically sets “$HOME/.fvwm” to the variable accessible as: “$[FVWM_USERDIR]”.

Hmm, this’ll be quite slow on some machines - since jpg support is not in Fvwm anyway, surely having a preconverted set of .png files for this purpose would be far easier? It would save the processing time of having to convert each file on the fly, then.

Rather than symlinking each time, you could just ascertain which image to use for which desk, and change it without the symlink stuff, as in:

*FvwmBacker: Command($[desk.n], * *) ....

– Thomas Adam

So it does :slight_smile:

It would be easy to do the conversion to .png too, and use that instead. However, the script only runs on images which have not previously had a thumbnail created - assuming you’ve not changed the images in the directory, it takes virtually no time to load the menu. I just deleted all the thumbnails for a test, and it took just under 10 seconds to bring up a menu with nearly 20 entries (admitedly on a fast computer). The next time is instant.

The point of simlinking is that the next time you start FVWM, the same wallpapers are loaded as you had previously. Which was kind of my starting point for wanting to make this work.

I modified wallpaper.sh so it can handle all types of wallpapers, not just .jpgs:

#!/bin/sh
[ -d $1/.thumbs ] || mkdir $1/.thumbs
for pic in `find $1/* -exec basename {} \;`;
do
    base=`echo $pic | sed s/\.[^\.]*$//`
    [ -f $1/.thumbs/$base.png ] || convert -quality 0 -resize 48 $1/$pic $1/.thumbs/$base.png
    echo "+ %$1/.thumbs/$base.png%\"$base\" exec exec \`ln -sf $1/$pic $1/.current-$2-fvwm && xloadimage -fullscreen -onroot $1/$pic\`"
done

Other than that I’m liking the way this works. Although sometimes my pager will randomly freeze (after too many desktop switches? I dunno) and the only way to get it working again is to restart fvwm. Which is kind of annoying. If you have any thoughts as to what might be causing that I’m all ears.

Oh yeah, I also added in the following:

*FvwmBacker: RetainPixmap

Actually I’m not sure if that helps anything. At first I thought it sped things up, but now I’m not so sure :confused:

It just means that transparency works properly. If you on don’t use transparency then it won’t make any difference