+ printf("Using window 0x%lx\n", id);
+
+ do {
+ unsigned int w, h;
+
+ XGetWindowProperty(d, id, net_wm_icon, offset++, 1,
+ False, XA_CARDINAL, &ret_type, &ret_format,
+ &ret_items, &ret_bytesleft,
+ (unsigned char**) &prop_return[image]);
+ if (ret_type == None || ret_items < 1) {
+ printf("No icon found\n");
+ return 1;
+ }
+ w = prop_return[image][0];
+ XFree(prop_return[image]);
+
+ XGetWindowProperty(d, id, net_wm_icon, offset++, 1,
+ False, XA_CARDINAL, &ret_type, &ret_format,
+ &ret_items, &ret_bytesleft,
+ (unsigned char**) &prop_return[image]);
+ if (ret_type == None || ret_items < 1) {
+ printf("Failed to get height\n");
+ return 1;
+ }
+ h = prop_return[image][0];
+ XFree(prop_return[image]);
+
+ XGetWindowProperty(d, id, net_wm_icon, offset, w*h,
+ False, XA_CARDINAL, &ret_type, &ret_format,
+ &ret_items, &ret_bytesleft,
+ (unsigned char**) &prop_return[image]);
+ if (ret_type == None || ret_items < w*h) {
+ printf("Failed to get image data\n");
+ return 1;
+ }
+ offset += w*h;
+
+ printf("Found icon with size %dx%d\n", w, h);
+
+ i[image] = XCreateImage(d, DefaultVisual(d, s), DefaultDepth(d, s),
+ ZPixmap, 0, NULL, w, h, 32, 0);
+ assert(i[image]);
+ i[image]->byte_order = LSBFirst;
+ i[image]->data = (char*)prop_return[image];
+ for (j = 0; j < w*h; j++) {
+ unsigned char alpha = (unsigned char)i[image]->data[j*4+3];
+ unsigned char r = (unsigned char) i[image]->data[j*4+0];
+ unsigned char g = (unsigned char) i[image]->data[j*4+1];
+ unsigned char b = (unsigned char) i[image]->data[j*4+2];
+
+ // background color
+ unsigned char bgr = 0;
+ unsigned char bgg = 0;
+ unsigned char bgb = 0;
+
+ r = bgr + (r - bgr) * alpha / 256;
+ g = bgg + (g - bgg) * alpha / 256;
+ b = bgb + (b - bgb) * alpha / 256;
+
+ i[image]->data[j*4+0] = (char) r;
+ i[image]->data[j*4+1] = (char) g;
+ i[image]->data[j*4+2] = (char) b;
+ }
+
+ winw += w;
+ if (h > winh) winh = h;
+
+ ++image;
+ } while (ret_bytesleft > 0 && image < MAX_IMAGES);
+
+ win = XCreateSimpleWindow(d, RootWindow(d, s), 0, 0, winw, winh,
+ 0, 0, 0);
+ assert(win);
+ XMapWindow(d, win);
+
+ p = XCreatePixmap(d, win, winw, winh, DefaultDepth(d, s));
+ XFillRectangle(d, p, DefaultGC(d, s), 0, 0, winw, winh);
+
+ for (j = 0; j < image; ++j) {
+ static unsigned int x = 0;
+
+ XPutImage(d, p, DefaultGC(d, s), i[j], 0, 0, x, 0,
+ i[j]->width, i[j]->height);
+ x += i[j]->width;
+ XDestroyImage(i[j]);
+ }