--- rxvt-unicode/src/background.C 2007/09/12 20:29:24 1.1 +++ rxvt-unicode/src/background.C 2007/11/26 11:20:13 1.16 @@ -1,11 +1,8 @@ /*----------------------------------------------------------------------* - * File: background.C - former xmp.C + * File: background.C - former xpm.C *----------------------------------------------------------------------* * * 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) 2007 Sasha Vasko * @@ -33,7 +30,7 @@ #define TIMING_TEST_START(id) \ 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__,\ @@ -89,10 +86,40 @@ */ #ifdef HAVE_BG_PIXMAP +bgPixmap_t::bgPixmap_t () +{ +#ifdef HAVE_AFTERIMAGE + original_asim = NULL; +#endif +#ifdef BG_IMAGE_FROM_FILE + h_scale = v_scale = 0; + h_align = v_align = 0; +#endif + flags = 0; + pixmap = None; +} + +void +bgPixmap_t::destroy () +{ +#ifdef HAVE_AFTERIMAGE + if (original_asim) + safe_asimage_destroy (original_asim); +#endif + + if (pixmap && target) + XFreePixmap (target->dpy, pixmap); +} + bool bgPixmap_t::window_size_sensitive () { -# ifdef XPM_BACKGROUND +# ifdef ENABLE_TRANSPARENCY + if (flags & isTransparent) + return true; +# endif + +# ifdef BG_IMAGE_FROM_FILE # ifdef HAVE_AFTERIMAGE if (original_asim != NULL) # endif @@ -102,12 +129,30 @@ 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 +# ifdef HAVE_AFTERIMAGE + if (original_asim != NULL) +# endif + { + if (h_align == rootAlign || v_align == rootAlign) + return true; + } +# endif + return false; -} +}; bool bgPixmap_t::need_client_side_rendering () { @@ -118,15 +163,18 @@ # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) { - if (((flags & blurNeeded) && !(flags & blurServerSide)) - || ((flags & tintNeeded) && !(flags & tintServerSide))) - return true; +# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways + if ((flags & blurNeeded) && !(flags & blurServerSide)) + return true; +# endif + if ((flags & tintNeeded) && !(flags & tintServerSide)) + return true; } # endif return false; } -# ifdef XPM_BACKGROUND +# ifdef BG_IMAGE_FROM_FILE static inline bool check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) { @@ -148,10 +196,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; @@ -299,11 +350,12 @@ } } /* done parsing geometry string */ else if (!(flags & geometrySet)) - { /* default geometry - scaled and centered */ + { + /* default geometry - scaled and centered */ x = y = defaultAlign; w = h = defaultScale; } - + if (!(flags & geometrySet)) geom_flags |= WidthValue|HeightValue|XValue|YValue; @@ -315,14 +367,14 @@ # 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")) { if (w == 0 && h == 0) { - w = 100; + w = windowScale; geom_flags |= WidthValue; } new_flags |= propScale; @@ -330,29 +382,35 @@ else if (CHECK_GEOM_OPS("hscale")) { if (w == 0) - w = 100; - h = 0; + w = windowScale; + h = noScale; geom_flags |= WidthValue|HeightValue; } else if (CHECK_GEOM_OPS("vscale")) { if (h == 0) - h = 100; - w = 0; + h = windowScale; + w = noScale; geom_flags |= WidthValue|HeightValue; } else if (CHECK_GEOM_OPS("scale")) { if (h == 0) - h = 100; + h = windowScale; if (w == 0) - w = 100; + w = windowScale; geom_flags |= WidthValue|HeightValue; } 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 @@ -401,8 +459,16 @@ 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 @@ -434,25 +500,27 @@ if ((w > 0 && w != original_asim->width) || (h > 0 && h != original_asim->height)) { - result = scale_asimage (target->asv, original_asim, - w > 0 ? w : original_asim->width, + result = scale_asimage (target->asv, original_asim, + w > 0 ? w : original_asim->width, h > 0 ? h : original_asim->height, 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 then 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, + (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) @@ -563,7 +631,7 @@ /* put result on pixmap */ if (dst_x < new_pmap_width && dst_y < new_pmap_height) asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); - + if (result != background && result != original_asim) destroy_asimage (&result); @@ -599,15 +667,15 @@ free (f); } return (original_asim != NULL); -# endif +# endif } return false; } -# endif /* XPM_BACKGROUND */ +# endif /* BG_IMAGE_FROM_FILE */ # ifdef ENABLE_TRANSPARENCY -bool +bool bgPixmap_t::set_transparent () { if (!(flags & isTransparent)) @@ -642,7 +710,7 @@ ++changed; v_blurRadius = vr; } - + if (v_blurRadius == 0 && h_blurRadius == 0) flags &= ~blurNeeded; else @@ -656,19 +724,20 @@ { unsigned long flags = 0; rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); + bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); if (tint) { tint->get (c); # define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) - if (IS_COMPONENT_WHOLESOME (c.r) + if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) && IS_COMPONENT_WHOLESOME (c.g) && IS_COMPONENT_WHOLESOME (c.b)) flags |= bgPixmap_t::tintWholesome; # undef IS_COMPONENT_WHOLESOME } - if ((shade > 0 && shade < 100) || (shade > 100 && shade < 200)) + if (has_shade) flags |= bgPixmap_t::tintNeeded; else if (tint) { @@ -678,14 +747,17 @@ flags |= bgPixmap_t::tintNeeded; } } - + if (flags & bgPixmap_t::tintNeeded) { if (flags & bgPixmap_t::tintWholesome) flags |= bgPixmap_t::tintServerSide; + else + { #if XFT - flags |= bgPixmap_t::tintServerSide; + flags |= bgPixmap_t::tintServerSide; #endif + } } return flags; @@ -722,22 +794,24 @@ { int new_shade = (shade_str) ? atoi (shade_str) : 0; - if (new_shade == 100) + if (new_shade < 0 && new_shade > -100) + new_shade = 200 - (100 + new_shade); + else if (new_shade == 100) new_shade = 0; if (new_shade != shade) { unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); shade = new_shade; - flags = (flags & ~tintFlags) | new_flags; + flags = (flags & (~tintFlags | tintSet)) | new_flags; return true; } return false; } -/* make_transparency_pixmap() +/* make_transparency_pixmap() * Builds a pixmap sized the same as terminal window, with depth same as the root window - * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by + * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by * our window. */ unsigned long @@ -790,7 +864,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; @@ -820,7 +895,8 @@ ++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) { @@ -846,8 +922,8 @@ gcv.tile = root_pixmap; gcv.fill_style = FillTiled; - while (sx < 0) sx += (int)window_width; - while (sy < 0) sy += (int)window_height; + while (sx < 0) sx += (int)root_width; + while (sy < 0) sy += (int)root_height; gcv.ts_x_origin = -sx; gcv.ts_y_origin = -sy; @@ -863,9 +939,9 @@ if (tiled_root_pmap != None) { - if (!need_client_side_rendering ()) + if (!need_client_side_rendering ()) { - if ((flags & tintNeeded)) + if ((flags & tintNeeded)) { if (flags & tintWholesome) { @@ -916,14 +992,14 @@ pf.direct.alphaMask = 0xff; XRenderPictFormat *solid_format = XRenderFindFormat (dpy, - (PictFormatType| - PictFormatDepth| - PictFormatRedMask| - PictFormatGreenMask| - PictFormatBlueMask| - PictFormatAlphaMask), - &pf, - 0); + (PictFormatType| + PictFormatDepth| + PictFormatRedMask| + PictFormatGreenMask| + PictFormatBlueMask| + PictFormatAlphaMask), + &pf, + 0); XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); XRenderPictureAttributes pa ; @@ -935,7 +1011,7 @@ Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); XFreePixmap (dpy, overlay_pmap); - pa.component_alpha = True; + pa.component_alpha = True; Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); XFreePixmap (dpy, mask_pmap); @@ -947,37 +1023,21 @@ memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); mask_c.alpha = 0xffff; XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); - memset (&mask_c, 0x0, sizeof (mask_c)); - mask_c.alpha = 0; - if (c.r == c.b && c.b == c.g) /* pure shading */ - { - mask_c.red = mask_c.green = mask_c.blue = 0xffff - c.r; - XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); - XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); - } - else - { - mask_c.red = 0xffff - c.r; - XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); - XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); - mask_c.red = 0; - mask_c.green = 0xffff - c.g; - XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); - XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); - mask_c.green = 0; - mask_c.blue = 0xffff - c.b; - XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); - XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); - } - result |= transpPmapTinted; + mask_c.alpha = 0; + mask_c.red = 0xffff - c.r; + mask_c.green = 0xffff - c.g; + mask_c.blue = 0xffff - c.b; + XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); + 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); # if DO_TIMING_TEST XSync (dpy, False); -# endif +# endif # endif } } @@ -991,20 +1051,20 @@ pmap_height = window_height; pmap_depth = root_depth; } - + if (gc) XFreeGC (dpy, gc); TIMING_TEST_PRINT_RESULT (tp); - - return result; + + return result; } bool bgPixmap_t::set_root_pixmap () { Pixmap new_root_pixmap = None; - + 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); @@ -1031,6 +1091,8 @@ if (target == NULL) return false; + TIMING_TEST_START (tp); + invalidate(); # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) @@ -1092,7 +1154,12 @@ { result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); } -# else /* our own client-side tinting */ + +# elif !XFT /* our own client-side tinting */ + + /* 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 !!! */ + if (background_flags && (flags & isInvalid)) { result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); @@ -1124,7 +1191,8 @@ pmap_depth = target->depth; } if (pmap_depth != result->depth) - { /* Bad Match error will ensue ! stupid X !!!! */ + { + /* 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) @@ -1153,10 +1221,12 @@ apply (); - return true; + TIMING_TEST_PRINT_RESULT (tp); + + return true; } -bool +bool bgPixmap_t::set_target (rxvt_term *new_target) { if (new_target) @@ -1178,7 +1248,8 @@ { flags &= ~isVtOrigin; if (pixmap != None) - { /* set target's background to pixmap */ + { + /* set target's background to pixmap */ # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) { @@ -1204,7 +1275,8 @@ } } 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 ? */ @@ -1213,11 +1285,9 @@ XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); # endif } - - /* don't want Expose on the parent */ - XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); - /* do want Expose on the vt, so we get refreshed properly */ - XClearArea (target->dpy, target->vt, 0, 0, 0, 0, True); + /* 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) @@ -1226,12 +1296,15 @@ 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) +#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT /* taken from aterm-0.4.2 */ typedef uint32_t RUINT32T;