--- rxvt-unicode/src/background.C 2012/05/25 08:27:47 1.220 +++ rxvt-unicode/src/background.C 2012/05/31 05:53:46 1.226 @@ -60,6 +60,11 @@ void rxvt_term::bg_destroy () { +# ifdef BG_IMAGE_FROM_FILE + for (vector::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) + bg_image->destroy (); +# endif + if (bg_pixmap) XFreePixmap (dpy, bg_pixmap); } @@ -300,9 +305,7 @@ changed = true; } - if (!(flags & IM_TILE) - || h_scale || v_scale - || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) + if (is_size_sensitive ()) flags |= IM_IS_SIZE_SENSITIVE; else flags &= ~IM_IS_SIZE_SENSITIVE; @@ -602,6 +605,11 @@ dst_width, dst_height, need_blend); } + if (image.need_blur ()) + blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius); + if (image.need_tint ()) + tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade); + #if XRENDER if (need_blend) { @@ -616,7 +624,7 @@ XRenderColor mask_c; - mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; + mask_c.alpha = image.alpha; mask_c.red = mask_c.green = mask_c.blue = 0; @@ -671,32 +679,24 @@ void rxvt_term::parse_image (int id, const char *type, const char *arg) { - rxvt_image *image; - - for (image = image_vec.begin (); image < image_vec.end (); image++) - if (image->id == id) - break; + if (image_vec.size () < id + 1) + image_vec.resize (id + 1); - if (image == image_vec.end ()) - { - image = new_image (); - image->id = id; - } + rxvt_image *image = &image_vec[id]; } # endif rxvt_image::rxvt_image () { - id = - alpha = - flags = + alpha = 0xffff; + flags = 0; h_scale = - v_scale = + v_scale = defaultScale; h_align = - v_align = 0; + v_align = defaultAlign; # ifdef HAVE_PIXBUF - pixbuf.reset (0); + pixbuf = 0; # endif } @@ -719,8 +719,8 @@ bool ret = set_file (file); alpha = 0x8000; - if (ret && p) - set_geometry (p + 1); + if (ret) + set_geometry (p ? p + 1 : ""); return ret; } @@ -735,27 +735,21 @@ { if (pixbuf) g_object_unref (pixbuf); - pixbuf.reset (image); + pixbuf = image; ret = true; } # endif if (ret) - { - alpha = 0xffff; - flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; - h_scale = v_scale = defaultScale; - h_align = v_align = defaultAlign; - } + flags |= IM_IS_SET; return ret; } # endif /* BG_IMAGE_FROM_FILE */ -# ifdef ENABLE_TRANSPARENCY bool -rxvt_term::bg_set_blur (const char *geom) +image_effects::set_blur (const char *geom) { bool changed = false; unsigned int hr, vr; @@ -786,21 +780,12 @@ } bool -rxvt_term::bg_set_tint (rxvt_color &new_tint) +image_effects::set_tint (const rxvt_color &new_tint) { - if (!(bg_flags & BG_TINT_SET) || tint != new_tint) + if (!tint_set || tint != new_tint) { tint = new_tint; - bg_flags |= BG_TINT_SET; - - rgba c; - tint.get (c); - if ((c.r <= 0x00ff || c.r >= 0xff00) - && (c.g <= 0x00ff || c.g >= 0xff00) - && (c.b <= 0x00ff || c.b >= 0xff00)) - bg_flags |= BG_TINT_BITAND; - else - bg_flags &= ~BG_TINT_BITAND; + tint_set = true; return true; } @@ -809,7 +794,7 @@ } bool -rxvt_term::bg_set_shade (const char *shade_str) +image_effects::set_shade (const char *shade_str) { int new_shade = atoi (shade_str); @@ -850,7 +835,7 @@ #endif bool -rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) +rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) { bool ret = false; #if XRENDER @@ -862,7 +847,8 @@ XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); XRenderPictureAttributes pa; - XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); + XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) + : XRenderFindVisualFormat (dpy, visual); pa.repeat = RepeatPad; Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); @@ -915,11 +901,19 @@ } bool -rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) +rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade) { bool ret = false; - if (shade == 100 && (bg_flags & BG_TINT_BITAND)) + rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); + + if (tint_set) + tint.get (c); + + if (shade == 100 + && (c.r <= 0x00ff || c.r >= 0xff00) + && (c.g <= 0x00ff || c.g >= 0xff00) + && (c.b <= 0x00ff || c.b >= 0xff00)) { XGCValues gcv; GC gc; @@ -941,11 +935,6 @@ # if XRENDER else if (bg_flags & BG_HAS_RENDER) { - rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); - - if (bg_flags & BG_TINT_SET) - tint.get (c); - if (shade <= 100) { c.r = c.r * shade / 100; @@ -959,7 +948,8 @@ c.b = c.b * (200 - shade) / 100; } - XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); + XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) + : XRenderFindVisualFormat (dpy, visual); Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); @@ -1005,6 +995,7 @@ return ret; } +# ifdef ENABLE_TRANSPARENCY /* * Builds a pixmap of the same size as the terminal window that contains * the tiled portion of the root pixmap that is supposed to be covered by @@ -1105,19 +1096,21 @@ { XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); ret = true; - bool need_blur = h_blurRadius && v_blurRadius; - bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); + bool need_blur = root_effects.need_blur (); + bool need_tint = root_effects.need_tint (); if (!(bg_flags & BG_CLIENT_RENDER)) { if (need_blur) { - if (blur_pixmap (bg_pixmap, window_width, window_height)) + if (blur_pixmap (bg_pixmap, window_width, window_height, false, + root_effects.h_blurRadius, root_effects.v_blurRadius)) need_blur = false; } if (need_tint) { - if (tint_pixmap (bg_pixmap, window_width, window_height)) + if (tint_pixmap (bg_pixmap, window_width, window_height, false, + root_effects.tint, root_effects.tint_set, root_effects.shade)) need_tint = false; } if (need_tint) @@ -1126,7 +1119,7 @@ if (ximage) { /* our own client-side tinting */ - tint_ximage (ximage); + tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); XDestroyImage (ximage); @@ -1195,10 +1188,6 @@ void rxvt_term::bg_init () { -#ifdef ENABLE_TRANSPARENCY - shade = 100; -#endif - bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); #if XRENDER int major, minor; @@ -1231,7 +1220,12 @@ if (!(bg_image->flags & IM_IS_SET)) bg_image = image_vec.erase (bg_image); else - bg_image++; + { + if (bg_image->is_size_sensitive ()) + bg_image->flags |= IM_IS_SIZE_SENSITIVE; + + bg_image++; + } } # endif @@ -1241,9 +1235,6 @@ #endif } -#endif /* HAVE_BG_PIXMAP */ - -#ifdef ENABLE_TRANSPARENCY /* based on code from aterm-0.4.2 */ static inline void @@ -1259,7 +1250,7 @@ } void -rxvt_term::tint_ximage (XImage *ximage) +rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade) { unsigned int size_r, size_g, size_b; int sh_r, sh_g, sh_b; @@ -1294,7 +1285,7 @@ rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); - if (bg_flags & BG_TINT_SET) + if (tint_set) tint.get (c); /* prepare limits for color transformation (each channel is handled separately) */ @@ -1354,4 +1345,5 @@ free (lookup); } -#endif /* ENABLE_TRANSPARENCY */ + +#endif /* HAVE_BG_PIXMAP */