--- rxvt-unicode/src/background.C 2007/11/15 11:36:15 1.12 +++ rxvt-unicode/src/background.C 2008/01/05 13:52:23 1.23 @@ -3,9 +3,6 @@ *----------------------------------------------------------------------* * * 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 * @@ -30,6 +27,7 @@ #define DO_TIMING_TEST 0 #if DO_TIMING_TEST +# include #define TIMING_TEST_START(id) \ struct timeval timing_test_##id##_stv;\ gettimeofday (&timing_test_##id##_stv, NULL); @@ -89,7 +87,7 @@ */ #ifdef HAVE_BG_PIXMAP -bgPixmap_t::bgPixmap_t() +bgPixmap_t::bgPixmap_t () { #ifdef HAVE_AFTERIMAGE original_asim = NULL; @@ -100,14 +98,17 @@ #endif flags = 0; pixmap = None; + valid_since = invalid_since = 0; } -bgPixmap_t::~bgPixmap_t() +void +bgPixmap_t::destroy () { #ifdef HAVE_AFTERIMAGE if (original_asim) safe_asimage_destroy (original_asim); #endif + if (pixmap && target) XFreePixmap (target->dpy, pixmap); } @@ -115,6 +116,11 @@ 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) @@ -125,12 +131,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 () { @@ -174,10 +198,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; @@ -232,7 +259,7 @@ unsigned int n; unsigned long new_flags = (flags & (~geometryFlags)); char *p; -# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ +# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ if (geom == NULL) return false; @@ -279,7 +306,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) @@ -305,14 +333,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) @@ -325,7 +355,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; } @@ -341,14 +372,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; @@ -356,29 +387,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,7 +438,7 @@ flags = new_flags; changed++; } -//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", +//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", // flags, h_scale, v_scale, h_align, v_align); return (changed > 0); } @@ -427,8 +464,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 @@ -467,18 +512,21 @@ 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, + new_pmap_width, + new_pmap_height, TINT_LEAVE_SAME, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) @@ -490,7 +538,8 @@ } } 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; @@ -500,13 +549,15 @@ 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; } @@ -731,6 +782,7 @@ flags = (flags & ~tintFlags) | new_flags | tintSet; return true; } + return false; } @@ -744,6 +796,7 @@ flags = (flags&~tintFlags)|new_flags; return true; } + return false; } @@ -753,7 +806,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; @@ -764,6 +817,7 @@ flags = (flags & (~tintFlags | tintSet)) | new_flags; return true; } + return false; } @@ -803,7 +857,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 */ @@ -822,7 +877,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; @@ -847,12 +903,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) { @@ -860,6 +917,7 @@ success = true; } } + XDestroyWindow (dpy, src); XUngrabServer (dpy); //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); @@ -874,7 +932,8 @@ result |= transpPmapTiled; } else - {/* strightforward pixmap copy */ + { + /* strightforward pixmap copy */ gcv.tile = root_pixmap; gcv.fill_style = FillTiled; @@ -932,7 +991,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; @@ -988,6 +1047,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); @@ -1019,9 +1079,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); @@ -1030,6 +1088,7 @@ root_pixmap = new_root_pixmap; return true; } + return false; } # endif /* ENABLE_TRANSPARENCY */ @@ -1038,7 +1097,6 @@ static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); # endif - bool bgPixmap_t::render () { @@ -1129,9 +1187,10 @@ } # endif /* HAVE_AFTERIMAGE */ - if (result != NULL) + if (result) { GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); + if (gc) { if (/*pmap_depth != target->depth &&*/ pixmap != None) @@ -1139,29 +1198,35 @@ 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); } @@ -1176,6 +1241,9 @@ apply (); + XSync (target->dpy, False); + valid_since = ev::now (); + TIMING_TEST_PRINT_RESULT (tp); return true; @@ -1197,13 +1265,14 @@ } 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) { @@ -1229,7 +1298,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 ? */