--- rxvt-unicode/src/background.C 2007/10/31 09:55:23 1.10 +++ rxvt-unicode/src/background.C 2010/09/02 15:48:10 1.55 @@ -3,10 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 1997 Carsten Haitzler - * Copyright (c) 1997,1998 Oezguer Kesim - * Copyright (c) 1998-2001 Geoff Wing - * Copyright (c) 2005-2006 Marc Lehmann + * Copyright (c) 2005-2008 Marc Lehmann * Copyright (c) 2007 Sasha Vasko * * This program is free software; you can redistribute it and/or modify @@ -30,18 +27,23 @@ #define DO_TIMING_TEST 0 #if DO_TIMING_TEST +# include #define TIMING_TEST_START(id) \ - struct timeval timing_test_##id##_stv;\ + struct timeval timing_test_##id##_stv; \ gettimeofday (&timing_test_##id##_stv, NULL); #define TIMING_TEST_PRINT_RESULT(id) \ - do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ - fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ - tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) + do { \ + struct timeval tv; \ + gettimeofday (&tv, NULL); \ + tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \ + fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \ + tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \ + } while (0) #else -#define TIMING_TEST_START(id) do{}while (0) -#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) +#define TIMING_TEST_START(id) do {} while (0) +#define TIMING_TEST_PRINT_RESULT(id) do {} while (0) #endif /* @@ -50,35 +52,35 @@ * adjustment and may optionally be followed by a colon and one or more * colon-delimited pixmap operations. * The following table shows the valid geometry strings and their - * affects on the background image : + * effects on the background image : * - * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. + * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. * W and H are percentages of the terminal window size. * X and Y are also percentages; e.g., +50+50 centers * the image in the window. - * WxH+X Assumes Y == X - * WxH Assumes Y == X == 50 (centers the image) - * W+X+Y Assumes H == W - * W+X Assumes H == W and Y == X - * W Assumes H == W and Y == X == 50 + * WxH+X Assumes Y == X + * WxH Assumes Y == X == 50 (centers the image) + * W+X+Y Assumes H == W + * W+X Assumes H == W and Y == X + * W Assumes H == W and Y == X == 50 * * Adjusting position only : - * =+X+Y Set position to X% by Y% (absolute). - * =+X Set position to X% by X%. - * +X+Y Adjust position horizontally X% and vertically Y% + * =+X+Y Set position to X% by Y% (absolute). + * =+X Set position to X% by X%. + * +X+Y Adjust position horizontally X% and vertically Y% * from current position (relative). - * +X Adjust position horizontally X% and vertically X% + * +X Adjust position horizontally X% and vertically X% * from current position. * * Adjusting scale only : - * Wx0 Multiply horizontal scaling factor by W% - * 0xH Multiply vertical scaling factor by H% - * 0x0 No scaling (show image at normal size). + * Wx0 Multiply horizontal scaling factor by W% + * 0xH Multiply vertical scaling factor by H% + * 0x0 No scaling (show image at normal size). * * Pixmap Operations : (should be prepended by a colon) - * tile Tile image. Scaling/position modifiers above will affect + * tile Tile image. Scaling/position modifiers above will affect * the tile size and origin. - * propscale When scaling, scale proportionally. That is, maintain the + * propscale When scaling, scale proportionally. That is, maintain the * proper aspect ratio for the image. Any portion of the * background not covered by the image is filled with the * current background color. @@ -89,44 +91,87 @@ */ #ifdef HAVE_BG_PIXMAP -bgPixmap_t::bgPixmap_t() +bgPixmap_t::bgPixmap_t () { + // this is basically redundant as bgPixmap_t is only used in + // zero_initialised-derived structs #ifdef HAVE_AFTERIMAGE original_asim = NULL; #endif +#ifdef HAVE_PIXBUF + pixbuf = NULL; +#endif #ifdef BG_IMAGE_FROM_FILE + have_image = false; h_scale = v_scale = 0; h_align = v_align = 0; #endif flags = 0; pixmap = None; + valid_since = invalid_since = 0; + target = 0; } +void +bgPixmap_t::destroy () +{ +#ifdef HAVE_AFTERIMAGE + if (original_asim) + safe_asimage_destroy (original_asim); +#endif + +#ifdef HAVE_PIXBUF + if (pixbuf) + g_object_unref (pixbuf); +#endif + + if (pixmap && target) + XFreePixmap (target->dpy, pixmap); +} bool bgPixmap_t::window_size_sensitive () { +# ifdef ENABLE_TRANSPARENCY + if (flags & isTransparent) + return true; +# endif + # ifdef BG_IMAGE_FROM_FILE -# ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) -# endif + if (have_image) { if (h_scale != 0 || v_scale != 0 || h_align != 0 || v_align != 0) return true; } # endif + + return false; +} + +bool +bgPixmap_t::window_position_sensitive () +{ # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) return true; # endif + +# ifdef BG_IMAGE_FROM_FILE + if (have_image) + { + if (h_align == rootAlign || v_align == rootAlign) + return true; + } +# endif + return false; -} +}; bool bgPixmap_t::need_client_side_rendering () { # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) return true; # endif # ifdef ENABLE_TRANSPARENCY @@ -165,10 +210,13 @@ { if (geom_flags & flag) { - if (new_value < -100) - new_value = -100; - else if (new_value > 200) - new_value = 200; + if (new_value != bgPixmap_t::rootAlign) + { + if (new_value < -100) + new_value = -100; + else if (new_value > 200) + new_value = 200; + } if (new_value != align) { align = new_value; @@ -222,8 +270,8 @@ unsigned int w = 0, h = 0; unsigned int n; unsigned long new_flags = (flags & (~geometryFlags)); - char *p; -# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ + const char *p; +# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ if (geom == NULL) return false; @@ -240,7 +288,7 @@ char *ops; new_flags |= geometrySet; - strncpy (str, geom, n); + memcpy (str, geom, n); str[n] = '\0'; if (str[0] == ':') ops = &str[0]; @@ -270,7 +318,8 @@ } if (flags & geometrySet) - {/* new geometry is an adjustment to the old one ! */ + { + /* new geometry is an adjustment to the old one ! */ if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) { if (w == 0 && h != 0) @@ -296,14 +345,16 @@ else /* setting up geometry from scratch */ { if (!(geom_flags & XValue)) - {/* use default geometry - centered */ + { + /* use default geometry - centered */ x = y = defaultAlign; } else if (!(geom_flags & YValue)) y = x; if ((geom_flags & (WidthValue|HeightValue)) == 0) - {/* use default geometry - scaled */ + { + /* use default geometry - scaled */ w = h = defaultScale; } else if (geom_flags & WidthValue) @@ -316,7 +367,8 @@ } } /* done parsing geometry string */ else if (!(flags & geometrySet)) - { /* default geometry - scaled and centered */ + { + /* default geometry - scaled and centered */ x = y = defaultAlign; w = h = defaultScale; } @@ -329,62 +381,65 @@ while (*ops) { while (*ops == ':' || isspace(*ops)) ++ops; -# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) - if (CHECK_GEOM_OPS("tile")) + +# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) + if (CHECK_GEOM_OPS ("tile")) { - w = h = 0; + w = h = noScale; geom_flags |= WidthValue|HeightValue; } - else if (CHECK_GEOM_OPS("propscale")) + else if (CHECK_GEOM_OPS ("propscale")) { if (w == 0 && h == 0) { - w = 100; + w = windowScale; geom_flags |= WidthValue; } new_flags |= propScale; } - else if (CHECK_GEOM_OPS("hscale")) + else if (CHECK_GEOM_OPS ("hscale")) { - if (w == 0) - w = 100; - h = 0; + if (w == 0) w = windowScale; + + h = noScale; geom_flags |= WidthValue|HeightValue; } - else if (CHECK_GEOM_OPS("vscale")) + else if (CHECK_GEOM_OPS ("vscale")) { - if (h == 0) - h = 100; - w = 0; + if (h == 0) h = windowScale; + + w = noScale; geom_flags |= WidthValue|HeightValue; } - else if (CHECK_GEOM_OPS("scale")) + else if (CHECK_GEOM_OPS ("scale")) { - if (h == 0) - h = 100; - if (w == 0) - w = 100; + if (h == 0) h = windowScale; + if (w == 0) w = windowScale; + geom_flags |= WidthValue|HeightValue; } - else if (CHECK_GEOM_OPS("auto")) + else if (CHECK_GEOM_OPS ("auto")) { - w = h = 100; - x = y = 50; + w = h = windowScale; + x = y = centerAlign; + geom_flags |= WidthValue|HeightValue|XValue|YValue; + } + else if (CHECK_GEOM_OPS ("root")) + { + w = h = noScale; + x = y = rootAlign; geom_flags |= WidthValue|HeightValue|XValue|YValue; } # undef CHECK_GEOM_OPS + while (*ops != ':' && *ops != '\0') ++ops; } /* done parsing ops */ } - if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) - ++changed; - if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) - ++changed; - if (check_set_align_value (geom_flags, XValue, h_align, x)) - ++changed; - if (check_set_align_value (geom_flags, YValue, v_align, y)) - ++changed; + if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; + if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; + if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; + if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; } if (new_flags != flags) @@ -392,22 +447,62 @@ flags = new_flags; changed++; } -//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", -// flags, h_scale, v_scale, h_align, v_align); + + //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", + // flags, h_scale, v_scale, h_align, v_align); return (changed > 0); } # ifdef HAVE_AFTERIMAGE bool -bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) +bgPixmap_t::render_image (unsigned long background_flags) { if (target == NULL) return false; - int target_width = (int)target->szHint.width; - int target_height = (int)target->szHint.height; - int new_pmap_width = target_width, new_pmap_height = target_height; - ASImage *result = NULL; + target->init_asv (); + + ASImage *background = NULL; + ARGB32 background_tint = TINT_LEAVE_SAME; + +# ifdef ENABLE_TRANSPARENCY + if (background_flags) + background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); + + if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) + { + ShadingInfo as_shade; + as_shade.shading = (shade == 0) ? 100 : shade; + + rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); + if (flags & tintSet) + tint.get (c); + as_shade.tintColor.red = c.r; + as_shade.tintColor.green = c.g; + as_shade.tintColor.blue = c.b; + + background_tint = shading2tint32 (&as_shade); + } + + if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) + { + ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, + (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, + 100, ASIMAGE_QUALITY_DEFAULT); + if (tmp) + { + destroy_asimage (&background); + background = tmp; + } + } +# endif + + ASImage *result = 0; + + int target_width = target->szHint.width; + int target_height = target->szHint.height; + int new_pmap_width = target_width; + int new_pmap_height = target_height; int x = 0; int y = 0; @@ -418,11 +513,21 @@ if (original_asim) { - x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); - y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); + if (h_align == rootAlign || v_align == rootAlign) + { + target->get_window_origin (x, y); + x = -x; + y = -y; + } + + if (h_align != rootAlign) + x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); + + if (v_align != rootAlign) + y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); } - if (original_asim == NULL + if (!original_asim || x >= target_width || y >= target_height || (w > 0 && x + w <= 0) @@ -433,9 +538,10 @@ new_pmap_width = background->width; new_pmap_height = background->height; result = background; + if (background_tint != TINT_LEAVE_SAME) { - ASImage* tmp = tile_asimage (target->asv, background, 0, 0, + ASImage *tmp = tile_asimage (target->asv, background, 0, 0, target_width, target_height, background_tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) @@ -448,6 +554,7 @@ else { result = original_asim; + if ((w > 0 && w != original_asim->width) || (h > 0 && h != original_asim->height)) { @@ -457,50 +564,59 @@ background ? ASA_ASImage : ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); } + if (background == NULL) - {/* if tiling - pixmap has to be sized exactly as the image */ + { + /* if tiling - pixmap has to be sized exactly as the image, + but there is no need to make it bigger than the window! */ if (h_scale == 0) - new_pmap_width = result->width; + new_pmap_width = min (result->width, target_width); if (v_scale == 0) - new_pmap_height = result->height; + new_pmap_height = min (result->height, target_height); /* we also need to tile our image in one or both directions */ if (h_scale == 0 || v_scale == 0) { ASImage *tmp = tile_asimage (target->asv, result, - (h_scale > 0) ? 0 : (int)result->width - x, - (v_scale > 0) ? 0 : (int)result->height - y, - result->width, result->height, - TINT_LEAVE_SAME, ASA_XImage, - 100, ASIMAGE_QUALITY_DEFAULT); + (h_scale > 0) ? 0 : (int)result->width - x, + (v_scale > 0) ? 0 : (int)result->height - y, + new_pmap_width, + new_pmap_height, + TINT_LEAVE_SAME, ASA_XImage, + 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) { if (result != original_asim) destroy_asimage (&result); + result = tmp; } } } else - {/* if blending background and image - pixmap has to be sized same as target window */ + { + /* if blending background and image - pixmap has to be sized same as target window */ ASImageLayer *layers = create_image_layers (2); - ASImage *merged_im = NULL; layers[0].im = background; layers[0].clip_width = target_width; layers[0].clip_height = target_height; layers[0].tint = background_tint; layers[1].im = result; + if (w <= 0) - {/* tile horizontally */ + { + /* tile horizontally */ while (x > 0) x -= (int)result->width; layers[1].dst_x = x; layers[1].clip_width = result->width+target_width; } else - {/* clip horizontally */ + { + /* clip horizontally */ layers[1].dst_x = x; layers[1].clip_width = result->width; } + if (h <= 0) { while (y > 0) y -= (int)result->height; @@ -512,42 +628,48 @@ layers[1].dst_y = y; layers[1].clip_height = result->height; } + if (target->rs[Rs_blendtype]) { layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); if (layers[1].merge_scanlines == NULL) layers[1].merge_scanlines = alphablend_scanlines; } + ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); + if (tmp) { if (result != original_asim) destroy_asimage (&result); + result = tmp; } + free (layers); } } TIMING_TEST_PRINT_RESULT (asim); - if (pixmap) - { - if (result == NULL - || pmap_width != new_pmap_width - || pmap_height != new_pmap_height - || pmap_depth != target->depth) - { - XFreePixmap (target->dpy, pixmap); - pixmap = None; - } - } + bool ret = false; if (result) { XGCValues gcv; GC gc; + if (pixmap) + { + if (pmap_width != new_pmap_width + || pmap_height != new_pmap_height + || pmap_depth != target->depth) + { + XFreePixmap (target->dpy, pixmap); + pixmap = None; + } + } + /* create Pixmap */ if (pixmap == None) { @@ -556,7 +678,7 @@ pmap_height = new_pmap_height; pmap_depth = target->depth; } - /* fill with background color ( if result's not completely overlapping it)*/ + /* fill with background color (if result's not completely overlapping it) */ gcv.foreground = target->pix_colors[Color_bg]; gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); @@ -564,17 +686,13 @@ int dst_width = result->width, dst_height = result->height; if (background == NULL) { - if (h_scale > 0) - src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); - if (v_scale > 0) - src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); + if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); + if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); if (dst_x > 0 || dst_y > 0 || dst_x + dst_width < new_pmap_width || dst_y + dst_height < new_pmap_height) - { - XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); - } + XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); } /* put result on pixmap */ @@ -586,42 +704,203 @@ XFreeGC (target->dpy, gc); TIMING_TEST_PRINT_RESULT (asim); + + ret = true; } - return true; + if (background) + destroy_asimage (&background); + + return ret; } # endif /* HAVE_AFTERIMAGE */ +# ifdef HAVE_PIXBUF bool -bgPixmap_t::set_file (const char *file) +bgPixmap_t::render_image (unsigned long background_flags) { - char *f; + if (target == NULL) + return false; + + if (!pixbuf) + return false; + + // TODO: add alpha blending + if (background_flags) + return false; + + GdkPixbuf *result; - assert (file != NULL); + int image_width = gdk_pixbuf_get_width (pixbuf); + int image_height = gdk_pixbuf_get_height (pixbuf); - if (*file != '\0') + int target_width = target->szHint.width; + int target_height = target->szHint.height; + int new_pmap_width = target_width; + int new_pmap_height = target_height; + + int x = 0; + int y = 0; + int w = h_scale * target_width / 100; + int h = v_scale * target_height / 100; + + if (h_align == rootAlign || v_align == rootAlign) { -# ifdef HAVE_AFTERIMAGE - if (target->asimman == NULL) - target->asimman = create_generic_imageman (target->rs[Rs_path]); - if ((f = strchr (file, ';')) == NULL) - original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); + target->get_window_origin (x, y); + x = -x; + y = -y; + } + + if (h_align != rootAlign) + x = make_align_position (h_align, target_width, w > 0 ? w : image_width); + + if (v_align != rootAlign) + y = make_align_position (v_align, target_height, h > 0 ? h : image_height); + + if (x >= target_width + || y >= target_height + || (w > 0 && x + w <= 0) + || (h > 0 && y + h <= 0)) + return false; + + result = pixbuf; + + if ((w > 0 && w != image_width) + || (h > 0 && h != image_height)) + { + result = gdk_pixbuf_scale_simple (pixbuf, + w > 0 ? w : image_width, + h > 0 ? h : image_height, + GDK_INTERP_BILINEAR); + } + + bool ret = false; + + if (result) + { + XGCValues gcv; + GC gc; + + image_width = gdk_pixbuf_get_width (result); + image_height = gdk_pixbuf_get_height (result); + + if (h_scale == 0) + new_pmap_width = min (image_width, target_width); + if (v_scale == 0) + new_pmap_height = min (image_height, target_height); + + if (pixmap) + { + if (pmap_width != new_pmap_width + || pmap_height != new_pmap_height + || pmap_depth != target->depth) + { + XFreePixmap (target->dpy, pixmap); + pixmap = None; + } + } + + if (pixmap == None) + { + pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); + pmap_width = new_pmap_width; + pmap_height = new_pmap_height; + pmap_depth = target->depth; + } + + gcv.foreground = target->pix_colors[Color_bg]; + gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); + + if (h_scale == 0 || v_scale == 0) + { + Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); + gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, + 0, 0, + 0, 0, + image_width, image_height, + XLIB_RGB_DITHER_NONE, + 0, 0); + + gcv.tile = tile; + gcv.fill_style = FillTiled; + gcv.ts_x_origin = x; + gcv.ts_y_origin = y; + XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); + + XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); + XFreePixmap (target->dpy, tile); + } else { - size_t len = f - file; - f = (char *)malloc (len + 1); - strncpy (f, file, len); + int src_x, src_y, dst_x, dst_y; + int dst_width, dst_height; + + src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); + src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); + + if (dst_x > 0 || dst_y > 0 + || dst_x + dst_width < new_pmap_width + || dst_y + dst_height < new_pmap_height) + XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); + + if (dst_x < new_pmap_width && dst_y < new_pmap_height) + gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, + src_x, src_y, + dst_x, dst_y, + dst_width, dst_height, + XLIB_RGB_DITHER_NONE, + 0, 0); + } + + if (result != pixbuf) + g_object_unref (result); + + XFreeGC (target->dpy, gc); + + ret = true; + } + + return ret; +} +# endif /* HAVE_PIXBUF */ + +bool +bgPixmap_t::set_file (const char *file) +{ + assert (file); + + if (*file) + { + if (const char *p = strchr (file, ';')) + { + size_t len = p - file; + char *f = rxvt_temp_buf (len + 1); + memcpy (f, file, len); f[len] = '\0'; - original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); - free (f); + file = f; } - return (original_asim != NULL); + +# ifdef HAVE_AFTERIMAGE + if (!target->asimman) + target->asimman = create_generic_imageman (target->rs[Rs_path]); + original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); + if (original_asim) + have_image = true; + return have_image; +# endif + +# ifdef HAVE_PIXBUF + pixbuf = gdk_pixbuf_new_from_file (file, NULL); + if (pixbuf) + have_image = true; + return have_image; # endif } + return false; } -# endif /* BG_IMAGE_FROM_FILE */ +# endif /* BG_IMAGE_FROM_FILE */ # ifdef ENABLE_TRANSPARENCY bool @@ -632,6 +911,7 @@ flags |= isTransparent; return true; } + return false; } @@ -643,9 +923,9 @@ int junk; int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); - if (!(geom_flags&WidthValue)) + if (!(geom_flags & WidthValue)) hr = 1; - if (!(geom_flags&HeightValue)) + if (!(geom_flags & HeightValue)) vr = hr; if (h_blurRadius != hr) @@ -665,7 +945,7 @@ else flags |= blurNeeded; - return (changed>0); + return (changed > 0); } static inline unsigned long @@ -692,9 +972,9 @@ { if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) - { - flags |= bgPixmap_t::tintNeeded; - } + { + flags |= bgPixmap_t::tintNeeded; + } } if (flags & bgPixmap_t::tintNeeded) @@ -722,6 +1002,7 @@ flags = (flags & ~tintFlags) | new_flags | tintSet; return true; } + return false; } @@ -732,9 +1013,10 @@ if (new_flags != (flags & tintFlags)) { - flags = (flags&~tintFlags)|new_flags; - return true; + flags = (flags & ~tintFlags) | new_flags; + return true; } + return false; } @@ -744,7 +1026,7 @@ int new_shade = (shade_str) ? atoi (shade_str) : 0; if (new_shade < 0 && new_shade > -100) - new_shade = 200 - (100 + new_shade); + new_shade = 200 - (100 + new_shade); else if (new_shade == 100) new_shade = 0; @@ -755,6 +1037,7 @@ flags = (flags & (~tintFlags | tintSet)) | new_flags; return true; } + return false; } @@ -771,7 +1054,7 @@ if (target == NULL) return 0; - /* root dimentions may change from call to call - but Display structure should + /* root dimensions may change from call to call - but Display structure should * be always up-to-date, so let's use it : */ Window root = target->display->root; @@ -794,7 +1077,8 @@ return 0; if (root_pixmap != None) - {/* we want to validate the pixmap and get it's size at the same time : */ + { + /* we want to validate the pixmap and get it's size at the same time : */ int junk; unsigned int ujunk; /* root pixmap may be bad - allow a error */ @@ -813,7 +1097,8 @@ return 0; if (root_pixmap == None) - { /* use tricks to obtain the root background image :*/ + { + /* use tricks to obtain the root background image :*/ /* we want to create Overrideredirect window overlapping out window with background type of Parent Relative and then grab it */ XSetWindowAttributes attr; @@ -824,7 +1109,7 @@ attr.backing_store = Always; attr.event_mask = ExposureMask; attr.override_redirect = True; - src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, + src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, &attr); @@ -838,12 +1123,13 @@ XSync (dpy, False); /* XSync should get window where it's properly exposed, - * but to be on the safe side - let's check for the actuall event to arrive : */ + * but to be on the safe side - let's check for the actual event to arrive : */ while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) ++ev_count; if (ev_count > 0); - { /* hooray! - we can grab the image! */ + { + /* hooray! - we can grab the image! */ gc = XCreateGC (dpy, root, 0, NULL); if (gc) { @@ -851,21 +1137,23 @@ success = true; } } + XDestroyWindow (dpy, src); XUngrabServer (dpy); //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); } - if (!success) - { - XFreePixmap (dpy, tiled_root_pmap); - tiled_root_pmap = None; - } - else - result |= transpPmapTiled; + if (!success) + { + XFreePixmap (dpy, tiled_root_pmap); + tiled_root_pmap = None; + } + else + result |= transpPmapTiled; } else - {/* strightforward pixmap copy */ + { + /* straightforward pixmap copy */ gcv.tile = root_pixmap; gcv.fill_style = FillTiled; @@ -923,7 +1211,7 @@ c.g = (c.g * shade) / 100; c.b = (c.b * shade) / 100; } - else if( shade > 100 && shade < 200) + else if (shade > 100 && shade < 200) { c.r = (c.r * (200 - shade)) / 100; c.g = (c.g * (200 - shade)) / 100; @@ -979,6 +1267,7 @@ XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); result |= transpPmapTinted; } + XRenderFreePicture (dpy, mask_pic); XRenderFreePicture (dpy, overlay_pic); XRenderFreePicture (dpy, back_pic); @@ -987,7 +1276,7 @@ # endif # endif } - } + } } /* server side rendering completed */ if (pixmap) @@ -1010,9 +1299,7 @@ bool bgPixmap_t::set_root_pixmap () { - Pixmap new_root_pixmap = None; - - new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); + Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); if (new_root_pixmap == None) new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); @@ -1021,15 +1308,15 @@ root_pixmap = new_root_pixmap; return true; } + return false; } # endif /* ENABLE_TRANSPARENCY */ # ifndef HAVE_AFTERIMAGE -static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); +static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); # endif - bool bgPixmap_t::render () { @@ -1040,7 +1327,7 @@ TIMING_TEST_START (tp); - invalidate(); + invalidate (); # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) { @@ -1049,80 +1336,44 @@ if (background_flags == 0) return false; else if ((background_flags & transpTransformations) == (flags & transpTransformations) - && pmap_depth == target->depth) + && pmap_depth == target->depth) flags = flags & ~isInvalid; } # endif - XImage *result = NULL; -# ifdef HAVE_AFTERIMAGE - if (original_asim +# ifdef BG_IMAGE_FROM_FILE + if (have_image || (background_flags & transpTransformations) != (flags & transpTransformations)) { - ASImage *background = NULL; - ARGB32 as_tint = TINT_LEAVE_SAME; - if (background_flags) - background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); - -# ifdef ENABLE_TRANSPARENCY - if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) - { - ShadingInfo as_shade; - as_shade.shading = (shade == 0) ? 100 : shade; - - rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); - if (flags & tintSet) - tint.get (c); - as_shade.tintColor.red = c.r; - as_shade.tintColor.green = c.g; - as_shade.tintColor.blue = c.b; - - as_tint = shading2tint32 (&as_shade); - } - if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) - { - ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, - (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, - 100, ASIMAGE_QUALITY_DEFAULT); - if (tmp) - { - destroy_asimage (&background); - background = tmp; - } - } -# endif - - if (render_asim (background, as_tint)) + if (render_image (background_flags)) flags = flags & ~isInvalid; - if (background) - destroy_asimage (&background); } - else if (background_flags && pmap_depth != target->depth) - { - result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); - } - -# elif !XFT /* our own client-side tinting */ +# endif - /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side. - This may need to be changed in need_client_side_rendering() logic is altered !!! */ + XImage *result = NULL; if (background_flags && (flags & isInvalid)) { result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); - if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) + } + + if (result) + { +# if !defined(HAVE_AFTERIMAGE) && !XFT + /* our own client-side tinting */ + /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. + This may need to be changed in need_client_side_rendering() logic is altered !!! */ + if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) { rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); if (flags & tintSet) tint.get (c); ShadeXImage (target, result, shade, c.r, c.g, c.b); } - } -# endif /* HAVE_AFTERIMAGE */ +# endif - if (result != NULL) - { GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); + if (gc) { if (/*pmap_depth != target->depth &&*/ pixmap != None) @@ -1130,30 +1381,36 @@ XFreePixmap (target->dpy, pixmap); pixmap = None; } + if (pixmap == None) { pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); - pmap_width = result->width; + pmap_width = result->width; pmap_height = result->height; - pmap_depth = target->depth; + pmap_depth = target->depth; } + if (pmap_depth != result->depth) - { /* Bad Match error will ensue ! stupid X !!!! */ - if( result->depth == 24 && pmap_depth == 32) + { + /* Bad Match error will ensue ! stupid X !!!! */ + if (result->depth == 24 && pmap_depth == 32) result->depth = 32; - else if( result->depth == 32 && pmap_depth == 24) + else if (result->depth == 32 && pmap_depth == 24) result->depth = 24; else { /* TODO: implement image recoding */ } } + if (pmap_depth == result->depth) XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); + XFreeGC (target->dpy, gc); flags = flags & ~isInvalid; } - XDestroyImage (result); + + XDestroyImage (result); } if (flags & isInvalid) @@ -1167,6 +1424,9 @@ apply (); + XSync (target->dpy, False); + valid_since = ev::now (); + TIMING_TEST_PRINT_RESULT (tp); return true; @@ -1184,26 +1444,28 @@ # endif return true; } + return false; } void -bgPixmap_t::apply() +bgPixmap_t::apply () { if (target) { flags &= ~isVtOrigin; + if (pixmap != None) - { /* set target's background to pixmap */ + { + /* set target's background to pixmap */ # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) { XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); -# if HAVE_SCROLLBARS + if (target->scrollBar.win) XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); -# endif } else # endif @@ -1213,40 +1475,37 @@ XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); /* do we also need to set scrollbar's background here ? */ -# if HAVE_SCROLLBARS + if (target->scrollBar.win) - XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); -# endif + XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); } } else - { /* set target background to a pixel */ + { + /* set target background to a pixel */ XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); /* do we also need to set scrollbar's background here ? */ -# if HAVE_SCROLLBARS if (target->scrollBar.win) - XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); -# endif + XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); } + /* don't want Expose on the parent or vt. It is better to use scr_touch or we get a great deal of flicker otherwise: */ XClearWindow (target->dpy, target->parent[0]); -# if HAVE_SCROLLBARS - if (target->scrollBar.win) + if (target->scrollBar.state && target->scrollBar.win) { - target->scrollBar.setIdle (); - target->scrollbar_show (0); + target->scrollBar.state = STATE_IDLE; + target->scrollBar.show (0); } -# endif target->want_refresh = 1; flags |= hasChanged; } } -#endif /* HAVE_BG_PIXMAP */ +#endif /* HAVE_BG_PIXMAP */ #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT /* taken from aterm-0.4.2 */ @@ -1254,7 +1513,7 @@ typedef uint32_t RUINT32T; static void -ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) +ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) { int sh_r, sh_g, sh_b; RUINT32T mask_r, mask_g, mask_b;