--- rxvt-unicode/src/xpm.C 2007/08/06 22:42:05 1.60 +++ rxvt-unicode/src/xpm.C 2007/08/09 22:08:21 1.64 @@ -74,23 +74,23 @@ bool bgPixmap_t::window_size_sensitive () { -#ifdef XPM_BACKGROUND -#ifdef HAVE_AFTERIMAGE +# ifdef XPM_BACKGROUND +# ifdef HAVE_AFTERIMAGE if (original_asim != NULL) -#endif +# endif { if (h_scale != 0 || v_scale != 0) return true; } -#endif -#ifdef ENABLE_TRANSPARENCY +# endif +# ifdef ENABLE_TRANSPARENCY if (flags & bgPmap_Transparent) return true; -#endif +# endif return false; } -#ifdef XPM_BACKGROUND +# ifdef XPM_BACKGROUND static inline bool check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) { @@ -134,7 +134,7 @@ if (align >= 0 && align <= 50) return diff * align / 100; else if (align > 50 && align <= 100) - return window_size - image_size + diff * align / 100; + return window_size - image_size - diff * (100 - align) / 100; else if (align > 100 && align <= 200 ) return ((align - 100) * smaller / 100) + window_size - smaller; else if (align > -100 && align < 0) @@ -142,26 +142,23 @@ return 0; } -static inline void -make_clip_rectangle (int pos, int size, int target_size, int &clip_pos, int &clip_size) +static inline int +make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) { - if (size <= 0) - { /* special case - tiling */ - clip_pos = pos; - clip_size = target_size; - } - else if (pos < 0) - { - clip_pos = 0; - clip_size = MIN (target_size, size + pos); - } - else - { - clip_pos = pos; - clip_size = size; - if (pos < target_size && (int)clip_size > target_size - pos) - clip_pos = target_size - pos; - } + int src_pos = 0; + dst_pos = 0; + dst_size = size; + if (pos < 0 && size > target_size) + { + src_pos = -pos; + dst_size += pos; + } + else if (pos > 0) + dst_pos = pos; + + if (dst_pos + dst_size > target_size) + dst_size = target_size - dst_pos; + return src_pos; } bool @@ -173,7 +170,7 @@ unsigned int n; unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); char *p; -#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ +# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ if (geom == NULL) return false; @@ -182,12 +179,13 @@ if (!strcmp (geom, "?")) { -#if 0 /* TODO: */ - sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ - min (h_scale, 32767), min (v_scale, 32767), - min (h_align, 32767), min (v_align, 32767)); - process_xterm_seq (XTerm_title, str, CHAR_ST); -#endif + if (target) + { + sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ + min (h_scale, 32767), min (v_scale, 32767), + min (h_align, 32767), min (v_align, 32767)); + target->process_xterm_seq (XTerm_title, str, CHAR_ST); + } return false; } while (isspace(*geom)) ++geom; @@ -269,16 +267,16 @@ else if (geom_flags & WidthValue) { if (!(geom_flags & HeightValue)) - h = w; + h = w; } else - w = h; + w = h; } } /* done parsing geometry string */ else if (!(flags & bgPmap_geometrySet)) { /* default geometry - scaled and centered */ - x = y = bgPmap_defaultAlign; - w = h = bgPmap_defaultScale; + x = y = bgPmap_defaultAlign; + w = h = bgPmap_defaultScale; } if (!(flags & bgPmap_geometrySet)) @@ -289,7 +287,7 @@ while (*ops) { while (*ops == ':' || isspace(*ops)) ++ops; -#define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) +# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) if (CHECK_GEOM_OPS("tile")) { w = h = 0; @@ -332,7 +330,7 @@ x = y = 50; geom_flags |= WidthValue|HeightValue|XValue|YValue; } -#undef CHECK_GEOM_OPS +# undef CHECK_GEOM_OPS while (*ops != ':' && *ops != '\0') ++ops; } /* done parsing ops */ } @@ -357,9 +355,9 @@ return (changed > 0); } -#ifdef HAVE_AFTERIMAGE +# ifdef HAVE_AFTERIMAGE bool -bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) +bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) { if (target == NULL) return false; @@ -380,25 +378,28 @@ y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); } - int dst_x, dst_y; - int clip_width, clip_height; - - make_clip_rectangle (x, w, target_width, dst_x, clip_width); - make_clip_rectangle (y, h, target_height, dst_y, clip_height); - - /* TODO : actuall scaling code :) */ - if (dst_x >= target_width || dst_y >= target_height - || clip_width <= 0 || clip_height <= 0 || original_asim == NULL) + if (original_asim == NULL + || x >= target_width + || y >= target_height + || (w > 0 && x + w <= 0) + || (h > 0 && y + h <= 0)) { - result = background; - dst_x = dst_y = 0; if (background) { - new_pmap_width = clip_width = background->width; - new_pmap_height = clip_height = background->height; + 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, + target_width, target_height, background_tint, + ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); + if (tmp) + result = tmp; + } } else - new_pmap_width = new_pmap_height = 0; + new_pmap_width = new_pmap_height = 0; } else { @@ -418,6 +419,22 @@ new_pmap_width = result->width; if (v_scale == 0) new_pmap_height = result->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); + 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 */ @@ -431,23 +448,25 @@ layers[1].im = result; if (w <= 0) {/* tile horizontally */ - layers[1].dst_x = dst_x - (int)result->width; - layers[1].clip_width = result->width; + while (x > 0) x -= (int)result->width; + layers[1].dst_x = x; + layers[1].clip_width = result->width+target_width; } else {/* clip horizontally */ - layers[1].dst_x = dst_x; - layers[1].clip_width = clip_width; + layers[1].dst_x = x; + layers[1].clip_width = result->width; } if (h <= 0) { - layers[1].dst_y = dst_y - (int)result->height; - layers[1].clip_height = result->height; + while (y > 0) y -= (int)result->height; + layers[1].dst_y = y; + layers[1].clip_height = result->height + target_height; } else { - layers[1].dst_y = dst_y; - layers[1].clip_height = clip_height; + layers[1].dst_y = y; + layers[1].clip_height = result->height; } if (target->rs[Rs_blendtype]) { @@ -462,9 +481,6 @@ if (result != original_asim) destroy_asimage (&result); result = tmp; - dst_x = dst_y = 0; - clip_width = target_width; - clip_height = target_height; } free (layers); } @@ -499,112 +515,57 @@ gcv.foreground = target->pix_colors[Color_bg]; gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); - if (dst_x > 0 || dst_y > 0 - || dst_x + clip_width < new_pmap_width - || dst_y + clip_height < new_pmap_height) + int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; + int dst_width = result->width, dst_height = result->height; + if (background == NULL) { - XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_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); + } } - /* put result on pixmap */ - asimage2drawable (target->asv, pixmap, result, gc, 0, 0, dst_x, dst_y, clip_width, clip_height, True); - /* set target's background to pixmap */ - XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); + /* 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); XFreeGC (target->dpy, gc); - } - else - { - /* set target background to a pixel */ - XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); + if (background) + flags |= bgPmap_Transparent; + else + flags &= ~bgPmap_Transparent; } return true; } -#endif +# endif /* HAVE_AFTERIMAGE */ void rxvt_term::resize_pixmap () { - XGCValues gcvalue; - GC gc; - unsigned int w = bgPixmap.h_scale*szHint.width/100; - unsigned int h = bgPixmap.v_scale*szHint.height/100; - int x = bgPixmap.h_align*szHint.width/100; - int y = bgPixmap.v_align*szHint.height/100; -#ifdef HAVE_AFTERIMAGE - ASImage *im = bgPixmap.original_asim; -#else - void *im = NULL; -#endif -/* preliminary cleanup - this needs to be integrated with check_our_parents() code */ - if (bgPixmap.pixmap != None) - { - XFreePixmap (dpy, bgPixmap.pixmap); - bgPixmap.pixmap = None ; - } -#ifdef ENABLE_TRANSPARENCY + +# ifdef ENABLE_TRANSPARENCY if (option(Opt_transparent) && am_transparent) { /* we need to re-generate transparency pixmap in that case ! */ check_our_parents (); return; } -#endif - - if (im == NULL) - { /* So be it: I'm not using pixmaps */ - XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); - return; - } - - gcvalue.foreground = pix_colors[Color_bg]; - gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); - - /* don't zoom pixmap too much nor expand really small pixmaps */ - if (w > 16000) - w = 1; - if (h > 16000) - h = 1; - -#ifdef HAVE_AFTERIMAGE - if (w == 0) - w = im->width; - if (h == 0) - h = im->height; - - if (w != im->width || h != im->height) - { - ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT); - if (tmp != NULL) - im = tmp; - } - bgPixmap.pmap_width = MIN(w,szHint.width); - bgPixmap.pmap_height = MIN(h,szHint.height); -#if 0 /* TODO: fix that! */ - if (x != 0 || y != 0) - { - ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); - if (tmp != NULL) - { - if (im != bgPixmap.original_asim) - destroy_asimage (&im); - im = tmp; - } - } -#endif - bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth); - bgPixmap.pmap_depth = depth; - - asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True); - - if (im != bgPixmap.original_asim) - destroy_asimage (&im); -#endif - if( bgPixmap.pixmap ) - XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap); - - XFreeGC (dpy, gc); +# endif +# ifdef HAVE_AFTERIMAGE + bgPixmap.render_asim(NULL, TINT_LEAVE_SAME); + bgPixmap.apply_background(); +# endif } void @@ -623,7 +584,7 @@ XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); if (*file != '\0') { -#ifdef HAVE_AFTERIMAGE +# ifdef HAVE_AFTERIMAGE if (asimman == NULL) asimman = create_generic_imageman(rs[Rs_path]); if ((f = strchr (file, ';')) == NULL) @@ -637,15 +598,221 @@ bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); free( f ); } -#endif +# endif + } + resize_pixmap (); /* TODO: temporary fix - should be done by the caller! */ +} + +# endif /* XPM_BACKGROUND */ + +# ifdef ENABLE_TRANSPARENCY +/* 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 + * our window. + */ +bool +bgPixmap_t::make_transparency_pixmap() +{ + if (target == NULL) + return false; + + /* root dimentions 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; + int screen = target->display->screen; + Display *dpy = target->dpy; + int root_width = DisplayWidth (dpy, screen); + int root_height = DisplayHeight (dpy, screen); + unsigned int root_pmap_width, root_pmap_height; + int window_width = target->szHint.width; + int window_height = target->szHint.height; + int sx, sy; + + target->get_window_origin (sx, sy); + + /* check if we are outside of the visible part of the virtual screen : */ + if (sx + window_width <= 0 || sy + window_height <= 0 + || sx >= root_width || sy >= root_height) + return false; + + if (root_pixmap != None) + {/* 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 */ + target->allowedxerror = -1; + if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) + root_pixmap = None; + target->allowedxerror = 0; + } + + Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); + GC gc = NULL; + + if (tiled_root_pmap == None) /* something really bad happened - abort */ + return false; + + if (root_pixmap == None) + { /* 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; + Window src; + bool success = false; + + attr.background_pixmap = ParentRelative; + attr.backing_store = Always; + attr.event_mask = ExposureMask; + attr.override_redirect = True; + src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, + CopyFromParent, CopyFromParent, CopyFromParent, + CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, + &attr); + + if (src != None) + { + XEvent event; + int ev_count = 0; + XGrabServer (dpy); + XMapRaised (dpy, src); + 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 : */ + while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) + ++ev_count; + if (ev_count > 0); + { /* hooray! - we can grab the image! */ + gc = XCreateGC (dpy, root, 0, NULL); + XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); + 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 + {/* strightforward pixmap copy */ + XGCValues gcv; + gcv.tile = root_pixmap; + gcv.fill_style = FillTiled; + while (sx < 0) sx += (int)window_width; + while (sy < 0) sy += (int)window_height; + gcv.ts_x_origin = -sx; + gcv.ts_y_origin = -sy; + gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); + XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); } - resize_pixmap (); + if (gc) + XFreeGC (dpy, gc); + + if (tiled_root_pmap != None) + { + if (pixmap) + XFreePixmap (dpy, pixmap); + pixmap = tiled_root_pmap; + pmap_width = window_width; + pmap_height = window_height; + pmap_depth = root_depth; + } +} + +# endif /* ENABLE_TRANSPARENCY */ + +bool +bgPixmap_t::set_target (rxvt_term *new_target) +{ + if (new_target) + if (target != new_target) + { + target = new_target; +# ifdef ENABLE_TRANSPARENCY + root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); + root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); + if (root_pixmap == None) + root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); +# endif + return true; + } + return false; } -#endif /* XPM_BACKGROUND */ +void +bgPixmap_t::apply_background() +{ + if (target) + { + if (pixmap != None) + { /* set target's background to pixmap */ +# ifdef ENABLE_TRANSPARENCY + if (flags & bgPmap_Transparent) + { + XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); + XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); + if (target->scrollBar.win) + XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); + } + else +# endif + { + /* force old pixmap dereference in case it was transparent before :*/ + XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); + XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); + /* do we also need to set scrollbar's background here ? */ + } + } + else + { /* set target background to a pixel */ + XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); + XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); + /* do we also need to set scrollbar's background here ? */ + } + /* don't want Expose on the parent */ + XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); + /* do want Expose on the vt */ + XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); + } +} #endif /* HAVE_BG_PIXMAP */ + +void +rxvt_term::get_window_origin (int &x, int &y) +{ + Window cr; + XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); +} + +Pixmap +rxvt_term::get_pixmap_property (int prop_id) +{ + if (prop_id > 0 && prop_id < NUM_XA) + if (xa[prop_id]) + { + int aformat, rootdepth; + unsigned long nitems, bytes_after; + Atom atype; + unsigned char *prop = NULL; + int result = XGetWindowProperty (dpy, display->root, xa[prop_id], + 0L, 1L, False, XA_PIXMAP, &atype, &aformat, + &nitems, &bytes_after, &prop); + if (result == Success && prop && atype == XA_PIXMAP) + { + return *(Pixmap *)prop; + } + } + return None; +} + + #ifdef ENABLE_TRANSPARENCY #ifndef HAVE_AFTERIMAGE /* taken from aterm-0.4.2 */ @@ -894,7 +1061,7 @@ void rxvt_term::check_our_parents_cb (time_watcher &w) { - int i, pchanged, aformat, rootdepth; + int i, aformat, rootdepth; unsigned long nitems, bytes_after; Atom atype; unsigned char *prop = NULL; @@ -905,11 +1072,8 @@ Window cr; unsigned int rootpixmap_w = 0, rootpixmap_h = 0; - pchanged = 0; - if (!option (Opt_transparent)) - return /*pchanged*/; /* Don't try any more */ - + return; /* Don't try any more */ #if 0 struct timeval stv; gettimeofday (&stv,NULL); @@ -930,12 +1094,11 @@ { if (am_transparent) { - pchanged = 1; XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); am_transparent = am_pixmap_trans = 0; } - return /*pchanged*/; /* Don't try any more */ + return; /* Don't try any more */ } /* Get all X ops out of the queue so that our information is up-to-date. */ @@ -963,14 +1126,7 @@ 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success); - /* TODO: the below logic needs to be cleaned up */ - if (!i || prop == NULL - || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL -#ifdef HAVE_AFTERIMAGE - && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL -#endif - ) - ) + if (!i || prop == NULL) rootpixmap = None; else { @@ -1010,29 +1166,8 @@ && IS_COMPONENT_WHOLESOME(c.b)); no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); #undef IS_COMPONENT_WHOLESOME - /* theer are no performance advantages to reusing same pixmap */ - if (bgPixmap.pixmap != None) - XFreePixmap (dpy, bgPixmap.pixmap); - bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth); - bgPixmap.pmap_width = szHint.width; - bgPixmap.pmap_height = szHint.height; - bgPixmap.pmap_depth = rootdepth; - -#if 0 /* TODO : identify cases where this will be detrimental to performance : */ - /* we want to tile root pixmap into our own pixmap in this cases : - * 1) rootpixmap does not cover our window entirely - * 2) whole_tint - we can use server-side tinting or tinting disabled - */ - if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height) - { - } -#endif - gcvalue.tile = rootpixmap; - gcvalue.fill_style = FillTiled; - gcvalue.ts_x_origin = -sx; - gcvalue.ts_y_origin = -sy; - gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue); - XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); + + bgPixmap.make_transparency_pixmap(); if (whole_tint && !no_tint) { @@ -1042,7 +1177,10 @@ gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]); gcvalue.function = GXand; gcvalue.fill_style = FillSolid; - XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); + if (gc) + XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); + else + gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcvalue); XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); } success = True; @@ -1084,66 +1222,11 @@ back_im = tmp; } } - - if (bgPixmap.original_asim != NULL) - { - ASImageLayer *layers = create_image_layers (2); - ASImage *merged_im = NULL; - int fore_w, fore_h; - - layers[0].im = back_im; - layers[0].clip_width = szHint.width; - layers[0].clip_height = szHint.height; - layers[0].tint = tint; - layers[1].im = bgPixmap.original_asim; - - fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100; - fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100; - - if (fore_w != bgPixmap.original_asim->width - || fore_h != bgPixmap.original_asim->height) - { - layers[1].im = scale_asimage (asv, - bgPixmap.original_asim, - fore_w, fore_h, - ASA_ASImage, 100, - ASIMAGE_QUALITY_DEFAULT); - } - layers[1].clip_width = szHint.width; - layers[1].clip_height = szHint.height; - - if (rs[Rs_blendtype]) - { - layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); - if (layers[1].merge_scanlines == NULL) - layers[1].merge_scanlines = alphablend_scanlines; - } - PRINT_BACKGROUND_OP_TIME; - merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height, - ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); - if (layers[1].im != bgPixmap.original_asim) - destroy_asimage (&(layers[1].im)); - free (layers); - - if (merged_im != NULL) - { - destroy_asimage (&back_im); - back_im = merged_im; - } - PRINT_BACKGROUND_OP_TIME; - } - else if (tint != TINT_LEAVE_SAME) - { - ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); - if (tmp) - { - destroy_asimage (&back_im); - back_im = tmp; - } - PRINT_BACKGROUND_OP_TIME; - } - asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True); + /* TODO: temporary fix - redo the logic, so that same function can do both + transparency and non-transparency */ + bgPixmap.render_asim (back_im, tint); destroy_asimage (&back_im); + } /* back_im != NULL */ else success = False; @@ -1170,110 +1253,30 @@ if (gc != NULL) XFreeGC (dpy, gc); - + + bgPixmap.apply_background(); if (!success) - { - if (am_transparent && am_pixmap_trans) - { - pchanged = 1; - if (bgPixmap.pixmap != None) - { - XFreePixmap (dpy, bgPixmap.pixmap); - bgPixmap.pixmap = None; - } - } - am_pixmap_trans = 0; - } else { - XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap); - XClearWindow (dpy, parent[0]); - - if (!am_transparent || !am_pixmap_trans) - pchanged = 1; - am_transparent = am_pixmap_trans = 1; } } /* rootpixmap != None */ if (am_pixmap_trans) - XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); - else { - unsigned int n; - /* - * InheritPixmap transparency - */ - for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) - { - oldp = parent[i]; - XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n); - XFree (list); - - if (parent[i] == display->root) - { - if (oldp != None) - pchanged = 1; - - break; - } - - if (oldp != parent[i]) - pchanged = 1; - } - - n = 0; - - if (pchanged) - for (; n < (unsigned int)i; n++) - { - XGetWindowAttributes (dpy, parent[n], &wattr); - - if (wattr.depth != rootdepth || wattr.c_class == InputOnly) - { - n = (int) (sizeof (parent) / sizeof (Window)) + 1; - break; - } - } - - if (n > (sizeof (parent) / sizeof (parent[0]))) + if (scrollBar.win) { - XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]); - XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); - am_transparent = 0; - /* XXX: also turn off Opt_transparent? */ + scrollBar.setIdle (); + scrollbar_show (0); } - else - { - for (n = 0; n < (unsigned int)i; n++) - { - XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative); - XClearWindow (dpy, parent[n]); - } - XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); - am_transparent = 1; + if (am_transparent) + { + want_refresh = want_full_refresh = 1; + if (am_pixmap_trans) + flush (); } - - for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) - parent[i] = None; - } - - if (scrollBar.win) - { - XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); - scrollBar.setIdle (); - scrollbar_show (0); - } - - if (am_transparent) - { - want_refresh = want_full_refresh = 1; - if (am_pixmap_trans) - flush (); } - -// return pchanged; } #endif