--- rxvt-unicode/src/background.C 2008/01/05 13:52:23 1.23 +++ rxvt-unicode/src/background.C 2010/07/26 09:57:53 1.39 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * 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 @@ -29,7 +29,7 @@ #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) \ @@ -89,6 +89,8 @@ #ifdef HAVE_BG_PIXMAP 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 @@ -99,6 +101,7 @@ flags = 0; pixmap = None; valid_since = invalid_since = 0; + target = 0; } void @@ -123,7 +126,7 @@ # ifdef BG_IMAGE_FROM_FILE # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) # endif { if (h_scale != 0 || v_scale != 0 @@ -135,8 +138,8 @@ return false; } -bool -bgPixmap_t::window_position_sensitive () +bool +bgPixmap_t::window_position_sensitive () { # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) @@ -145,7 +148,7 @@ # ifdef BG_IMAGE_FROM_FILE # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) # endif { if (h_align == rootAlign || v_align == rootAlign) @@ -159,7 +162,7 @@ bool bgPixmap_t::need_client_side_rendering () { # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) return true; # endif # ifdef ENABLE_TRANSPARENCY @@ -258,7 +261,7 @@ unsigned int w = 0, h = 0; unsigned int n; unsigned long new_flags = (flags & (~geometryFlags)); - char *p; + const char *p; # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ if (geom == NULL) @@ -276,7 +279,7 @@ char *ops; new_flags |= geometrySet; - strncpy (str, geom, n); + memcpy (str, geom, n); str[n] = '\0'; if (str[0] == ':') ops = &str[0]; @@ -369,13 +372,14 @@ 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 = noScale; geom_flags |= WidthValue|HeightValue; } - else if (CHECK_GEOM_OPS("propscale")) + else if (CHECK_GEOM_OPS ("propscale")) { if (w == 0 && h == 0) { @@ -384,53 +388,49 @@ } new_flags |= propScale; } - else if (CHECK_GEOM_OPS("hscale")) + else if (CHECK_GEOM_OPS ("hscale")) { - if (w == 0) - w = windowScale; + 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 = windowScale; + 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 = windowScale; - if (w == 0) - w = windowScale; + 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 = windowScale; x = y = centerAlign; geom_flags |= WidthValue|HeightValue|XValue|YValue; } - else if (CHECK_GEOM_OPS("root")) + 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) @@ -438,6 +438,7 @@ flags = new_flags; changed++; } + //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", // flags, h_scale, v_scale, h_align, v_align); return (changed > 0); @@ -450,10 +451,14 @@ 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 *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; @@ -470,13 +475,15 @@ 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) @@ -487,9 +494,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) @@ -502,6 +510,7 @@ else { result = original_asim; + if ((w > 0 && w != original_asim->width) || (h > 0 && h != original_asim->height)) { @@ -511,6 +520,7 @@ background ? ASA_ASImage : ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); } + if (background == NULL) { /* if tiling - pixmap has to be sized exactly as the image, @@ -523,16 +533,17 @@ 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, - new_pmap_width, - new_pmap_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; } } @@ -548,6 +559,7 @@ layers[0].clip_height = target_height; layers[0].tint = background_tint; layers[1].im = result; + if (w <= 0) { /* tile horizontally */ @@ -561,6 +573,7 @@ layers[1].dst_x = x; layers[1].clip_width = result->width; } + if (h <= 0) { while (y > 0) y -= (int)result->height; @@ -572,20 +585,25 @@ 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); } } @@ -624,17 +642,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 */ @@ -655,29 +669,30 @@ bool bgPixmap_t::set_file (const char *file) { - char *f; - - assert (file != NULL); + assert (file); - if (*file != '\0') + if (*file) { # ifdef HAVE_AFTERIMAGE - if (target->asimman == NULL) + if (!target->asimman) target->asimman = create_generic_imageman (target->rs[Rs_path]); - if ((f = strchr (file, ';')) == NULL) - original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); - else + + if (const char *p = strchr (file, ';')) { - size_t len = f - file; - f = (char *)malloc (len + 1); - strncpy (f, file, len); + size_t len = p - file; + char *f = (char *)malloc (len + 1); + memcpy (f, file, len); f[len] = '\0'; original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); free (f); } - return (original_asim != NULL); + else + original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); + + return original_asim; # endif } + return false; } @@ -692,6 +707,7 @@ flags |= isTransparent; return true; } + return false; } @@ -834,7 +850,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; @@ -933,7 +949,7 @@ } else { - /* strightforward pixmap copy */ + /* straightforward pixmap copy */ gcv.tile = root_pixmap; gcv.fill_style = FillTiled; @@ -1094,7 +1110,7 @@ # 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 @@ -1107,7 +1123,7 @@ TIMING_TEST_START (tp); - invalidate(); + invalidate (); # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) { @@ -1126,10 +1142,12 @@ if (original_asim || (background_flags & transpTransformations) != (flags & transpTransformations)) { + target->init_asv (); + 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); + background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); # ifdef ENABLE_TRANSPARENCY if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) @@ -1146,9 +1164,10 @@ 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, + 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) @@ -1162,21 +1181,20 @@ if (render_asim (background, as_tint)) flags = flags & ~isInvalid; if (background) - destroy_asimage (&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); - } + result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); # elif !XFT /* our own client-side tinting */ - /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side. + /* 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 && (flags & isInvalid)) { result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); + if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) { rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); @@ -1261,6 +1279,7 @@ # endif return true; } + return false; } @@ -1270,6 +1289,7 @@ if (target) { flags &= ~isVtOrigin; + if (pixmap != None) { /* set target's background to pixmap */ @@ -1278,10 +1298,9 @@ { 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 @@ -1291,10 +1310,9 @@ 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 @@ -1303,22 +1321,19 @@ 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; @@ -1333,7 +1348,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;