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.71 by root, Mon Jul 2 01:40:41 2012 UTC vs.
Revision 1.76 by root, Tue Aug 14 23:57:07 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
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
289uses it), then the in-memory copy us returned instead. 313uses it), then the in-memory copy us returned instead.
290 314
291=item load_uc $path 315=item load_uc $path
292 316
293Load 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
294is 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.
295 320
296=cut 321=cut
322
323 sub load_uc($) {
324 $self->new_img_from_file ($_[0])
325 }
297 326
298 sub load($) { 327 sub load($) {
299 my ($path) = @_; 328 my ($path) = @_;
300 329
301 $_IMG_CACHE{$path} || do { 330 $_IMG_CACHE{$path} || do {
302 my $img = $self->new_img_from_file ($path); 331 my $img = load_uc $path;
303 Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); 332 Scalar::Util::weaken ($_IMG_CACHE{$path} = $img);
304 $img 333 $img
305 } 334 }
306 } 335 }
307 336
392 $base->draw ($_) 421 $base->draw ($_)
393 for @_; 422 for @_;
394 423
395 $base 424 $base
396 } 425 }
426
427=back
397 428
398=head2 TILING MODES 429=head2 TILING MODES
399 430
400The 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
401way 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.
822latter in a white picture. 853latter in a white picture.
823 854
824Due to idiosyncrasies in the underlying XRender extension, biases less 855Due to idiosyncrasies in the underlying XRender extension, biases less
825than zero can be I<very> slow. 856than zero can be I<very> slow.
826 857
858You can also try the experimental(!) C<muladd> operator.
859
827=cut 860=cut
828 861
829 sub contrast($$;$$;$) { 862 sub contrast($$;$$;$) {
830 my $img = pop; 863 my $img = pop;
831 my ($r, $g, $b, $a) = @_; 864 my ($r, $g, $b, $a) = @_;
846 $a = 1 if @_ < 4; 879 $a = 1 if @_ < 4;
847 880
848 $img = $img->clone; 881 $img = $img->clone;
849 $img->brightness ($r, $g, $b, $a); 882 $img->brightness ($r, $g, $b, $a);
850 $img 883 $img
884 }
885
886=item muladd $mul, $add, $img # EXPERIMENTAL
887
888First multipliesthe pixels by C<$mul>, then adds C<$add>. This cna be used
889to implement brightness and contrast at the same time, with a wider value
890range than contrast and brightness operators.
891
892Due to numerous bugs in XRender implementations, it can also introduce a
893number of visual artifacts.
894
895Example: increase contrast by a factor of C<$c> without changing image
896brightness too much.
897
898 muladd $c, (1 - $c) * 0.5, $img
899
900=cut
901
902 sub muladd($$$) {
903 $_[2]->muladd ($_[0], $_[1])
851 } 904 }
852 905
853=item blur $radius, $img 906=item blur $radius, $img
854 907
855=item blur $radius_horz, $radius_vert, $img 908=item blur $radius_horz, $radius_vert, $img
900C<keep> block so it only is reevaluated as required. 953C<keep> block so it only is reevaluated as required.
901 954
902Putting the blur into a C<keep> block will make sure the blur is only done 955Putting the blur into a C<keep> block will make sure the blur is only done
903once, while the C<rootalign> is still done each time the window moves. 956once, while the C<rootalign> is still done each time the window moves.
904 957
905 rootlign keep { blur 10, root } 958 rootalign keep { blur 10, root }
906 959
907This leaves the question of how to force reevaluation of the block, 960This leaves the question of how to force reevaluation of the block,
908in case the root background changes: If expression inside the block 961in case the root background changes: If expression inside the block
909is sensitive to some event (root background changes, window geometry 962is sensitive to some event (root background changes, window geometry
910changes), then it will be reevaluated automatically as needed. 963changes), then it will be reevaluated automatically as needed.
962 1015
963# compiles a parsed expression 1016# compiles a parsed expression
964sub set_expr { 1017sub set_expr {
965 my ($self, $expr) = @_; 1018 my ($self, $expr) = @_;
966 1019
967 $self->{root} = []; 1020 $self->{root} = []; # the outermost frame
968 $self->{expr} = $expr; 1021 $self->{expr} = $expr;
969 $self->recalculate; 1022 $self->recalculate;
970} 1023}
971 1024
972# takes a hash of sensitivity indicators and installs watchers 1025# takes a hash of sensitivity indicators and installs watchers
1034 1087
1035 # set environment to evaluate user expression 1088 # set environment to evaluate user expression
1036 1089
1037 local $self = $arg_self; 1090 local $self = $arg_self;
1038 local $HOME = $ENV{HOME}; 1091 local $HOME = $ENV{HOME};
1039 local $frame = []; 1092 local $frame = $self->{root};
1040 1093
1041 ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); 1094 ($x, $y, $w, $h) = $self->background_geometry ($self->{border});
1042 1095
1043 # evaluate user expression 1096 # evaluate user expression
1044 1097

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines