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.70 by root, Mon Jul 2 01:35:37 2012 UTC vs.
Revision 1.75 by root, Fri Aug 10 20:07:11 2012 UTC

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
156 180
157This one first takes a snapshot of the screen background image, and then 181This one first takes a snapshot of the screen background image, and then
158moves it to the upper left corner of the screen (as opposed to the upper 182moves it to the upper left corner of the screen (as opposed to the upper
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.
185
186=head2 COLOUR SPECIFICATIONS
187
188Whenever an operator expects a "colour", then this can be specified in one
189of two ways: Either as string with an X11 colour specification, such as:
190
191 "red" # named colour
192 "#f00" # simple rgb
193 "[50]red" # red with 50% alpha
194 "TekHVC:300/50/50" # anything goes
195
196OR as an array reference with one, three or four components:
197
198 [0.5] # 50% gray, 100% alpha
199 [0.5, 0, 0] # dark red, no green or blur, 100% alpha
200 [0.5, 0, 0, 0.7] # same with explicit 70% alpha
161 201
162=head2 CACHING AND SENSITIVITY 202=head2 CACHING AND SENSITIVITY
163 203
164Since some operations (such as C<load> and C<blur>) can take a long time, 204Since some operations (such as C<load> and C<blur>) can take a long time,
165caching results can be very important for a smooth operation. Caching can 205caching results can be very important for a smooth operation. Caching can
273uses it), then the in-memory copy us returned instead. 313uses it), then the in-memory copy us returned instead.
274 314
275=item load_uc $path 315=item load_uc $path
276 316
277Load uncached - same as load, but does not cache the image, which means it 317Load uncached - same as load, but does not cache the image, which means it
278is I<always> loaded from the filesystem again. 318is I<always> loaded from the filesystem again, even if another copy of it
319is in memory at the time.
279 320
280=cut 321=cut
322
323 sub load_uc($) {
324 $self->new_img_from_file ($_[0])
325 }
281 326
282 sub load($) { 327 sub load($) {
283 my ($path) = @_; 328 my ($path) = @_;
284 329
285 $_IMG_CACHE{$path} || do { 330 $_IMG_CACHE{$path} || do {
286 my $img = $self->new_img_from_file ($path); 331 my $img = load_uc $path;
287 Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); 332 Scalar::Util::weaken ($_IMG_CACHE{$path} = $img);
288 $img 333 $img
289 } 334 }
290 } 335 }
291 336
806latter in a white picture. 851latter in a white picture.
807 852
808Due to idiosyncrasies in the underlying XRender extension, biases less 853Due to idiosyncrasies in the underlying XRender extension, biases less
809than zero can be I<very> slow. 854than zero can be I<very> slow.
810 855
856You can also try the experimental(!) C<muladd> operator.
857
811=cut 858=cut
812 859
813 sub contrast($$;$$;$) { 860 sub contrast($$;$$;$) {
814 my $img = pop; 861 my $img = pop;
815 my ($r, $g, $b, $a) = @_; 862 my ($r, $g, $b, $a) = @_;
830 $a = 1 if @_ < 4; 877 $a = 1 if @_ < 4;
831 878
832 $img = $img->clone; 879 $img = $img->clone;
833 $img->brightness ($r, $g, $b, $a); 880 $img->brightness ($r, $g, $b, $a);
834 $img 881 $img
882 }
883
884=item muladd $mul, $add, $img # EXPERIMENTAL
885
886First multipliesthe pixels by C<$mul>, then adds C<$add>. This cna be used
887to implement brightness and contrast at the same time, with a wider value
888range than contrast and brightness operators.
889
890Due to numerous bugs in XRender implementations, it can also introduce a
891number of visual artifacts.
892
893Example: increase contrast by a factor of C<$c> without changing image
894brightness too much.
895
896 muladd $c, (1 - $c) * 0.5, $img
897
898=cut
899
900 sub muladd($$$) {
901 $_[2]->muladd ($_[0], $_[1])
835 } 902 }
836 903
837=item blur $radius, $img 904=item blur $radius, $img
838 905
839=item blur $radius_horz, $radius_vert, $img 906=item blur $radius_horz, $radius_vert, $img
884C<keep> block so it only is reevaluated as required. 951C<keep> block so it only is reevaluated as required.
885 952
886Putting the blur into a C<keep> block will make sure the blur is only done 953Putting the blur into a C<keep> block will make sure the blur is only done
887once, while the C<rootalign> is still done each time the window moves. 954once, while the C<rootalign> is still done each time the window moves.
888 955
889 rootlign keep { blur 10, root } 956 rootalign keep { blur 10, root }
890 957
891This leaves the question of how to force reevaluation of the block, 958This leaves the question of how to force reevaluation of the block,
892in case the root background changes: If expression inside the block 959in case the root background changes: If expression inside the block
893is sensitive to some event (root background changes, window geometry 960is sensitive to some event (root background changes, window geometry
894changes), then it will be reevaluated automatically as needed. 961changes), then it will be reevaluated automatically as needed.
946 1013
947# compiles a parsed expression 1014# compiles a parsed expression
948sub set_expr { 1015sub set_expr {
949 my ($self, $expr) = @_; 1016 my ($self, $expr) = @_;
950 1017
951 $self->{root} = []; 1018 $self->{root} = []; # the outermost frame
952 $self->{expr} = $expr; 1019 $self->{expr} = $expr;
953 $self->recalculate; 1020 $self->recalculate;
954} 1021}
955 1022
956# takes a hash of sensitivity indicators and installs watchers 1023# takes a hash of sensitivity indicators and installs watchers
1018 1085
1019 # set environment to evaluate user expression 1086 # set environment to evaluate user expression
1020 1087
1021 local $self = $arg_self; 1088 local $self = $arg_self;
1022 local $HOME = $ENV{HOME}; 1089 local $HOME = $ENV{HOME};
1023 local $frame = []; 1090 local $frame = $self->{root};
1024 1091
1025 ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); 1092 ($x, $y, $w, $h) = $self->background_geometry ($self->{border});
1026 1093
1027 # evaluate user expression 1094 # evaluate user expression
1028 1095

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines