… | |
… | |
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 | |
17 | This extension manages the terminal background by creating a picture that |
19 | This extension manages the terminal background by creating a picture that |
18 | is behind the text, replacing the normal background colour. |
20 | is behind the text, replacing the normal background colour. |
19 | |
21 | |
20 | It does so by evaluating a Perl expression that I<calculates> the image on |
22 | It does so by evaluating a Perl expression that I<calculates> the image on |
… | |
… | |
30 | |
32 | |
31 | Or specified as a X resource: |
33 | Or 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 | |
37 | At startup, just before the window is mapped for the first time, the |
39 | At startup, just before the window is mapped for the first time, the |
38 | expression is evaluated and must yield an image. The image is then |
40 | expression is evaluated and must yield an image. The image is then |
39 | extended as necessary to cover the whole terminal window, and is set as a |
41 | extended as necessary to cover the whole terminal window, and is set as a |
40 | background pixmap. |
42 | background pixmap. |
… | |
… | |
57 | image to the window size, so it relies on the window size and will |
59 | image to the window size, so it relies on the window size and will |
58 | be reevaluated each time it is changed, but not when it moves for |
60 | be reevaluated each time it is changed, but not when it moves for |
59 | example. That ensures that the picture always fills the terminal, even |
61 | example. That ensures that the picture always fills the terminal, even |
60 | after it's size changes. |
62 | after it's size changes. |
61 | |
63 | |
62 | =head3 EXPRESSIONS |
64 | =head2 EXPRESSIONS |
63 | |
65 | |
64 | Expressions are normal Perl expressions, in fact, they are Perl blocks - |
66 | Expressions are normal Perl expressions, in fact, they are Perl blocks - |
65 | which means you could use multiple lines and statements: |
67 | which 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 | |
74 | This expression gets evaluated once per hour. It will set F<sunday.png> as |
76 | This expression gets evaluated once per hour. It will set F<sunday.png> as |
75 | background on sundays, and F<weekday.png> on all other days. |
77 | background on Sundays, and F<weekday.png> on all other days. |
76 | |
78 | |
77 | Fortunately, we expect that most expressions will be much simpler, with |
79 | Fortunately, we expect that most expressions will be much simpler, with |
78 | little Perl knowledge needed. |
80 | little Perl knowledge needed. |
79 | |
81 | |
80 | Basically, you always start with a function that "generates" an image |
82 | Basically, you always start with a function that "generates" an image |
… | |
… | |
112 | horizontal and vertical dimensions. For example, this halves the image |
114 | horizontal and vertical dimensions. For example, this halves the image |
113 | width and doubles the image height: |
115 | width 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 | |
117 | TODO |
119 | Other effects than scalign are also readily available, for exmaple, you can |
|
|
120 | tile the image to fill the whole window, instead of resizing it: |
118 | |
121 | |
|
|
122 | tile load "$HOME/mypic.png" |
|
|
123 | |
|
|
124 | In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator |
|
|
125 | is kind of superfluous. |
|
|
126 | |
|
|
127 | Another common effect is to mirror the image, so that the same edges touch: |
|
|
128 | |
|
|
129 | mirror load "$HOME/mypic.png" |
|
|
130 | |
|
|
131 | This is also a typical background expression: |
|
|
132 | |
|
|
133 | rootalign root |
|
|
134 | |
|
|
135 | It first takes a snapshot of the screen background image, and then |
|
|
136 | moves it to the upper left corner of the screen - the result is |
|
|
137 | pseudo-transparency, as the image seems to be static while the window is |
|
|
138 | moved around. |
|
|
139 | |
119 | =head3 CYCLES AND CACHING |
140 | =head2 CYCLES AND CACHING |
120 | |
141 | |
121 | TODO |
142 | As has been mentioned before, the expression might be evaluated multiple |
122 | |
|
|
123 | Each time the expression is reevaluated, a new cycle is said to have begun. Many operators |
143 | times. Each time the expression is reevaluated, a new cycle is said to |
124 | cache their results till the next cycle. For example |
144 | have begun. Many operators cache their results till the next cycle. |
125 | |
145 | |
|
|
146 | For example, the C<load> operator keeps a copy of the image. If it is |
|
|
147 | asked to load the same image on the next cycle it will not load it again, |
|
|
148 | but return the cached copy. |
|
|
149 | |
|
|
150 | This only works for one cycle though, so as long as you load the same |
|
|
151 | image every time, it will always be cached, but when you load a different |
|
|
152 | image, it will forget about the first one. |
|
|
153 | |
|
|
154 | This allows you to either speed things up by keeping multiple images in |
|
|
155 | memory, or comserve memory by loading images more often. |
|
|
156 | |
|
|
157 | For example, you can keep two images in memory and use a random one like |
|
|
158 | this: |
|
|
159 | |
|
|
160 | my $img1 = load "img1.png"; |
|
|
161 | my $img2 = load "img2.png"; |
|
|
162 | (0.5 > rand) ? $img1 : $img2 |
|
|
163 | |
|
|
164 | Since both images are "loaded" every time the expression is evaluated, |
|
|
165 | they 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 | |
|
|
171 | Here, a path is selected randomly, and load is only called for one image, |
|
|
172 | so keeps only one image in memory. If, on the next evaluation, luck |
|
|
173 | decides 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 | |
… | |
… | |
142 | replaces the background of the character area. |
191 | replaces the background of the character area. |
143 | |
192 | |
144 | =back |
193 | =back |
145 | |
194 | |
146 | =cut |
195 | =cut |
147 | |
|
|
148 | our $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 | |
161 | our $HOME; |
197 | our $HOME; |
162 | our ($self, $old, $new); |
198 | our ($self, $old, $new); |
163 | our ($x, $y, $w, $h); |
199 | our ($x, $y, $w, $h); |
164 | |
200 | |
… | |
… | |
211 | =item solid $width, $height, $colour |
247 | =item solid $width, $height, $colour |
212 | |
248 | |
213 | Creates a new image and completely fills it with the given colour. The |
249 | Creates a new image and completely fills it with the given colour. The |
214 | image is set to tiling mode. |
250 | image is set to tiling mode. |
215 | |
251 | |
216 | If <$width> and C<$height> are omitted, it creates a 1x1 image, which is |
252 | If C<$width> and C<$height> are omitted, it creates a 1x1 image, which is |
217 | useful for solid backgrounds or for use in filtering effects. |
253 | useful 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 | |
233 | The following functions provide variable data such as the terminal |
269 | The following functions provide variable data such as the terminal window |
|
|
270 | dimensions. They are not (Perl-) variables, they jsut return stuff that |
234 | window dimensions. Most of them make your expression sensitive to some |
271 | varies. Most of them make your expression sensitive to some events, for |
235 | events, for example using C<TW> (terminal width) means your expression is |
272 | example using C<TW> (terminal width) means your expression is evaluated |
236 | evaluated again when the terminal is resized. |
273 | again 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 | |
565 | Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii |
602 | Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii |
566 | can also be specified separately. |
603 | can also be specified separately. |
|
|
604 | |
|
|
605 | Blurring is often I<very> slow, at least compared or other |
|
|
606 | operators. Larger blur radii are slower than smaller ones, too, so if you |
|
|
607 | don't want to freeze your screen for long times, start experimenting with |
|
|
608 | low 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; |