ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
(Generate patch)

Comparing rxvt-unicode/src/perl/background (file contents):
Revision 1.72 by root, Mon Jul 2 02:01:41 2012 UTC vs.
Revision 1.79 by root, Tue Sep 4 22:41:11 2012 UTC

4#:META:X_RESOURCE:%.border:boolean:respect the terminal border 4#:META:X_RESOURCE:%.border:boolean:respect the terminal border
5#:META:X_RESOURCE:%.interval:seconds:minimum time between updates 5#:META:X_RESOURCE:%.interval:seconds:minimum time between updates
6 6
7=head1 NAME 7=head1 NAME
8 8
9 background - manage terminal background 9background - manage terminal background
10 10
11=head1 SYNOPSIS 11=head1 SYNOPSIS
12 12
13 urxvt --background-expr 'background expression' 13 urxvt --background-expr 'background expression'
14 --background-border 14 --background-border
15 --background-interval seconds 15 --background-interval seconds
16
17=head1 QUICK AND DIRTY CHEAT SHEET
18
19Just load a random jpeg image and tile the background with it without
20scaling or anything else:
21
22 load "/path/to/img.jpg"
23
24The same, but use mirroring/reflection instead of tiling:
25
26 mirror load "/path/to/img.jpg"
27
28Load an image and scale it to exactly fill the terminal window:
29
30 scale keep { load "/path/to/img.jpg" }
31
32Implement pseudo-transparency by using a suitably-aligned root pixmap
33as window background:
34
35 rootalign root
36
37Likewise, but keep a blurred copy:
38
39 rootalign keep { blur 10, root }
16 40
17=head1 DESCRIPTION 41=head1 DESCRIPTION
18 42
19This extension manages the terminal background by creating a picture that 43This extension manages the terminal background by creating a picture that
20is behind the text, replacing the normal background colour. 44is behind the text, replacing the normal background colour.
74 return load "$HOME/sunday.png"; 98 return load "$HOME/sunday.png";
75 } 99 }
76 } 100 }
77 101
78This inner expression is evaluated once per hour (and whenever the 102This inner expression is evaluated once per hour (and whenever the
79temrinal window is resized). It sets F<sunday.png> as background on 103terminal window is resized). It sets F<sunday.png> as background on
80Sundays, and F<weekday.png> on all other days. 104Sundays, and F<weekday.png> on all other days.
81 105
82Fortunately, we expect that most expressions will be much simpler, with 106Fortunately, we expect that most expressions will be much simpler, with
83little Perl knowledge needed. 107little Perl knowledge needed.
84 108
119width and doubles the image height: 143width and doubles the image height:
120 144
121 scale 0.5, 2, load "$HOME/mypic.png" 145 scale 0.5, 2, load "$HOME/mypic.png"
122 146
123IF you try out these expressions, you might suffer from some sluggishness, 147IF you try out these expressions, you might suffer from some sluggishness,
124because each time the terminal is resized, it loads the PNG image agin 148because each time the terminal is resized, it loads the PNG image again
125and scales it. Scaling is usually fast (and unavoidable), but loading the 149and scales it. Scaling is usually fast (and unavoidable), but loading the
126image can be quite time consuming. This is where C<keep> comes in handy: 150image can be quite time consuming. This is where C<keep> comes in handy:
127 151
128 scale 0.5, 2, keep { load "$HOME/mypic.png" } 152 scale 0.5, 2, keep { load "$HOME/mypic.png" }
129 153
159left corner of the terminal window)- the result is pseudo-transparency: 183left corner of the terminal window)- the result is pseudo-transparency:
160the image seems to be static while the window is moved around. 184the image seems to be static while the window is moved around.
161 185
162=head2 COLOUR SPECIFICATIONS 186=head2 COLOUR SPECIFICATIONS
163 187
164Whenever an oprator expects a "colour", then this can be specified in one 188Whenever an operator expects a "colour", then this can be specified in one
165of two ways: Either as string with an X11 colour specification, such as: 189of two ways: Either as string with an X11 colour specification, such as:
166 190
167 "red" # named colour 191 "red" # named colour
168 "#f00" # simple rgb 192 "#f00" # simple rgb
169 "[50]red" # red with 50% alpha 193 "[50]red" # red with 50% alpha
398 for @_; 422 for @_;
399 423
400 $base 424 $base
401 } 425 }
402 426
427=back
428
403=head2 TILING MODES 429=head2 TILING MODES
404 430
405The following operators modify the tiling mode of an image, that is, the 431The following operators modify the tiling mode of an image, that is, the
406way that pixels outside the image area are painted when the image is used. 432way that pixels outside the image area are painted when the image is used.
407 433
509 535
510 move -TX, -TY, keep { load "mybg.png" } 536 move -TX, -TY, keep { load "mybg.png" }
511 537
512=item TW 538=item TW
513 539
540=item TH
541
514Return the width (C<TW>) and height (C<TH>) of the terminal window (the 542Return the width (C<TW>) and height (C<TH>) of the terminal window (the
515terminal window is the full window by default, and the character area only 543terminal window is the full window by default, and the character area only
516when in border-respect mode). 544when in border-respect mode).
517 545
518Using these functions make your expression sensitive to window resizes. 546Using these functions make your expression sensitive to window resizes.
585Clips an image to the given rectangle. If the rectangle is outside the 613Clips an image to the given rectangle. If the rectangle is outside the
586image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is 614image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is
587larger than the image, then the tiling mode defines how the extra pixels 615larger than the image, then the tiling mode defines how the extra pixels
588will be filled. 616will be filled.
589 617
590If C<$x> an C<$y> are missing, then C<0> is assumed for both. 618If C<$x> and C<$y> are missing, then C<0> is assumed for both.
591 619
592If C<$width> and C<$height> are missing, then the window size will be 620If C<$width> and C<$height> are missing, then the window size will be
593assumed. 621assumed.
594 622
595Example: load an image, blur it, and clip it to the window size to save 623Example: load an image, blur it, and clip it to the window size to save
827latter in a white picture. 855latter in a white picture.
828 856
829Due to idiosyncrasies in the underlying XRender extension, biases less 857Due to idiosyncrasies in the underlying XRender extension, biases less
830than zero can be I<very> slow. 858than zero can be I<very> slow.
831 859
860You can also try the experimental(!) C<muladd> operator.
861
832=cut 862=cut
833 863
834 sub contrast($$;$$;$) { 864 sub contrast($$;$$;$) {
835 my $img = pop; 865 my $img = pop;
836 my ($r, $g, $b, $a) = @_; 866 my ($r, $g, $b, $a) = @_;
851 $a = 1 if @_ < 4; 881 $a = 1 if @_ < 4;
852 882
853 $img = $img->clone; 883 $img = $img->clone;
854 $img->brightness ($r, $g, $b, $a); 884 $img->brightness ($r, $g, $b, $a);
855 $img 885 $img
886 }
887
888=item muladd $mul, $add, $img # EXPERIMENTAL
889
890First multipliesthe pixels by C<$mul>, then adds C<$add>. This cna be used
891to implement brightness and contrast at the same time, with a wider value
892range than contrast and brightness operators.
893
894Due to numerous bugs in XRender implementations, it can also introduce a
895number of visual artifacts.
896
897Example: increase contrast by a factor of C<$c> without changing image
898brightness too much.
899
900 muladd $c, (1 - $c) * 0.5, $img
901
902=cut
903
904 sub muladd($$$) {
905 $_[2]->muladd ($_[0], $_[1])
856 } 906 }
857 907
858=item blur $radius, $img 908=item blur $radius, $img
859 909
860=item blur $radius_horz, $radius_vert, $img 910=item blur $radius_horz, $radius_vert, $img
905C<keep> block so it only is reevaluated as required. 955C<keep> block so it only is reevaluated as required.
906 956
907Putting the blur into a C<keep> block will make sure the blur is only done 957Putting the blur into a C<keep> block will make sure the blur is only done
908once, while the C<rootalign> is still done each time the window moves. 958once, while the C<rootalign> is still done each time the window moves.
909 959
910 rootlign keep { blur 10, root } 960 rootalign keep { blur 10, root }
911 961
912This leaves the question of how to force reevaluation of the block, 962This leaves the question of how to force reevaluation of the block,
913in case the root background changes: If expression inside the block 963in case the root background changes: If expression inside the block
914is sensitive to some event (root background changes, window geometry 964is sensitive to some event (root background changes, window geometry
915changes), then it will be reevaluated automatically as needed. 965changes), then it will be reevaluated automatically as needed.
967 1017
968# compiles a parsed expression 1018# compiles a parsed expression
969sub set_expr { 1019sub set_expr {
970 my ($self, $expr) = @_; 1020 my ($self, $expr) = @_;
971 1021
972 $self->{root} = []; 1022 $self->{root} = []; # the outermost frame
973 $self->{expr} = $expr; 1023 $self->{expr} = $expr;
974 $self->recalculate; 1024 $self->recalculate;
975} 1025}
976 1026
977# takes a hash of sensitivity indicators and installs watchers 1027# takes a hash of sensitivity indicators and installs watchers
1039 1089
1040 # set environment to evaluate user expression 1090 # set environment to evaluate user expression
1041 1091
1042 local $self = $arg_self; 1092 local $self = $arg_self;
1043 local $HOME = $ENV{HOME}; 1093 local $HOME = $ENV{HOME};
1044 local $frame = []; 1094 local $frame = $self->{root};
1045 1095
1046 ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); 1096 ($x, $y, $w, $h) = $self->background_geometry ($self->{border});
1047 1097
1048 # evaluate user expression 1098 # evaluate user expression
1049 1099

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines