--- rxvt-unicode/src/init.C 2010/08/28 11:03:30 1.275 +++ rxvt-unicode/src/init.C 2010/12/02 11:02:17 1.285 @@ -634,6 +634,10 @@ set_output_threshold (OUTPUT_LEVEL_WARNING); #endif +#ifdef HAVE_PIXBUF + g_type_init (); +#endif + #if ENABLE_PERL if (!rs[Rs_perl_ext_1]) rs[Rs_perl_ext_1] = "default"; @@ -817,10 +821,9 @@ { bgPixmap.set_transparent (); -#ifdef HAVE_AFTERIMAGE if (rs [Rs_blurradius]) bgPixmap.set_blur_radius (rs [Rs_blurradius]); -#endif + if (ISSET_PIXCOLOR (Color_tint)) bgPixmap.set_tint (pix_colors_focused [Color_tint]); @@ -1281,6 +1284,118 @@ ModMetaMask = modmasks[i - 1]; } +void +rxvt_term::set_icon (const char *file) +{ +#ifdef HAVE_AFTERIMAGE + init_asv (); + + ASImage *im = file2ASImage (file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); + if (!im) + { + rxvt_warn ("Loading image icon failed, continuing without.\n"); + return; + } + + unsigned int w = im->width; + unsigned int h = im->height; + + if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) + { + rxvt_warn ("Icon image too big, continuing without.\n"); + destroy_asimage (&im); + return; + } + + ASImage *result = scale_asimage (asv, im, + w, h, ASA_ARGB32, + 100, ASIMAGE_QUALITY_DEFAULT); + destroy_asimage (&im); + + if (!result) + { + rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); + return; + } + + long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); + if (buffer) + { + ARGB32 *asbuf = result->alt.argb32; + buffer [0] = w; + buffer [1] = h; + + for (unsigned int i = 0; i < w * h; ++i) + buffer [i + 2] = asbuf [i]; + + XChangeProperty (dpy, parent[0], xa[XA_NET_WM_ICON], XA_CARDINAL, 32, + PropModeReplace, (const unsigned char *) buffer, 2 + w * h); + free (buffer); + } + else + rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); + + destroy_asimage (&result); +#endif + +#ifdef HAVE_PIXBUF + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); + if (!pixbuf) + { + rxvt_warn ("Loading image icon failed, continuing without.\n"); + return; + } + + unsigned int w = gdk_pixbuf_get_width (pixbuf); + unsigned int h = gdk_pixbuf_get_height (pixbuf); + + if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) + { + rxvt_warn ("Icon image too big, continuing without.\n"); + g_object_unref (pixbuf); + return; + } + + if (long *buffer = (long *)malloc ((2 + w * h) * sizeof (long))) + { + int rowstride = gdk_pixbuf_get_rowstride (pixbuf); + unsigned char *row = gdk_pixbuf_get_pixels (pixbuf); + int channels = gdk_pixbuf_get_n_channels (pixbuf); + + buffer [0] = w; + buffer [1] = h; + for (int i = 0; i < h; i++) + { + for (int j = 0; j < w; j++) + { + unsigned char *pixel = row + j * channels; + long value; + + if (channels == 4) + value = pixel[3]; + else + value = (unsigned char)0x00ff; + + value = (value << 8) + pixel[0]; + value = (value << 8) + pixel[1]; + value = (value << 8) + pixel[2]; + buffer[(i * w + j) + 2] = value; + } + + row += rowstride; + } + + XChangeProperty (dpy, parent[0], xa[XA_NET_WM_ICON], XA_CARDINAL, 32, + PropModeReplace, (const unsigned char *) buffer, 2 + w * h); + free (buffer); + } + else + rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); + + g_object_unref (pixbuf); +#endif +} + /*----------------------------------------------------------------------*/ /* rxvt_Create_Windows () - Open and map the window */ void @@ -1370,7 +1485,6 @@ XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, &szHint, &wmHint, &classHint); #if ENABLE_EWMH -# ifdef HAVE_AFTERIMAGE /* * set up icon hint * rs [Rs_iconfile] is path to icon @@ -1378,46 +1492,8 @@ if (rs [Rs_iconfile]) { - init_asv (); - - ASImage *im = file2ASImage (rs [Rs_iconfile], 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); - if (asv && im) - { - int w = im->width; - int h = im->height; - long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); - ASImage *result = scale_asimage (asv, im, - w, h, ASA_ARGB32, - 100, ASIMAGE_QUALITY_DEFAULT); - destroy_asimage (&im); - - if (buffer && result) - { - ARGB32 *asbuf = result->alt.argb32; - buffer [0] = w; - buffer [1] = h; - - for (unsigned int i = 0; i < w * h; ++i) - buffer [i + 2] = asbuf [i]; - - destroy_asimage (&result); - XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32, - PropModeReplace, (const unsigned char *) buffer, 2 + w * h); - free (buffer); - } - else - { - if (!buffer) - rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); - - if (!result) - rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); - } - } - else - rxvt_warn ("Loading image icon failed, continuing without.\n"); + set_icon (rs [Rs_iconfile]); } -# endif #endif #if ENABLE_FRILLS