--- rxvt-unicode/src/perl/background 2012/07/01 21:47:07 1.68 +++ rxvt-unicode/src/perl/background 2013/06/02 17:55:07 1.83 @@ -6,7 +6,7 @@ =head1 NAME - background - manage terminal background +background - manage terminal background =head1 SYNOPSIS @@ -14,6 +14,30 @@ --background-border --background-interval seconds +=head1 QUICK AND DIRTY CHEAT SHEET + +Just load a random jpeg image and tile the background with it without +scaling or anything else: + + load "/path/to/img.jpg" + +The same, but use mirroring/reflection instead of tiling: + + mirror load "/path/to/img.jpg" + +Load an image and scale it to exactly fill the terminal window: + + scale keep { load "/path/to/img.jpg" } + +Implement pseudo-transparency by using a suitably-aligned root pixmap +as window background: + + rootalign root + +Likewise, but keep a blurred copy: + + rootalign keep { blur 10, root } + =head1 DESCRIPTION This extension manages the terminal background by creating a picture that @@ -76,7 +100,7 @@ } This inner expression is evaluated once per hour (and whenever the -temrinal window is resized). It sets F as background on +terminal window is resized). It sets F as background on Sundays, and F on all other days. Fortunately, we expect that most expressions will be much simpler, with @@ -121,7 +145,7 @@ scale 0.5, 2, load "$HOME/mypic.png" IF you try out these expressions, you might suffer from some sluggishness, -because each time the terminal is resized, it loads the PNG image agin +because each time the terminal is resized, it loads the PNG image again and scales it. Scaling is usually fast (and unavoidable), but loading the image can be quite time consuming. This is where C comes in handy: @@ -159,6 +183,22 @@ left corner of the terminal window)- the result is pseudo-transparency: the image seems to be static while the window is moved around. +=head2 COLOUR SPECIFICATIONS + +Whenever an operator expects a "colour", then this can be specified in one +of two ways: Either as string with an X11 colour specification, such as: + + "red" # named colour + "#f00" # simple rgb + "[50]red" # red with 50% alpha + "TekHVC:300/50/50" # anything goes + +OR as an array reference with one, three or four components: + + [0.5] # 50% gray, 100% alpha + [0.5, 0, 0] # dark red, no green or blur, 100% alpha + [0.5, 0, 0, 0.7] # same with explicit 70% alpha + =head2 CACHING AND SENSITIVITY Since some operations (such as C and C) can take a long time, @@ -270,17 +310,18 @@ mode. If the image is already in memory (e.g. because another terminal instance -uses it), then the in-memory copy us returned instead. +uses it), then the in-memory copy is returned instead. =item load_uc $path Load uncached - same as load, but does not cache the image, which means it -is I loaded from the filesystem again. +is I loaded from the filesystem again, even if another copy of it +is in memory at the time. =cut sub load_uc($) { - $self->new_img_from_file ($path) + $self->new_img_from_file ($_[0]) } sub load($) { @@ -383,6 +424,8 @@ $base } +=back + =head2 TILING MODES The following operators modify the tiling mode of an image, that is, the @@ -494,6 +537,8 @@ =item TW +=item TH + Return the width (C) and height (C) of the terminal window (the terminal window is the full window by default, and the character area only when in border-respect mode). @@ -570,7 +615,7 @@ larger than the image, then the tiling mode defines how the extra pixels will be filled. -If C<$x> an C<$y> are missing, then C<0> is assumed for both. +If C<$x> and C<$y> are missing, then C<0> is assumed for both. If C<$width> and C<$height> are missing, then the window size will be assumed. @@ -598,7 +643,7 @@ Scales the image by the given factors in horizontal (C<$width>) and vertical (C<$height>) direction. -If only one factor is give, it is used for both directions. +If only one factor is given, it is used for both directions. If no factors are given, scales the image to the window size without keeping aspect. @@ -733,7 +778,7 @@ Rotates the image clockwise by C<$degrees> degrees, around the point at C<$center_x> and C<$center_y> (specified as factor of image width/height). -Example: rotate the image by 90 degrees around it's center. +Example: rotate the image by 90 degrees around its center. rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } @@ -756,6 +801,34 @@ =over 4 +=item tint $color, $img + +Tints the image in the given colour. + +Example: tint the image red. + + tint "red", load "rgb.png" + +Example: the same, but specify the colour by component. + + tint [1, 0, 0], load "rgb.png" + +=cut + + sub tint($$) { + $_[1]->tint ($_[0]) + } + +=item shade $factor, $img + +Shade the image by the given factor. + +=cut + + sub shade($$) { + $_[1]->shade ($_[0]) + } + =item contrast $factor, $img =item contrast $r, $g, $b, $img @@ -794,6 +867,8 @@ Due to idiosyncrasies in the underlying XRender extension, biases less than zero can be I slow. +You can also try the experimental(!) C operator. + =cut sub contrast($$;$$;$) { @@ -820,6 +895,26 @@ $img } +=item muladd $mul, $add, $img # EXPERIMENTAL + +First multiplies the pixels by C<$mul>, then adds C<$add>. This can be used +to implement brightness and contrast at the same time, with a wider value +range than contrast and brightness operators. + +Due to numerous bugs in XRender implementations, it can also introduce a +number of visual artifacts. + +Example: increase contrast by a factor of C<$c> without changing image +brightness too much. + + muladd $c, (1 - $c) * 0.5, $img + +=cut + + sub muladd($$$) { + $_[2]->muladd ($_[0], $_[1]) + } + =item blur $radius, $img =item blur $radius_horz, $radius_vert, $img @@ -872,7 +967,7 @@ Putting the blur into a C block will make sure the blur is only done once, while the C is still done each time the window moves. - rootlign keep { blur 10, root } + rootalign keep { blur 10, root } This leaves the question of how to force reevaluation of the block, in case the root background changes: If expression inside the block @@ -934,7 +1029,7 @@ sub set_expr { my ($self, $expr) = @_; - $self->{root} = []; + $self->{root} = []; # the outermost frame $self->{expr} = $expr; $self->recalculate; } @@ -1006,7 +1101,7 @@ local $self = $arg_self; local $HOME = $ENV{HOME}; - local $frame = []; + local $frame = $self->{root}; ($x, $y, $w, $h) = $self->background_geometry ($self->{border});