1 | #! perl |
1 | #! perl |
2 | |
2 | |
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 | #:META:X_RESOURCE:%.interval:seconds:minimum time between updates |
6 | #TODO: once, rootalign |
|
|
7 | |
6 | |
8 | =head1 NAME |
7 | =head1 NAME |
9 | |
8 | |
10 | background - manage terminal background |
9 | background - manage terminal background |
11 | |
10 | |
12 | =head1 SYNOPSIS |
11 | =head1 SYNOPSIS |
13 | |
12 | |
14 | urxvt --background-expr 'background expression' |
13 | urxvt --background-expr 'background expression' |
15 | --background-border |
14 | --background-border |
|
|
15 | --background-interval seconds |
16 | |
16 | |
17 | =head1 DESCRIPTION |
17 | =head1 DESCRIPTION |
18 | |
18 | |
19 | This extension manages the terminal background by creating a picture that |
19 | This extension manages the terminal background by creating a picture that |
20 | is behind the text, replacing the normal background colour. |
20 | is behind the text, replacing the normal background colour. |
… | |
… | |
57 | |
57 | |
58 | For example, an expression such as C<scale load "$HOME/mybg.png"> scales the |
58 | For example, an expression such as C<scale load "$HOME/mybg.png"> scales the |
59 | 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 |
60 | 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 |
61 | example. That ensures that the picture always fills the terminal, even |
61 | example. That ensures that the picture always fills the terminal, even |
62 | after it's size changes. |
62 | after its size changes. |
63 | |
63 | |
64 | =head2 EXPRESSIONS |
64 | =head2 EXPRESSIONS |
65 | |
65 | |
66 | Expressions are normal Perl expressions, in fact, they are Perl blocks - |
66 | Expressions are normal Perl expressions, in fact, they are Perl blocks - |
67 | which means you could use multiple lines and statements: |
67 | which means you could use multiple lines and statements: |
… | |
… | |
71 | return scale load "$HOME/weekday.png"; |
71 | return scale load "$HOME/weekday.png"; |
72 | } else { |
72 | } else { |
73 | return scale load "$HOME/sunday.png"; |
73 | return scale load "$HOME/sunday.png"; |
74 | } |
74 | } |
75 | |
75 | |
76 | This expression gets evaluated once per hour. It will set F<sunday.png> as |
76 | This expression is evaluated once per hour. It will set F<sunday.png> as |
77 | background on Sundays, and F<weekday.png> on all other days. |
77 | background on Sundays, and F<weekday.png> on all other days. |
78 | |
78 | |
79 | Fortunately, we expect that most expressions will be much simpler, with |
79 | Fortunately, we expect that most expressions will be much simpler, with |
80 | little Perl knowledge needed. |
80 | little Perl knowledge needed. |
81 | |
81 | |
… | |
… | |
99 | its result becomes the argument to the C<scale> function. |
99 | its result becomes the argument to the C<scale> function. |
100 | |
100 | |
101 | Many operators also allow some parameters preceding the input image |
101 | Many operators also allow some parameters preceding the input image |
102 | that modify its behaviour. For example, C<scale> without any additional |
102 | that modify its behaviour. For example, C<scale> without any additional |
103 | arguments scales the image to size of the terminal window. If you specify |
103 | arguments scales the image to size of the terminal window. If you specify |
104 | an additional argument, it uses it as a percentage: |
104 | an additional argument, it uses it as a scale factor (multiply by 100 to |
|
|
105 | get a percentage): |
105 | |
106 | |
106 | scale 200, load "$HOME/mypic.png" |
107 | scale 2, load "$HOME/mypic.png" |
107 | |
108 | |
108 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
109 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
109 | has now two arguments, the C<200> and the C<load> expression, while |
110 | has now two arguments, the C<200> and the C<load> expression, while |
110 | C<load> only has one argument. Arguments are separated from each other by |
111 | C<load> only has one argument. Arguments are separated from each other by |
111 | commas. |
112 | commas. |
112 | |
113 | |
113 | Scale also accepts two arguments, which are then separate factors for both |
114 | Scale also accepts two arguments, which are then separate factors for both |
114 | horizontal and vertical dimensions. For example, this halves the image |
115 | horizontal and vertical dimensions. For example, this halves the image |
115 | width and doubles the image height: |
116 | width and doubles the image height: |
116 | |
117 | |
117 | scale 50, 200, load "$HOME/mypic.png" |
118 | scale 0.5, 2, load "$HOME/mypic.png" |
118 | |
119 | |
119 | Other effects than scalign are also readily available, for exmaple, you can |
120 | Other effects than scaling are also readily available, for example, you can |
120 | tile the image to fill the whole window, instead of resizing it: |
121 | tile the image to fill the whole window, instead of resizing it: |
121 | |
122 | |
122 | tile load "$HOME/mypic.png" |
123 | tile load "$HOME/mypic.png" |
123 | |
124 | |
124 | In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator |
125 | In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator |
… | |
… | |
137 | pseudo-transparency, as the image seems to be static while the window is |
138 | pseudo-transparency, as the image seems to be static while the window is |
138 | moved around. |
139 | moved around. |
139 | |
140 | |
140 | =head2 CYCLES AND CACHING |
141 | =head2 CYCLES AND CACHING |
141 | |
142 | |
|
|
143 | =head3 C<load> et al. |
|
|
144 | |
142 | As has been mentioned before, the expression might be evaluated multiple |
145 | As has been mentioned before, the expression might be evaluated multiple |
143 | times. Each time the expression is reevaluated, a new cycle is said to |
146 | times. Each time the expression is reevaluated, a new cycle is said to |
144 | have begun. Many operators cache their results till the next cycle. |
147 | have begun. Many operators cache their results till the next cycle. |
145 | |
148 | |
146 | For example, the C<load> operator keeps a copy of the image. If it is |
149 | For example, the C<load> operator keeps a copy of the image. If it is |
… | |
… | |
150 | This only works for one cycle though, so as long as you load the same |
153 | 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 |
154 | image every time, it will always be cached, but when you load a different |
152 | image, it will forget about the first one. |
155 | image, it will forget about the first one. |
153 | |
156 | |
154 | This allows you to either speed things up by keeping multiple images in |
157 | This allows you to either speed things up by keeping multiple images in |
155 | memory, or comserve memory by loading images more often. |
158 | memory, or conserve memory by loading images more often. |
156 | |
159 | |
157 | For example, you can keep two images in memory and use a random one like |
160 | For example, you can keep two images in memory and use a random one like |
158 | this: |
161 | this: |
159 | |
162 | |
160 | my $img1 = load "img1.png"; |
163 | my $img1 = load "img1.png"; |
… | |
… | |
170 | |
173 | |
171 | Here, a path is selected randomly, and load is only called for one image, |
174 | 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 |
175 | 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. |
176 | decides to use the other path, then it will have to load that image again. |
174 | |
177 | |
|
|
178 | =head3 C<once { ... }> |
|
|
179 | |
|
|
180 | Another way to cache expensive operations is to use C<once { ... }>. The |
|
|
181 | C<once> operator takes a block of multiple statements enclosed by C<{}> |
|
|
182 | and evaluates it only.. once, returning any images the last statement |
|
|
183 | returned. Further calls simply produce the values from the cache. |
|
|
184 | |
|
|
185 | This is most useful for expensive operations, such as C<blur>: |
|
|
186 | |
|
|
187 | rootalign once { blur 20, root } |
|
|
188 | |
|
|
189 | This makes a blurred copy of the root background once, and on subsequent |
|
|
190 | calls, just root-aligns it. Since C<blur> is usually quite slow and |
|
|
191 | C<rootalign> is quite fast, this trades extra memory (For the cached |
|
|
192 | blurred pixmap) with speed (blur only needs to be redone when root |
|
|
193 | changes). |
|
|
194 | |
175 | =head1 REFERENCE |
195 | =head1 REFERENCE |
176 | |
196 | |
177 | =head2 COMMAND LINE SWITCHES |
197 | =head2 COMMAND LINE SWITCHES |
178 | |
198 | |
179 | =over 4 |
199 | =over 4 |
… | |
… | |
188 | overwriting borders and any other areas, such as the scrollbar. |
208 | overwriting borders and any other areas, such as the scrollbar. |
189 | |
209 | |
190 | Specifying this flag changes the behaviour, so that the image only |
210 | Specifying this flag changes the behaviour, so that the image only |
191 | replaces the background of the character area. |
211 | replaces the background of the character area. |
192 | |
212 | |
|
|
213 | =item --background-interval seconds |
|
|
214 | |
|
|
215 | Since some operations in the underlying XRender extension can effectively |
|
|
216 | freeze your X-server for prolonged time, this extension enforces a minimum |
|
|
217 | time between updates, which is normally about 0.1 seconds. |
|
|
218 | |
|
|
219 | If you want to do updates more often, you can decrease this safety |
|
|
220 | interval with this switch. |
|
|
221 | |
193 | =back |
222 | =back |
194 | |
223 | |
195 | =cut |
224 | =cut |
196 | |
225 | |
|
|
226 | our %_IMG_CACHE; |
197 | our $HOME; |
227 | our $HOME; |
198 | our ($self, $old, $new); |
228 | our ($self, $frame); |
199 | our ($x, $y, $w, $h); |
229 | our ($x, $y, $w, $h); |
200 | |
230 | |
201 | # enforce at least this interval between updates |
231 | # enforce at least this interval between updates |
202 | our $MIN_INTERVAL = 1/100; |
232 | our $MIN_INTERVAL = 6/59.951; |
203 | |
233 | |
204 | { |
234 | { |
205 | package urxvt::bgdsl; # background language |
235 | package urxvt::bgdsl; # background language |
|
|
236 | |
|
|
237 | sub FR_PARENT() { 0 } # parent frame, if any - must be #0 |
|
|
238 | sub FR_CACHE () { 1 } # cached values |
|
|
239 | sub FR_AGAIN () { 2 } # what this expr is sensitive to |
|
|
240 | sub FR_STATE () { 3 } # watchers etc. |
|
|
241 | |
|
|
242 | use List::Util qw(min max sum shuffle); |
206 | |
243 | |
207 | =head2 PROVIDERS/GENERATORS |
244 | =head2 PROVIDERS/GENERATORS |
208 | |
245 | |
209 | These functions provide an image, by loading it from disk, grabbing it |
246 | These functions provide an image, by loading it from disk, grabbing it |
210 | from the root screen or by simply generating it. They are used as starting |
247 | from the root screen or by simply generating it. They are used as starting |
… | |
… | |
215 | =item load $path |
252 | =item load $path |
216 | |
253 | |
217 | Loads the image at the given C<$path>. The image is set to plane tiling |
254 | Loads the image at the given C<$path>. The image is set to plane tiling |
218 | mode. |
255 | mode. |
219 | |
256 | |
220 | Loaded images will be cached for one cycle. |
257 | Loaded images will be cached for one cycle, and shared between temrinals |
|
|
258 | running in the same process (e.g. in C<urxvtd>). |
|
|
259 | |
|
|
260 | #=item load_uc $path |
|
|
261 | # |
|
|
262 | #Load uncached - same as load, but does not cache the image. This function |
|
|
263 | #is most useufl if you want to optimise a background expression in some |
|
|
264 | #way. |
221 | |
265 | |
222 | =cut |
266 | =cut |
223 | |
267 | |
224 | sub load($) { |
268 | sub load($) { |
225 | my ($path) = @_; |
269 | my ($path) = @_; |
226 | |
270 | |
227 | $new->{load}{$path} = $old->{load}{$path} || $self->new_img_from_file ($path); |
271 | $_IMG_CACHE{$path} || do { |
|
|
272 | my $img = $self->new_img_from_file ($path); |
|
|
273 | Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); |
|
|
274 | $img |
|
|
275 | } |
228 | } |
276 | } |
229 | |
277 | |
230 | =item root |
278 | =item root |
231 | |
279 | |
232 | Returns the root window pixmap, that is, hopefully, the background image |
280 | Returns the root window pixmap, that is, hopefully, the background image |
233 | of your screen. The image is set to extend mode. |
281 | of your screen. |
234 | |
282 | |
235 | This function makes your expression root sensitive, that means it will be |
283 | This function makes your expression root sensitive, that means it will be |
236 | reevaluated when the bg image changes. |
284 | reevaluated when the bg image changes. |
237 | |
285 | |
238 | =cut |
286 | =cut |
239 | |
287 | |
240 | sub root() { |
288 | sub root() { |
241 | $new->{rootpmap_sensitive} = 1; |
289 | $frame->[FR_AGAIN]{rootpmap} = 1; |
242 | die "root op not supported, exg, we need you"; |
290 | $self->new_img_from_root |
243 | } |
291 | } |
244 | |
292 | |
245 | =item solid $colour |
293 | =item solid $colour |
246 | |
294 | |
247 | =item solid $width, $height, $colour |
295 | =item solid $width, $height, $colour |
… | |
… | |
255 | =cut |
303 | =cut |
256 | |
304 | |
257 | sub solid($;$$) { |
305 | sub solid($;$$) { |
258 | my $colour = pop; |
306 | my $colour = pop; |
259 | |
307 | |
260 | my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); |
308 | my $img = $self->new_img (urxvt::PictStandardARGB32, 0, 0, $_[0] || 1, $_[1] || 1); |
261 | $img->fill ($colour); |
309 | $img->fill ($colour); |
262 | $img |
310 | $img |
263 | } |
311 | } |
264 | |
312 | |
265 | =back |
313 | =item clone $img |
266 | |
314 | |
267 | =head2 VARIABLES |
315 | Returns an exact copy of the image. This is useful if you want to have |
|
|
316 | multiple copies of the same image to apply different effects to. |
268 | |
317 | |
269 | The following functions provide variable data such as the terminal window |
|
|
270 | dimensions. They are not (Perl-) variables, they jsut return stuff that |
|
|
271 | varies. Most of them make your expression sensitive to some events, for |
|
|
272 | example using C<TW> (terminal width) means your expression is evaluated |
|
|
273 | again when the terminal is resized. |
|
|
274 | |
|
|
275 | =over 4 |
|
|
276 | |
|
|
277 | =item TX |
|
|
278 | |
|
|
279 | =item TY |
|
|
280 | |
|
|
281 | Return the X and Y coordinates of the terminal window (the terminal |
|
|
282 | window is the full window by default, and the character area only when in |
|
|
283 | border-respect mode). |
|
|
284 | |
|
|
285 | Using these functions make your expression sensitive to window moves. |
|
|
286 | |
|
|
287 | These functions are mainly useful to align images to the root window. |
|
|
288 | |
|
|
289 | Example: load an image and align it so it looks as if anchored to the |
|
|
290 | background. |
|
|
291 | |
|
|
292 | move -TX, -TY, load "mybg.png" |
|
|
293 | |
|
|
294 | =item TW |
|
|
295 | |
|
|
296 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
|
|
297 | terminal window is the full window by default, and the character area only |
|
|
298 | when in border-respect mode). |
|
|
299 | |
|
|
300 | Using these functions make your expression sensitive to window resizes. |
|
|
301 | |
|
|
302 | These functions are mainly useful to scale images, or to clip images to |
|
|
303 | the window size to conserve memory. |
|
|
304 | |
|
|
305 | Example: take the screen background, clip it to the window size, blur it a |
|
|
306 | bit, align it to the window position and use it as background. |
|
|
307 | |
|
|
308 | clip move -TX, -TY, blur 5, root |
|
|
309 | |
|
|
310 | =cut |
318 | =cut |
311 | |
319 | |
312 | sub TX() { $new->{position_sensitive} = 1; $x } |
|
|
313 | sub TY() { $new->{position_sensitive} = 1; $y } |
|
|
314 | sub TW() { $new->{size_sensitive} = 1; $w } |
|
|
315 | sub TH() { $new->{size_sensitive} = 1; $h } |
|
|
316 | |
|
|
317 | =item now |
|
|
318 | |
|
|
319 | Returns the current time as (fractional) seconds since the epoch. |
|
|
320 | |
|
|
321 | Using this expression does I<not> make your expression sensitive to time, |
|
|
322 | but the next two functions do. |
|
|
323 | |
|
|
324 | =item again $seconds |
|
|
325 | |
|
|
326 | When this function is used the expression will be reevaluated again in |
|
|
327 | C<$seconds> seconds. |
|
|
328 | |
|
|
329 | Example: load some image and rotate it according to the time of day (as if it were |
|
|
330 | the hour pointer of a clock). Update this image every minute. |
|
|
331 | |
|
|
332 | again 60; rotate TW, TH, 50, 50, (now % 86400) * -720 / 86400, scale load "myclock.png" |
|
|
333 | |
|
|
334 | =item counter $seconds |
|
|
335 | |
|
|
336 | Like C<again>, but also returns an increasing counter value, starting at |
|
|
337 | 0, which might be useful for some simple animation effects. |
|
|
338 | |
|
|
339 | =cut |
|
|
340 | |
|
|
341 | sub now() { urxvt::NOW } |
|
|
342 | |
|
|
343 | sub again($) { |
|
|
344 | $new->{again} = $_[0]; |
|
|
345 | } |
|
|
346 | |
|
|
347 | sub counter($) { |
320 | sub clone($) { |
348 | $new->{again} = $_[0]; |
321 | $_[0]->clone |
349 | $self->{counter} + 0 |
|
|
350 | } |
322 | } |
351 | |
323 | |
352 | =back |
324 | =item merge $img ... |
|
|
325 | |
|
|
326 | Takes any number of images and merges them together, creating a single |
|
|
327 | image containing them all. The tiling mode of the first image is used as |
|
|
328 | the tiling mdoe of the resulting image. |
|
|
329 | |
|
|
330 | This function is called automatically when an expression returns multiple |
|
|
331 | images. |
|
|
332 | |
|
|
333 | =cut |
|
|
334 | |
|
|
335 | sub merge(@) { |
|
|
336 | return $_[0] unless $#_; |
|
|
337 | |
|
|
338 | # rather annoyingly clumsy, but optimisation is for another time |
|
|
339 | |
|
|
340 | my $x0 = +1e9; |
|
|
341 | my $y0 = +1e9; |
|
|
342 | my $x1 = -1e9; |
|
|
343 | my $y1 = -1e9; |
|
|
344 | |
|
|
345 | for (@_) { |
|
|
346 | my ($x, $y, $w, $h) = $_->geometry; |
|
|
347 | |
|
|
348 | $x0 = $x if $x0 > $x; |
|
|
349 | $y0 = $y if $y0 > $y; |
|
|
350 | |
|
|
351 | $x += $w; |
|
|
352 | $y += $h; |
|
|
353 | |
|
|
354 | $x1 = $x if $x1 < $x; |
|
|
355 | $y1 = $y if $y1 < $y; |
|
|
356 | } |
|
|
357 | |
|
|
358 | my $base = $self->new_img (urxvt::PictStandardARGB32, $x0, $y0, $x1 - $x0, $y1 - $y0); |
|
|
359 | $base->repeat_mode ($_[0]->repeat_mode); |
|
|
360 | $base->fill ([0, 0, 0, 0]); |
|
|
361 | |
|
|
362 | $base->draw ($_) |
|
|
363 | for @_; |
|
|
364 | |
|
|
365 | $base |
|
|
366 | } |
353 | |
367 | |
354 | =head2 TILING MODES |
368 | =head2 TILING MODES |
355 | |
369 | |
356 | The following operators modify the tiling mode of an image, that is, the |
370 | The following operators modify the tiling mode of an image, that is, the |
357 | way that pixels outside the image area are painted when the image is used. |
371 | way that pixels outside the image area are painted when the image is used. |
… | |
… | |
387 | become transparent. This mode is most useful when you want to place an |
401 | become transparent. This mode is most useful when you want to place an |
388 | image over another image or the background colour while leaving all |
402 | image over another image or the background colour while leaving all |
389 | background pixels outside the image unchanged. |
403 | background pixels outside the image unchanged. |
390 | |
404 | |
391 | Example: load an image and display it in the upper left corner. The rest |
405 | Example: load an image and display it in the upper left corner. The rest |
392 | of the space is left "empty" (transparent or wahtever your compisotr does |
406 | of the space is left "empty" (transparent or whatever your compositor does |
393 | in alpha mode, else background colour). |
407 | in alpha mode, else background colour). |
394 | |
408 | |
395 | pad load "mybg.png" |
409 | pad load "mybg.png" |
396 | |
410 | |
397 | =item extend $img |
411 | =item extend $img |
398 | |
412 | |
399 | Extends the image over the whole plane, using the closest pixel in the |
413 | Extends the image over the whole plane, using the closest pixel in the |
400 | area outside the image. This mode is mostly useful when you more complex |
414 | area outside the image. This mode is mostly useful when you use more complex |
401 | filtering operations and want the pixels outside the image to have the |
415 | filtering operations and want the pixels outside the image to have the |
402 | same values as the pixels near the edge. |
416 | same values as the pixels near the edge. |
403 | |
417 | |
404 | Example: just for curiosity, how does this pixel extension stuff work? |
418 | Example: just for curiosity, how does this pixel extension stuff work? |
405 | |
419 | |
… | |
… | |
431 | $img |
445 | $img |
432 | } |
446 | } |
433 | |
447 | |
434 | =back |
448 | =back |
435 | |
449 | |
436 | =head2 PIXEL OPERATORS |
450 | =head2 VARIABLE VALUES |
437 | |
451 | |
438 | The following operators modify the image pixels in various ways. |
452 | The following functions provide variable data such as the terminal window |
|
|
453 | dimensions. They are not (Perl-) variables, they just return stuff that |
|
|
454 | varies. Most of them make your expression sensitive to some events, for |
|
|
455 | example using C<TW> (terminal width) means your expression is evaluated |
|
|
456 | again when the terminal is resized. |
439 | |
457 | |
440 | =over 4 |
458 | =over 4 |
441 | |
459 | |
442 | =item clone $img |
460 | =item TX |
443 | |
461 | |
444 | Returns an exact copy of the image. |
462 | =item TY |
445 | |
463 | |
446 | =cut |
464 | Return the X and Y coordinates of the terminal window (the terminal |
|
|
465 | window is the full window by default, and the character area only when in |
|
|
466 | border-respect mode). |
447 | |
467 | |
|
|
468 | Using these functions make your expression sensitive to window moves. |
|
|
469 | |
|
|
470 | These functions are mainly useful to align images to the root window. |
|
|
471 | |
|
|
472 | Example: load an image and align it so it looks as if anchored to the |
|
|
473 | background. |
|
|
474 | |
|
|
475 | move -TX, -TY, load "mybg.png" |
|
|
476 | |
|
|
477 | =item TW |
|
|
478 | |
|
|
479 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
|
|
480 | terminal window is the full window by default, and the character area only |
|
|
481 | when in border-respect mode). |
|
|
482 | |
|
|
483 | Using these functions make your expression sensitive to window resizes. |
|
|
484 | |
|
|
485 | These functions are mainly useful to scale images, or to clip images to |
|
|
486 | the window size to conserve memory. |
|
|
487 | |
|
|
488 | Example: take the screen background, clip it to the window size, blur it a |
|
|
489 | bit, align it to the window position and use it as background. |
|
|
490 | |
|
|
491 | clip move -TX, -TY, once { blur 5, root } |
|
|
492 | |
|
|
493 | =cut |
|
|
494 | |
|
|
495 | sub TX() { $frame->[FR_AGAIN]{position} = 1; $x } |
|
|
496 | sub TY() { $frame->[FR_AGAIN]{position} = 1; $y } |
|
|
497 | sub TW() { $frame->[FR_AGAIN]{size} = 1; $w } |
|
|
498 | sub TH() { $frame->[FR_AGAIN]{size} = 1; $h } |
|
|
499 | |
|
|
500 | =item now |
|
|
501 | |
|
|
502 | Returns the current time as (fractional) seconds since the epoch. |
|
|
503 | |
|
|
504 | Using this expression does I<not> make your expression sensitive to time, |
|
|
505 | but the next two functions do. |
|
|
506 | |
|
|
507 | =item again $seconds |
|
|
508 | |
|
|
509 | When this function is used the expression will be reevaluated again in |
|
|
510 | C<$seconds> seconds. |
|
|
511 | |
|
|
512 | Example: load some image and rotate it according to the time of day (as if it were |
|
|
513 | the hour pointer of a clock). Update this image every minute. |
|
|
514 | |
|
|
515 | again 60; rotate 50, 50, (now % 86400) * -720 / 86400, scale load "myclock.png" |
|
|
516 | |
|
|
517 | =item counter $seconds |
|
|
518 | |
|
|
519 | Like C<again>, but also returns an increasing counter value, starting at |
|
|
520 | 0, which might be useful for some simple animation effects. |
|
|
521 | |
|
|
522 | =cut |
|
|
523 | |
|
|
524 | sub now() { urxvt::NOW } |
|
|
525 | |
|
|
526 | sub again($) { |
|
|
527 | $frame->[FR_AGAIN]{time} = $_[0]; |
|
|
528 | } |
|
|
529 | |
448 | sub clone($) { |
530 | sub counter($) { |
449 | $_[0]->clone |
531 | $frame->[FR_AGAIN]{time} = $_[0]; |
|
|
532 | $frame->[FR_STATE]{counter} + 0 |
450 | } |
533 | } |
|
|
534 | |
|
|
535 | =back |
|
|
536 | |
|
|
537 | =head2 SHAPE CHANGING OPERATORS |
|
|
538 | |
|
|
539 | The following operators modify the shape, size or position of the image. |
|
|
540 | |
|
|
541 | =over 4 |
451 | |
542 | |
452 | =item clip $img |
543 | =item clip $img |
453 | |
544 | |
454 | =item clip $width, $height, $img |
545 | =item clip $width, $height, $img |
455 | |
546 | |
… | |
… | |
479 | $img->sub_rect ($_[0], $_[1], $w, $h) |
570 | $img->sub_rect ($_[0], $_[1], $w, $h) |
480 | } |
571 | } |
481 | |
572 | |
482 | =item scale $img |
573 | =item scale $img |
483 | |
574 | |
484 | =item scale $size_percent, $img |
575 | =item scale $size_factor, $img |
485 | |
576 | |
486 | =item scale $width_percent, $height_percent, $img |
577 | =item scale $width_factor, $height_factor, $img |
487 | |
578 | |
488 | Scales the image by the given percentages in horizontal |
579 | Scales the image by the given factors in horizontal |
489 | (C<$width_percent>) and vertical (C<$height_percent>) direction. |
580 | (C<$width>) and vertical (C<$height>) direction. |
490 | |
581 | |
491 | If only one percentage is give, it is used for both directions. |
582 | If only one factor is give, it is used for both directions. |
492 | |
583 | |
493 | If no percentages are given, scales the image to the window size without |
584 | If no factors are given, scales the image to the window size without |
494 | keeping aspect. |
585 | keeping aspect. |
495 | |
586 | |
496 | =item resize $width, $height, $img |
587 | =item resize $width, $height, $img |
497 | |
588 | |
498 | Resizes the image to exactly C<$width> times C<$height> pixels. |
589 | Resizes the image to exactly C<$width> times C<$height> pixels. |
499 | |
590 | |
500 | =cut |
591 | =item fit $img |
501 | |
592 | |
502 | #TODO: maximise, maximise_fill? |
593 | =item fit $width, $height, $img |
|
|
594 | |
|
|
595 | Fits the image into the given C<$width> and C<$height> without changing |
|
|
596 | aspect, or the terminal size. That means it will be shrunk or grown until |
|
|
597 | the whole image fits into the given area, possibly leaving borders. |
|
|
598 | |
|
|
599 | =item cover $img |
|
|
600 | |
|
|
601 | =item cover $width, $height, $img |
|
|
602 | |
|
|
603 | Similar to C<fit>, but shrinks or grows until all of the area is covered |
|
|
604 | by the image, so instead of potentially leaving borders, it will cut off |
|
|
605 | image data that doesn't fit. |
|
|
606 | |
|
|
607 | =cut |
503 | |
608 | |
504 | sub scale($;$;$) { |
609 | sub scale($;$;$) { |
505 | my $img = pop; |
610 | my $img = pop; |
506 | |
611 | |
507 | @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) |
612 | @_ == 2 ? $img->scale ($_[0] * $img->w, $_[1] * $img->h) |
508 | : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) |
613 | : @_ ? $img->scale ($_[0] * $img->w, $_[0] * $img->h) |
509 | : $img->scale (TW, TH) |
614 | : $img->scale (TW, TH) |
510 | } |
615 | } |
511 | |
616 | |
512 | sub resize($$$) { |
617 | sub resize($$$) { |
513 | my $img = pop; |
618 | my $img = pop; |
514 | $img->scale ($_[0], $_[1]) |
619 | $img->scale ($_[0], $_[1]) |
515 | } |
620 | } |
516 | |
621 | |
|
|
622 | sub fit($;$$) { |
|
|
623 | my $img = pop; |
|
|
624 | my $w = ($_[0] || TW) / $img->w; |
|
|
625 | my $h = ($_[1] || TH) / $img->h; |
|
|
626 | scale +(min $w, $h), $img |
|
|
627 | } |
|
|
628 | |
|
|
629 | sub cover($;$$) { |
|
|
630 | my $img = pop; |
|
|
631 | my $w = ($_[0] || TW) / $img->w; |
|
|
632 | my $h = ($_[1] || TH) / $img->h; |
|
|
633 | scale +(max $w, $h), $img |
|
|
634 | } |
|
|
635 | |
517 | =item move $dx, $dy, $img |
636 | =item move $dx, $dy, $img |
518 | |
637 | |
519 | Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in |
638 | Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in |
520 | the vertical. |
639 | the vertical. |
521 | |
640 | |
522 | Example: move the image right by 20 pixels and down by 30. |
641 | Example: move the image right by 20 pixels and down by 30. |
523 | |
642 | |
524 | move 20, 30, ... |
643 | move 20, 30, ... |
|
|
644 | |
|
|
645 | =item align $xalign, $yalign, $img |
|
|
646 | |
|
|
647 | Aligns the image according to a factor - C<0> means the image is moved to |
|
|
648 | the left or top edge (for C<$xalign> or C<$yalign>), C<0.5> means it is |
|
|
649 | exactly centered and C<1> means it touches the right or bottom edge. |
|
|
650 | |
|
|
651 | Example: remove any visible border around an image, center it vertically but move |
|
|
652 | it to the right hand side. |
|
|
653 | |
|
|
654 | align 1, 0.5, pad $img |
|
|
655 | |
|
|
656 | =item center $img |
|
|
657 | |
|
|
658 | =item center $width, $height, $img |
|
|
659 | |
|
|
660 | Centers the image, i.e. the center of the image is moved to the center of |
|
|
661 | the terminal window (or the box specified by C<$width> and C<$height> if |
|
|
662 | given). |
|
|
663 | |
|
|
664 | Example: load an image and center it. |
|
|
665 | |
|
|
666 | center pad load "mybg.png" |
525 | |
667 | |
526 | =item rootalign $img |
668 | =item rootalign $img |
527 | |
669 | |
528 | Moves the image so that it appears glued to the screen as opposed to the |
670 | Moves the image so that it appears glued to the screen as opposed to the |
529 | window. This gives the illusion of a larger area behind the window. It is |
671 | window. This gives the illusion of a larger area behind the window. It is |
… | |
… | |
535 | rootalign mirror load "mybg.png" |
677 | rootalign mirror load "mybg.png" |
536 | |
678 | |
537 | Example: take the screen background and align it, giving the illusion of |
679 | Example: take the screen background and align it, giving the illusion of |
538 | transparency as long as the window isn't in front of other windows. |
680 | transparency as long as the window isn't in front of other windows. |
539 | |
681 | |
540 | rootalign root |
682 | rootalign root |
541 | |
683 | |
542 | =cut |
684 | =cut |
543 | |
685 | |
544 | sub move($$;$) { |
686 | sub move($$;$) { |
545 | my $img = pop->clone; |
687 | my $img = pop->clone; |
546 | $img->move ($_[0], $_[1]); |
688 | $img->move ($_[0], $_[1]); |
547 | $img |
689 | $img |
548 | } |
690 | } |
549 | |
691 | |
|
|
692 | sub align($;$$) { |
|
|
693 | my $img = pop; |
|
|
694 | |
|
|
695 | move $_[0] * (TW - $img->w), |
|
|
696 | $_[1] * (TH - $img->h), |
|
|
697 | $img |
|
|
698 | } |
|
|
699 | |
|
|
700 | sub center($;$$) { |
|
|
701 | my $img = pop; |
|
|
702 | my $w = $_[0] || TW; |
|
|
703 | my $h = $_[1] || TH; |
|
|
704 | |
|
|
705 | move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img |
|
|
706 | } |
|
|
707 | |
550 | sub rootalign($) { |
708 | sub rootalign($) { |
551 | move -TX, -TY, $_[0] |
709 | move -TX, -TY, $_[0] |
552 | } |
710 | } |
553 | |
711 | |
|
|
712 | =item rotate $center_x, $center_y, $degrees |
|
|
713 | |
|
|
714 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
|
|
715 | pointer at C<$center_x> and C<$center_y> (specified as factor of image |
|
|
716 | width/height). |
|
|
717 | |
|
|
718 | #TODO# new width, height, maybe more operators? |
|
|
719 | |
|
|
720 | Example: rotate the image by 90 degrees |
|
|
721 | |
|
|
722 | =cut |
|
|
723 | |
|
|
724 | sub rotate($$$$) { |
|
|
725 | my $img = pop; |
|
|
726 | $img->rotate ( |
|
|
727 | $_[0] * ($img->w + $img->x), |
|
|
728 | $_[1] * ($img->h + $img->y), |
|
|
729 | $_[2] * (3.14159265 / 180), |
|
|
730 | ) |
|
|
731 | } |
|
|
732 | |
|
|
733 | =back |
|
|
734 | |
|
|
735 | =head2 COLOUR MODIFICATIONS |
|
|
736 | |
|
|
737 | The following operators change the pixels of the image. |
|
|
738 | |
|
|
739 | =over 4 |
|
|
740 | |
554 | =item contrast $factor, $img |
741 | =item contrast $factor, $img |
555 | |
742 | |
556 | =item contrast $r, $g, $b, $img |
743 | =item contrast $r, $g, $b, $img |
557 | |
744 | |
558 | =item contrast $r, $g, $b, $a, $img |
745 | =item contrast $r, $g, $b, $a, $img |
559 | |
746 | |
560 | Adjusts the I<contrast> of an image. |
747 | Adjusts the I<contrast> of an image. |
561 | |
748 | |
562 | #TODO# |
749 | The first form applies a single C<$factor> to red, green and blue, the |
|
|
750 | second form applies separate factors to each colour channel, and the last |
|
|
751 | form includes the alpha channel. |
563 | |
752 | |
|
|
753 | Values from 0 to 1 lower the contrast, values higher than 1 increase the |
|
|
754 | contrast. |
|
|
755 | |
|
|
756 | Due to limitations in the underlying XRender extension, lowering contrast |
|
|
757 | also reduces brightness, while increasing contrast currently also |
|
|
758 | increases brightness. |
|
|
759 | |
564 | =item brightness $factor, $img |
760 | =item brightness $bias, $img |
565 | |
761 | |
566 | =item brightness $r, $g, $b, $img |
762 | =item brightness $r, $g, $b, $img |
567 | |
763 | |
568 | =item brightness $r, $g, $b, $a, $img |
764 | =item brightness $r, $g, $b, $a, $img |
569 | |
765 | |
570 | Adjusts the brightness of an image. |
766 | Adjusts the brightness of an image. |
|
|
767 | |
|
|
768 | The first form applies a single C<$bias> to red, green and blue, the |
|
|
769 | second form applies separate biases to each colour channel, and the last |
|
|
770 | form includes the alpha channel. |
|
|
771 | |
|
|
772 | Values less than 0 reduce brightness, while values larger than 0 increase |
|
|
773 | it. Useful range is from -1 to 1 - the former results in a black, the |
|
|
774 | latter in a white picture. |
|
|
775 | |
|
|
776 | Due to idiosyncrasies in the underlying XRender extension, biases less |
|
|
777 | than zero can be I<very> slow. |
571 | |
778 | |
572 | =cut |
779 | =cut |
573 | |
780 | |
574 | sub contrast($$;$$;$) { |
781 | sub contrast($$;$$;$) { |
575 | my $img = pop; |
782 | my $img = pop; |
576 | my ($r, $g, $b, $a) = @_; |
783 | my ($r, $g, $b, $a) = @_; |
577 | |
784 | |
578 | ($g, $b) = ($r, $r) if @_ < 4; |
785 | ($g, $b) = ($r, $r) if @_ < 3; |
579 | $a = 1 if @_ < 5; |
786 | $a = 1 if @_ < 4; |
580 | |
787 | |
581 | $img = $img->clone; |
788 | $img = $img->clone; |
582 | $img->contrast ($r, $g, $b, $a); |
789 | $img->contrast ($r, $g, $b, $a); |
583 | $img |
790 | $img |
584 | } |
791 | } |
585 | |
792 | |
586 | sub brightness($$;$$;$) { |
793 | sub brightness($$;$$;$) { |
587 | my $img = pop; |
794 | my $img = pop; |
588 | my ($r, $g, $b, $a) = @_; |
795 | my ($r, $g, $b, $a) = @_; |
589 | |
796 | |
590 | ($g, $b) = ($r, $r) if @_ < 4; |
797 | ($g, $b) = ($r, $r) if @_ < 3; |
591 | $a = 1 if @_ < 5; |
798 | $a = 1 if @_ < 4; |
592 | |
799 | |
593 | $img = $img->clone; |
800 | $img = $img->clone; |
594 | $img->brightness ($r, $g, $b, $a); |
801 | $img->brightness ($r, $g, $b, $a); |
595 | $img |
802 | $img |
596 | } |
803 | } |
… | |
… | |
612 | sub blur($$;$) { |
819 | sub blur($$;$) { |
613 | my $img = pop; |
820 | my $img = pop; |
614 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
821 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
615 | } |
822 | } |
616 | |
823 | |
617 | =item rotate $new_width, $new_height, $center_x, $center_y, $degrees |
|
|
618 | |
|
|
619 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
|
|
620 | pointer at C<$center_x> and C<$center_y> (specified as percentage of image |
|
|
621 | width/height), generating a new image with width C<$new_width> and height |
|
|
622 | C<$new_height>. |
|
|
623 | |
|
|
624 | #TODO# new width, height, maybe more operators? |
|
|
625 | |
|
|
626 | Example: rotate the image by 90 degrees |
|
|
627 | |
|
|
628 | =cut |
|
|
629 | |
|
|
630 | sub rotate($$$$$$) { |
|
|
631 | my $img = pop; |
|
|
632 | $img->rotate ( |
|
|
633 | $_[0], |
|
|
634 | $_[1], |
|
|
635 | $_[2] * $img->w * .01, |
|
|
636 | $_[3] * $img->h * .01, |
|
|
637 | $_[4] * (3.14159265 / 180), |
|
|
638 | ) |
|
|
639 | } |
|
|
640 | |
|
|
641 | =back |
824 | =back |
642 | |
825 | |
|
|
826 | =head2 OTHER STUFF |
|
|
827 | |
|
|
828 | Anything that didn't fit any of the other categories, even after applying |
|
|
829 | force and closing our eyes. |
|
|
830 | |
|
|
831 | =over 4 |
|
|
832 | |
|
|
833 | =item once { ... } |
|
|
834 | |
|
|
835 | This function takes a code block as argument, that is, one or more |
|
|
836 | statements enclosed by braces. |
|
|
837 | |
|
|
838 | The trick is that this code block is only evaluated once - future calls |
|
|
839 | will simply return the original image (yes, it should only be used with |
|
|
840 | images). |
|
|
841 | |
|
|
842 | This can be extremely useful to avoid redoing the same slow operations |
|
|
843 | again and again- for example, if your background expression takes the root |
|
|
844 | background, blurs it and then root-aligns it it would have to blur the |
|
|
845 | root background on every window move or resize. |
|
|
846 | |
|
|
847 | In fact, urxvt itself encloses the whole expression in some kind of |
|
|
848 | C<once> block so it only is reevaluated as required. |
|
|
849 | |
|
|
850 | Putting the blur into a C<once> block will make sure the blur is only done |
|
|
851 | once: |
|
|
852 | |
|
|
853 | rootlign once { blur 10, root } |
|
|
854 | |
|
|
855 | This leaves the question of how to force reevaluation of the block, |
|
|
856 | in case the root background changes: If expression inside the block |
|
|
857 | is sensitive to some event (root background changes, window geometry |
|
|
858 | changes), then it will be reevaluated automatically as needed. |
|
|
859 | |
|
|
860 | =item once_again |
|
|
861 | |
|
|
862 | Resets all C<once> block as if they had never been called, i.e. on the |
|
|
863 | next call they will be reevaluated again. |
|
|
864 | |
|
|
865 | =cut |
|
|
866 | |
|
|
867 | sub once(&) { |
|
|
868 | my $id = $_[0]+0; |
|
|
869 | |
|
|
870 | local $frame = $self->{frame_cache}{$id} ||= [$frame]; |
|
|
871 | |
|
|
872 | unless ($frame->[FR_CACHE]) { |
|
|
873 | $frame->[FR_CACHE] = [ $_[0]() ]; |
|
|
874 | |
|
|
875 | my $self = $self; |
|
|
876 | my $frame = $frame; |
|
|
877 | Scalar::Util::weaken $frame; |
|
|
878 | $self->compile_frame ($frame, sub { |
|
|
879 | # clear this frame cache, also for all parents |
|
|
880 | for (my $frame = $frame; $frame; $frame = $frame->[0]) { |
|
|
881 | undef $frame->[FR_CACHE]; |
|
|
882 | } |
|
|
883 | |
|
|
884 | unless ($self->{term}) { |
|
|
885 | use Data::Dump; |
|
|
886 | ddx $frame; |
|
|
887 | exit; |
|
|
888 | } |
|
|
889 | |
|
|
890 | $self->recalculate; |
|
|
891 | }); |
|
|
892 | }; |
|
|
893 | |
|
|
894 | # in scalar context we always return the first original result, which |
|
|
895 | # is not quite how perl works. |
|
|
896 | wantarray |
|
|
897 | ? @{ $frame->[FR_CACHE] } |
|
|
898 | : $frame->[FR_CACHE][0] |
|
|
899 | } |
|
|
900 | |
|
|
901 | sub once_again() { |
|
|
902 | delete $self->{frame_cache}; |
|
|
903 | } |
|
|
904 | |
|
|
905 | =back |
|
|
906 | |
643 | =cut |
907 | =cut |
644 | |
908 | |
645 | } |
909 | } |
646 | |
910 | |
647 | sub parse_expr { |
911 | sub parse_expr { |
648 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
912 | my $expr = eval |
|
|
913 | "sub {\n" |
|
|
914 | . "package urxvt::bgdsl;\n" |
|
|
915 | . "#line 0 'background expression'\n" |
|
|
916 | . "$_[0]\n" |
|
|
917 | . "}"; |
649 | die if $@; |
918 | die if $@; |
650 | $expr |
919 | $expr |
651 | } |
920 | } |
652 | |
921 | |
653 | # compiles a parsed expression |
922 | # compiles a parsed expression |
654 | sub set_expr { |
923 | sub set_expr { |
655 | my ($self, $expr) = @_; |
924 | my ($self, $expr) = @_; |
656 | |
925 | |
|
|
926 | $self->{root} = []; |
657 | $self->{expr} = $expr; |
927 | $self->{expr} = $expr; |
658 | $self->recalculate; |
928 | $self->recalculate; |
|
|
929 | } |
|
|
930 | |
|
|
931 | # takes a hash of sensitivity indicators and installs watchers |
|
|
932 | sub compile_frame { |
|
|
933 | my ($self, $frame, $cb) = @_; |
|
|
934 | |
|
|
935 | my $state = $frame->[urxvt::bgdsl::FR_STATE] ||= {}; |
|
|
936 | my $again = $frame->[urxvt::bgdsl::FR_AGAIN]; |
|
|
937 | |
|
|
938 | # don't keep stuff alive |
|
|
939 | Scalar::Util::weaken $state; |
|
|
940 | |
|
|
941 | if ($again->{nested}) { |
|
|
942 | $state->{nested} = 1; |
|
|
943 | } else { |
|
|
944 | delete $state->{nested}; |
|
|
945 | } |
|
|
946 | |
|
|
947 | if (my $interval = $again->{time}) { |
|
|
948 | $state->{time} = [$interval, urxvt::timer->new->after ($interval)->interval ($interval)] |
|
|
949 | if $state->{time}[0] != $interval; |
|
|
950 | |
|
|
951 | # callback *might* have changed, although we could just rule that out |
|
|
952 | $state->{time}[1]->cb (sub { |
|
|
953 | ++$state->{counter}; |
|
|
954 | $cb->(); |
|
|
955 | }); |
|
|
956 | } else { |
|
|
957 | delete $state->{time}; |
|
|
958 | } |
|
|
959 | |
|
|
960 | if ($again->{position}) { |
|
|
961 | $state->{position} = $self->on (position_change => $cb); |
|
|
962 | } else { |
|
|
963 | delete $state->{position}; |
|
|
964 | } |
|
|
965 | |
|
|
966 | if ($again->{size}) { |
|
|
967 | $state->{size} = $self->on (size_change => $cb); |
|
|
968 | } else { |
|
|
969 | delete $state->{size}; |
|
|
970 | } |
|
|
971 | |
|
|
972 | if ($again->{rootpmap}) { |
|
|
973 | $state->{rootpmap} = $self->on (rootpmap_change => $cb); |
|
|
974 | } else { |
|
|
975 | delete $state->{rootpmap}; |
|
|
976 | } |
659 | } |
977 | } |
660 | |
978 | |
661 | # evaluate the current bg expression |
979 | # evaluate the current bg expression |
662 | sub recalculate { |
980 | sub recalculate { |
663 | my ($arg_self) = @_; |
981 | my ($arg_self) = @_; |
… | |
… | |
673 | |
991 | |
674 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
992 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
675 | |
993 | |
676 | # set environment to evaluate user expression |
994 | # set environment to evaluate user expression |
677 | |
995 | |
678 | local $self = $arg_self; |
996 | local $self = $arg_self; |
679 | |
|
|
680 | local $HOME = $ENV{HOME}; |
997 | local $HOME = $ENV{HOME}; |
681 | local $old = $self->{state}; |
998 | local $frame = []; |
682 | local $new = my $state = $self->{state} = {}; |
|
|
683 | |
999 | |
684 | ($x, $y, $w, $h) = |
|
|
685 | $self->background_geometry ($self->{border}); |
1000 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
686 | |
1001 | |
687 | # evaluate user expression |
1002 | # evaluate user expression |
688 | |
1003 | |
689 | my $img = eval { $self->{expr}->() }; |
1004 | my @img = eval { $self->{expr}->() }; |
690 | warn $@ if $@;#d# |
1005 | die $@ if $@; |
|
|
1006 | die "background-expr did not return anything.\n" unless @img; |
|
|
1007 | die "background-expr: expected image(s), got something else.\n" |
691 | die if !UNIVERSAL::isa $img, "urxvt::img"; |
1008 | if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; |
692 | |
1009 | |
693 | $state->{size_sensitive} = 1 |
1010 | my $img = urxvt::bgdsl::merge @img; |
|
|
1011 | |
|
|
1012 | $frame->[FR_AGAIN]{size} = 1 |
694 | if $img->repeat_mode != urxvt::RepeatNormal; |
1013 | if $img->repeat_mode != urxvt::RepeatNormal; |
695 | |
1014 | |
696 | # if the expression is sensitive to external events, prepare reevaluation then |
1015 | # if the expression is sensitive to external events, prepare reevaluation then |
697 | |
1016 | $self->compile_frame ($frame, sub { $arg_self->recalculate }); |
698 | my $repeat; |
|
|
699 | |
|
|
700 | if (my $again = $state->{again}) { |
|
|
701 | $repeat = 1; |
|
|
702 | my $self = $self; |
|
|
703 | $state->{timer} = $again == $old->{again} |
|
|
704 | ? $old->{timer} |
|
|
705 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
|
|
706 | ++$self->{counter}; |
|
|
707 | $self->recalculate |
|
|
708 | }); |
|
|
709 | } |
|
|
710 | |
|
|
711 | if (delete $state->{position_sensitive}) { |
|
|
712 | $repeat = 1; |
|
|
713 | $self->enable (position_change => sub { $_[0]->recalculate }); |
|
|
714 | } else { |
|
|
715 | $self->disable ("position_change"); |
|
|
716 | } |
|
|
717 | |
|
|
718 | if (delete $state->{size_sensitive}) { |
|
|
719 | $repeat = 1; |
|
|
720 | $self->enable (size_change => sub { $_[0]->recalculate }); |
|
|
721 | } else { |
|
|
722 | $self->disable ("size_change"); |
|
|
723 | } |
|
|
724 | |
|
|
725 | if (delete $state->{rootpmap_sensitive}) { |
|
|
726 | $repeat = 1; |
|
|
727 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
|
|
728 | } else { |
|
|
729 | $self->disable ("rootpmap_change"); |
|
|
730 | } |
|
|
731 | |
1017 | |
732 | # clear stuff we no longer need |
1018 | # clear stuff we no longer need |
733 | |
1019 | |
734 | %$old = (); |
1020 | # unless (%{ $frame->[FR_STATE] }) { |
735 | |
|
|
736 | unless ($repeat) { |
|
|
737 | delete $self->{state}; |
1021 | # delete $self->{state}; |
738 | delete $self->{expr}; |
1022 | # delete $self->{expr}; |
739 | } |
1023 | # } |
740 | |
1024 | |
741 | # set background pixmap |
1025 | # set background pixmap |
742 | |
1026 | |
743 | $self->set_background ($img, $self->{border}); |
1027 | $self->set_background ($img, $self->{border}); |
744 | $self->scr_recolour (0); |
1028 | $self->scr_recolour (0); |
… | |
… | |
746 | } |
1030 | } |
747 | |
1031 | |
748 | sub on_start { |
1032 | sub on_start { |
749 | my ($self) = @_; |
1033 | my ($self) = @_; |
750 | |
1034 | |
751 | my $expr = $self->x_resource ("background.expr") |
1035 | my $expr = $self->x_resource ("%.expr") |
752 | or return; |
1036 | or return; |
753 | |
1037 | |
|
|
1038 | $self->has_render |
|
|
1039 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
|
|
1040 | |
754 | $self->set_expr (parse_expr $expr); |
1041 | $self->set_expr (parse_expr $expr); |
755 | $self->{border} = $self->x_resource_boolean ("background.border"); |
1042 | $self->{border} = $self->x_resource_boolean ("%.border"); |
|
|
1043 | |
|
|
1044 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
756 | |
1045 | |
757 | () |
1046 | () |
758 | } |
1047 | } |
759 | |
1048 | |