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.38 by root, Fri Jun 8 21:48:07 2012 UTC vs.
Revision 1.42 by root, Sun Jun 10 10:42:19 2012 UTC

3#:META:X_RESOURCE:%.expr:string:background expression 3#:META:X_RESOURCE:%.expr:string:background expression
4#:META:X_RESOURCE:%.border.:boolean:respect the terminal border 4#:META:X_RESOURCE:%.border.:boolean:respect the terminal border
5 5
6#TODO: once, rootalign 6#TODO: once, rootalign
7 7
8=head1 NAME
9
8=head1 background - manage terminal background 10 background - manage terminal background
9 11
10=head2 SYNOPSIS 12=head1 SYNOPSIS
11 13
12 urxvt --background-expr 'background expression' 14 urxvt --background-expr 'background expression'
13 --background-border 15 --background-border
14 16
15=head2 DESCRIPTION 17=head1 DESCRIPTION
16 18
17This extension manages the terminal background by creating a picture that 19This extension manages the terminal background by creating a picture that
18is behind the text, replacing the normal background colour. 20is behind the text, replacing the normal background colour.
19 21
20It does so by evaluating a Perl expression that I<calculates> the image on 22It does so by evaluating a Perl expression that I<calculates> the image on
30 32
31Or specified as a X resource: 33Or specified as a X resource:
32 34
33 URxvt.background-expr: scale load "/path/to/mybg.png" 35 URxvt.background-expr: scale load "/path/to/mybg.png"
34 36
35=head2 THEORY OF OPERATION 37=head1 THEORY OF OPERATION
36 38
37At startup, just before the window is mapped for the first time, the 39At startup, just before the window is mapped for the first time, the
38expression is evaluated and must yield an image. The image is then 40expression is evaluated and must yield an image. The image is then
39extended as necessary to cover the whole terminal window, and is set as a 41extended as necessary to cover the whole terminal window, and is set as a
40background pixmap. 42background pixmap.
57image to the window size, so it relies on the window size and will 59image to the window size, so it relies on the window size and will
58be reevaluated each time it is changed, but not when it moves for 60be reevaluated each time it is changed, but not when it moves for
59example. That ensures that the picture always fills the terminal, even 61example. That ensures that the picture always fills the terminal, even
60after it's size changes. 62after it's size changes.
61 63
62=head3 EXPRESSIONS 64=head2 EXPRESSIONS
63 65
64Expressions are normal Perl expressions, in fact, they are Perl blocks - 66Expressions are normal Perl expressions, in fact, they are Perl blocks -
65which means you could use multiple lines and statements: 67which means you could use multiple lines and statements:
66 68
67 again 3600; 69 again 3600;
70 } else { 72 } else {
71 return scale load "$HOME/sunday.png"; 73 return scale load "$HOME/sunday.png";
72 } 74 }
73 75
74This expression gets evaluated once per hour. It will set F<sunday.png> as 76This expression gets evaluated once per hour. It will set F<sunday.png> as
75background on sundays, and F<weekday.png> on all other days. 77background on Sundays, and F<weekday.png> on all other days.
76 78
77Fortunately, we expect that most expressions will be much simpler, with 79Fortunately, we expect that most expressions will be much simpler, with
78little Perl knowledge needed. 80little Perl knowledge needed.
79 81
80Basically, you always start with a function that "generates" an image 82Basically, you always start with a function that "generates" an image
112horizontal and vertical dimensions. For example, this halves the image 114horizontal and vertical dimensions. For example, this halves the image
113width and doubles the image height: 115width and doubles the image height:
114 116
115 scale 50, 200, load "$HOME/mypic.png" 117 scale 50, 200, load "$HOME/mypic.png"
116 118
117TODO 119Other effects than scalign are also readily available, for exmaple, you can
120tile the image to fill the whole window, instead of resizing it:
118 121
122 tile load "$HOME/mypic.png"
123
124In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator
125is kind of superfluous.
126
127Another common effect is to mirror the image, so that the same edges touch:
128
129 mirror load "$HOME/mypic.png"
130
131This is also a typical background expression:
132
133 rootalign root
134
135It first takes a snapshot of the screen background image, and then
136moves it to the upper left corner of the screen - the result is
137pseudo-transparency, as the image seems to be static while the window is
138moved around.
139
119=head3 CYCLES AND CACHING 140=head2 CYCLES AND CACHING
120 141
121TODO 142As has been mentioned before, the expression might be evaluated multiple
122
123Each time the expression is reevaluated, a new cycle is said to have begun. Many operators 143times. Each time the expression is reevaluated, a new cycle is said to
124cache their results till the next cycle. For example 144have begun. Many operators cache their results till the next cycle.
125 145
146For example, the C<load> operator keeps a copy of the image. If it is
147asked to load the same image on the next cycle it will not load it again,
148but return the cached copy.
149
150This only works for one cycle though, so as long as you load the same
151image every time, it will always be cached, but when you load a different
152image, it will forget about the first one.
153
154This allows you to either speed things up by keeping multiple images in
155memory, or comserve memory by loading images more often.
156
157For example, you can keep two images in memory and use a random one like
158this:
159
160 my $img1 = load "img1.png";
161 my $img2 = load "img2.png";
162 (0.5 > rand) ? $img1 : $img2
163
164Since both images are "loaded" every time the expression is evaluated,
165they are always kept in memory. Contrast this version:
166
167 my $path1 = "img1.png";
168 my $path2 = "img2.png";
169 load ((0.5 > rand) ? $path1 : $path2)
170
171Here, a path is selected randomly, and load is only called for one image,
172so keeps only one image in memory. If, on the next evaluation, luck
173decides to use the other path, then it will have to load that image again.
174
126=head2 REFERENCE 175=head1 REFERENCE
127 176
128=head3 COMMAND LINE SWITCHES 177=head2 COMMAND LINE SWITCHES
129 178
130=over 4 179=over 4
131 180
132=item --background-expr perl-expression 181=item --background-expr perl-expression
133 182
142replaces the background of the character area. 191replaces the background of the character area.
143 192
144=back 193=back
145 194
146=cut 195=cut
147
148our $EXPR;#d#
149#$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"';
150$EXPR = 'move -TX, -TY, load "argb.png"';
151#$EXPR = '
152# rotate W, H, 50, 50, counter 1/59.95, repeat_mirror,
153# clip X, Y, W, H, repeat_mirror,
154# load "/root/pix/das_fette_schwein.jpg"
155#';
156#$EXPR = 'solid "red"';
157#$EXPR = 'blur root, 10, 10'
158#$EXPR = 'blur move (root, -x, -y), 5, 5'
159#resize load "/root/pix/das_fette_schwein.jpg", w, h
160 196
161our $HOME; 197our $HOME;
162our ($self, $old, $new); 198our ($self, $old, $new);
163our ($x, $y, $w, $h); 199our ($x, $y, $w, $h);
164 200
211=item solid $width, $height, $colour 247=item solid $width, $height, $colour
212 248
213Creates a new image and completely fills it with the given colour. The 249Creates a new image and completely fills it with the given colour. The
214image is set to tiling mode. 250image is set to tiling mode.
215 251
216If <$width> and C<$height> are omitted, it creates a 1x1 image, which is 252If C<$width> and C<$height> are omitted, it creates a 1x1 image, which is
217useful for solid backgrounds or for use in filtering effects. 253useful for solid backgrounds or for use in filtering effects.
218 254
219=cut 255=cut
220 256
221 sub solid($$;$) { 257 sub solid($;$$) {
222 my $colour = pop; 258 my $colour = pop;
223 259
224 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); 260 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1);
225 $img->fill ($colour); 261 $img->fill ($colour);
226 $img 262 $img
228 264
229=back 265=back
230 266
231=head2 VARIABLES 267=head2 VARIABLES
232 268
233The following functions provide variable data such as the terminal 269The following functions provide variable data such as the terminal window
270dimensions. They are not (Perl-) variables, they jsut return stuff that
234window dimensions. Most of them make your expression sensitive to some 271varies. Most of them make your expression sensitive to some events, for
235events, for example using C<TW> (terminal width) means your expression is 272example using C<TW> (terminal width) means your expression is evaluated
236evaluated again when the terminal is resized. 273again when the terminal is resized.
237 274
238=over 4 275=over 4
239 276
240=item TX 277=item TX
241 278
562 599
563=item blur $radius_horz, $radius_vert, $img 600=item blur $radius_horz, $radius_vert, $img
564 601
565Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii 602Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii
566can also be specified separately. 603can also be specified separately.
604
605Blurring is often I<very> slow, at least compared or other
606operators. Larger blur radii are slower than smaller ones, too, so if you
607don't want to freeze your screen for long times, start experimenting with
608low values for radius (<5).
567 609
568=cut 610=cut
569 611
570 sub blur($$;$) { 612 sub blur($$;$) {
571 my $img = pop; 613 my $img = pop;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines