--- rxvt-unicode/src/init.C 2010/08/29 15:05:08 1.279 +++ rxvt-unicode/src/init.C 2011/01/03 03:05:47 1.289 @@ -62,13 +62,10 @@ #include #include -/* these next two are probably only on Sun (not Solaris) */ +/* these next is probably only on Sun (not Solaris) */ #ifdef HAVE_SYS_SOCKIO_H #include #endif -#ifdef HAVE_SYS_BYTEORDER_H -#include -#endif #include #include @@ -145,7 +142,7 @@ } #endif -const char *const def_colorName[] = +static const char *const def_colorName[] = { COLOR_FOREGROUND, COLOR_BACKGROUND, @@ -634,6 +631,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 +818,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]); @@ -889,7 +889,6 @@ void rxvt_term::init_env () { - int i; char *val; #ifdef DISPLAY_IS_IP @@ -913,8 +912,7 @@ if (rs[Rs_display_name] == NULL) rs[Rs_display_name] = val; /* use broken `:0' value */ - i = strlen (val); - env_display = (char *)rxvt_malloc (i + 9); + env_display = (char *)rxvt_malloc (strlen (val) + 9); sprintf (env_display, "DISPLAY=%s", val); @@ -1294,10 +1292,10 @@ return; } - int w = im->width; - int h = im->height; + unsigned int w = im->width; + unsigned int h = im->height; - if (!IN_RANGE_INC (w, 1, 32767) || !IN_RANGE_INC (h, 1, 32767)) + 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); @@ -1334,6 +1332,63 @@ 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 } /*----------------------------------------------------------------------*/ @@ -1449,7 +1504,7 @@ #endif }; - XSetWMProtocols (dpy, top, protocols, sizeof (protocols) / sizeof (protocols[0])); + XSetWMProtocols (dpy, top, protocols, ARRAY_LENGTH(protocols)); #if ENABLE_FRILLS if (rs[Rs_transient_for])