--- rxvt-unicode/src/background.C 2011/08/10 07:34:35 1.159 +++ rxvt-unicode/src/background.C 2011/08/21 14:38:39 1.171 @@ -34,29 +34,6 @@ #define FilterConvolution "convolution" #endif -/* - * Pixmap geometry string interpretation : - * Each geometry string contains zero or one scale/position - * 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 - * effects on the background image : - * - * 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. - * - * Pixmap Operations : (should be prepended by a colon) - * tile Tile image. Scaling/position modifiers above will affect - * the tile size and origin. - * 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. - * scale Scale both up and down - */ - #ifdef HAVE_BG_PIXMAP void rxvt_term::bg_destroy () @@ -206,58 +183,59 @@ int geom_flags = 0; int x = 0, y = 0; unsigned int w = 0, h = 0; - unsigned int n; unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); - const char *ops; if (geom == NULL) return false; - char str[256]; - - ops = strchr (geom, ':'); - if (ops == NULL) - n = strlen (geom); - else - n = ops - geom; - - if (n >= sizeof (str)) - return false; - - memcpy (str, geom, n); - str[n] = '\0'; - rxvt_strtrim (str); - - if (str[0]) - { - /* we have geometry string - let's handle it prior to applying ops */ - geom_flags = XParseGeometry (str, &x, &y, &w, &h); - } /* done parsing geometry string */ - - if (!update) + if (geom[0]) { - if (!(geom_flags & XValue)) - x = y = defaultAlign; - else if (!(geom_flags & YValue)) - y = x; - - if (!(geom_flags & (WidthValue|HeightValue))) - w = h = defaultScale; - else if (!(geom_flags & HeightValue)) - h = w; - else if (!(geom_flags & WidthValue)) - w = h; - - geom_flags |= WidthValue|HeightValue|XValue|YValue; - } - - if (ops) - { - char **arr = rxvt_strsplit (':', ops + 1); + char **arr = rxvt_strsplit (':', geom); for (int i = 0; arr[i]; i++) { - if (!strcasecmp (arr[i], "tile")) + if (!strcasecmp (arr[i], "style=tiled")) + { + new_flags = BG_TILE; + w = h = noScale; + x = y = 0; + geom_flags = WidthValue|HeightValue|XValue|YValue; + } + else if (!strcasecmp (arr[i], "style=aspect-stretched")) + { + new_flags = BG_PROP_SCALE; + w = h = windowScale; + x = y = centerAlign; + geom_flags = WidthValue|HeightValue|XValue|YValue; + } + else if (!strcasecmp (arr[i], "style=stretched")) + { + new_flags = 0; + w = h = windowScale; + geom_flags = WidthValue|HeightValue; + } + else if (!strcasecmp (arr[i], "style=centered")) + { + new_flags = 0; + w = h = noScale; + x = y = centerAlign; + geom_flags = WidthValue|HeightValue|XValue|YValue; + } + else if (!strcasecmp (arr[i], "style=root-tiled")) + { + new_flags = BG_TILE|BG_ROOT_ALIGN; + w = h = noScale; + geom_flags = WidthValue|HeightValue; + } + else if (!strcasecmp (arr[i], "op=tile")) + new_flags |= BG_TILE; + else if (!strcasecmp (arr[i], "op=pscale")) + new_flags |= BG_PROP_SCALE; + else if (!strcasecmp (arr[i], "op=root")) + new_flags |= BG_ROOT_ALIGN; + + // deprecated + else if (!strcasecmp (arr[i], "tile")) { new_flags |= BG_TILE; w = h = noScale; @@ -267,16 +245,28 @@ { new_flags |= BG_PROP_SCALE; } + else if (!strcasecmp (arr[i], "hscale")) + { + new_flags |= BG_TILE; + w = windowScale; + h = noScale; + geom_flags |= WidthValue|HeightValue; + } + else if (!strcasecmp (arr[i], "vscale")) + { + new_flags |= BG_TILE; + h = windowScale; + w = noScale; + geom_flags |= WidthValue|HeightValue; + } else if (!strcasecmp (arr[i], "scale")) { - if (h == 0) h = windowScale; - if (w == 0) w = windowScale; - + w = h = windowScale; geom_flags |= WidthValue|HeightValue; } - else if (!strcasecmp (arr[i], "center")) + else if (!strcasecmp (arr[i], "auto")) { - w = h = noScale; + w = h = windowScale; x = y = centerAlign; geom_flags |= WidthValue|HeightValue|XValue|YValue; } @@ -286,11 +276,31 @@ w = h = noScale; geom_flags |= WidthValue|HeightValue; } + + else + geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); } /* done parsing ops */ rxvt_free_strsplit (arr); } + if (!update) + { + if (!(geom_flags & XValue)) + x = y = defaultAlign; + else if (!(geom_flags & YValue)) + y = x; + + if (!(geom_flags & (WidthValue|HeightValue))) + w = h = defaultScale; + else if (!(geom_flags & HeightValue)) + h = w; + else if (!(geom_flags & WidthValue)) + w = h; + + geom_flags |= WidthValue|HeightValue|XValue|YValue; + } + if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; @@ -311,18 +321,16 @@ int target_width = szHint.width; int target_height = szHint.height; + w = h_scale * target_width / 100; + h = v_scale * target_height / 100; + if (bg_flags & BG_PROP_SCALE) { - float scale = (float)target_width / image_width; - min_it (scale, (float)target_height / image_height); + float scale = (float)w / image_width; + min_it (scale, (float)h / image_height); w = image_width * scale + 0.5; h = image_height * scale + 0.5; } - else - { - w = h_scale * target_width / 100; - h = v_scale * target_height / 100; - } if (!w) w = image_width; if (!h) h = image_height; @@ -340,7 +348,7 @@ bg_flags &= ~BG_IS_SIZE_SENSITIVE; if (!(bg_flags & BG_TILE) - || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale + || h_scale || v_scale || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) || w > target_width || h > target_height) bg_flags |= BG_IS_SIZE_SENSITIVE; @@ -377,7 +385,7 @@ if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) { ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, - (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, + ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) { @@ -436,7 +444,7 @@ { result = scale_asimage (asv, original_asim, w, h, - background ? ASA_ASImage : ASA_XImage, + ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); } @@ -842,7 +850,10 @@ if (!file || !*file) return false; - if (const char *p = strchr (file, ';')) + bool ret = false; + const char *p = strchr (file, ';'); + + if (p) { size_t len = p - file; char *f = rxvt_temp_buf (len + 1); @@ -861,7 +872,7 @@ safe_asimage_destroy (original_asim); original_asim = image; bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; - return true; + ret = true; } # endif @@ -873,11 +884,19 @@ g_object_unref (pixbuf); pixbuf = image; bg_flags |= BG_IS_FROM_FILE; - return true; + ret = true; } # endif - return false; + if (ret) + { + if (p) + bg_set_geometry (p + 1); + else + bg_set_default_geometry (); + } + + return ret; } # endif /* BG_IMAGE_FROM_FILE */ @@ -1324,8 +1343,7 @@ tr_flags = make_transparency_pixmap (); if (tr_flags == 0) return false; - else if (!(tr_flags & BG_EFFECTS_FLAGS)) - bg_flags |= BG_IS_VALID; + bg_flags |= BG_IS_VALID; } # endif @@ -1341,7 +1359,7 @@ # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) XImage *result = NULL; - if (tr_flags && !(bg_flags & BG_IS_VALID)) + if (tr_flags & BG_NEEDS_TINT) { result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); } @@ -1349,7 +1367,8 @@ if (result) { /* our own client-side tinting */ - if (tr_flags & BG_NEEDS_TINT) + //if (tr_flags & BG_NEEDS_TINT) + if (1) { rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); if (bg_flags & BG_TINT_SET) @@ -1364,7 +1383,6 @@ XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); XFreeGC (dpy, gc); - bg_flags |= BG_IS_VALID; } XDestroyImage (result); @@ -1415,7 +1433,7 @@ #endif /* HAVE_BG_PIXMAP */ #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) -/* taken from aterm-0.4.2 */ +/* based on code from aterm-0.4.2 */ static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c)