Based on the code and an idea from Sasha, I've modified this thumbnail function so that it blends the application's icon with a resized capture of its main window. The results are quite impressive: the thumbnail seems to be a native fvwm's function. It's based on the Imlib2. Here's the code. Save it as thumb.c:
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
Display *display;
XWindowAttributes windowattr;
Imlib_Image image;
Imlib_Image icon;
int windowid, thumbwidth, thumbheight;
char *imageformat, *imagepath;
char *iconformat, *iconpath;
int w, h;
if(argc != 5) {
puts("Usage: thumb WindowId ThumbWidth ThumbFile IconFile");
return 1;
}
sscanf(argv[1], "%x", &windowid);
sscanf(argv[2], "%d", &thumbwidth);
imagepath = argv[3];
imageformat = strrchr(argv[3], '.');
iconpath = argv[4];
iconformat = strrchr(argv[4], '.');
if((display = XOpenDisplay(NULL)) == NULL )
return 1;
XGetWindowAttributes(display, windowid, &windowattr);
thumbheight = (int)((float)windowattr.height / ((float)windowattr.width/(float)thumbwidth));
imlib_context_set_anti_alias(1);
imlib_context_set_display(display);
imlib_context_set_visual(DefaultVisual(display, DefaultScreen(display)));
imlib_context_set_colormap(DefaultColormap(display, DefaultScreen(display)));
imlib_context_set_drawable(windowid);
if( 4*thumbwidth >= windowattr.width ||
4*thumbheight >= windowattr.height ) {
image = imlib_create_image_from_drawable((Pixmap)0, 0, 0, windowattr.width, windowattr.height, 1);
imlib_context_set_image(image);
image = imlib_create_cropped_scaled_image(0, 0, windowattr.width, windowattr.height, thumbwidth, thumbheight);
} else {
image = imlib_create_scaled_image_from_drawable((Pixmap)0, 0, 0, windowattr.width, windowattr.height, 4*thumbwidth, 4*thumbheight, 1, 1);
imlib_context_set_image(image);
image = imlib_create_cropped_scaled_image(0, 0, 4*thumbwidth, 4*thumbheight, thumbwidth, thumbheight);
}
icon = imlib_load_image(argv[4]);
imlib_context_set_image(icon);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(image);
imlib_blend_image_onto_image(icon, 0, 0, 0, w, h, 0, 0, w, h);
imlib_image_set_format(imageformat + 1);
imlib_save_image(argv[3]);
fprintf(stdout, "WindowStyle IconOverride, Icon %s\n", argv[3]);
return 0;
}
To compile the beast, here's a simple Makefile:
CC := gcc
CFLAGS := -Wall -O3 -fomit-frame-pointer \
`imlib2-config --cflags`
CPPFLAGS :=
CXXFLAGS := $(CFLAGS)
TARGET_ARCH := -march=athlon-xp -mcpu=athlon-xp
LDFLAGS := -Wl,-O1 \
`imlib2-config --libs`
PRODUCTS := thumb
.PHONY: clean
all: $(PRODUCTS)
clean:
find *.o -exec rm {} \; && echo || echo
mrproper: clean
for product in $(PRODUCTS); \
do [ -f $$product ] && rm $$product; \
done && echo || echo
rebuild: mrproper all
thumb: thumb.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
strip $@
Adapt it to your need and it should produces the executable thumb. Put it under your fvwm's script repository.
I call it via a modified thumbnailling function strongly inspired from Taviso's work.
SetEnv fvwm_icon_size 150
DestroyFunc Thumbnail
AddToFunc Thumbnail
+ I Raise
+ I SetEnv Icon-$[w.id] $[w.IconFile]
+ I ThisWindow (!Shaded, Iconifiable, !Iconic) PipeRead \
"$./script/thumb $[w.id] $[fvwm_icon_size] /dev/shm/icon.tmp.$[w.id].png $[w.IconFile]"
+ I Iconify
DestroyFunc DeThumbnail
AddToFunc DeThumbnail
+ I Exec exec ogg123 -d esd $[fvwm_wave_path]/Popup.ogg
+ I PipeRead "echo WindowStyle IconOverride, Icon \\$\\[Icon-$[w.id]\\]"
+ I UnsetEnv Icon-$[w.id]
+ I Exec exec "rm -f /dev/shm/icon.tmp.$[w.id].png"
To work properly, every iconified program must have an icon declared. In my configuration, I've a style by default that provide an icon fallback:
span>Style * EWMHMiniIconOverride, \
Icon $[fvwm_icon]/64x64/filesystems/gnome-fs-network.png, \
MiniIcon $[fvwm_icon]/16x16/filesystems/gnome-fs-network.png