1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
3 | #:META:RESOURCE:%.expr:string:background expression |
4 | #:META:X_RESOURCE:%.border:boolean:respect the terminal border |
4 | #:META:RESOURCE:%.border:boolean:respect the terminal border |
5 | #:META:X_RESOURCE:%.interval:seconds:minimum time between updates |
5 | #:META:RESOURCE:%.interval:seconds:minimum time between updates |
|
|
6 | #:META:RESOURCE:pixmap:file[;geom]:set image as background |
|
|
7 | #:META:RESOURCE:backgroundPixmap:file[;geom]:set image as background |
|
|
8 | #:META:RESOURCE:tr:boolean:set root pixmap as background |
|
|
9 | #:META:RESOURCE:transparent:boolean:set root pixmap as background |
|
|
10 | #:META:RESOURCE:tint:color:tint background with color |
|
|
11 | #:META:RESOURCE:tintColor:color:tint background with color |
|
|
12 | #:META:RESOURCE:sh:number:shade background by number % |
|
|
13 | #:META:RESOURCE:shading:number:shade background by number % |
|
|
14 | #:META:RESOURCE:blr:HxV:gaussian-blur background with radii |
|
|
15 | #:META:RESOURCE:blurRadius:HxV:gaussian-blur background with radii |
6 | |
16 | |
7 | =head1 NAME |
17 | =head1 NAME |
8 | |
18 | |
9 | background - manage terminal background |
19 | background - manage terminal background |
10 | |
20 | |
11 | =head1 SYNOPSIS |
21 | =head1 SYNOPSIS |
12 | |
22 | |
13 | urxvt --background-expr 'background expression' |
23 | urxvt --background-expr 'background expression' |
14 | --background-border |
24 | --background-border |
15 | --background-interval seconds |
25 | --background-interval seconds |
16 | |
26 | |
|
|
27 | =head1 QUICK AND DIRTY CHEAT SHEET |
|
|
28 | |
|
|
29 | Just load a random jpeg image and tile the background with it without |
|
|
30 | scaling or anything else: |
|
|
31 | |
|
|
32 | load "/path/to/img.jpg" |
|
|
33 | |
|
|
34 | The same, but use mirroring/reflection instead of tiling: |
|
|
35 | |
|
|
36 | mirror load "/path/to/img.jpg" |
|
|
37 | |
|
|
38 | Load an image and scale it to exactly fill the terminal window: |
|
|
39 | |
|
|
40 | scale keep { load "/path/to/img.jpg" } |
|
|
41 | |
|
|
42 | Implement pseudo-transparency by using a suitably-aligned root pixmap |
|
|
43 | as window background: |
|
|
44 | |
|
|
45 | rootalign root |
|
|
46 | |
|
|
47 | Likewise, but keep a blurred copy: |
|
|
48 | |
|
|
49 | rootalign keep { blur 10, root } |
|
|
50 | |
17 | =head1 DESCRIPTION |
51 | =head1 DESCRIPTION |
18 | |
52 | |
19 | This extension manages the terminal background by creating a picture that |
53 | This extension manages the terminal background by creating a picture that |
20 | is behind the text, replacing the normal background colour. |
54 | is behind the text, replacing the normal background colour. |
21 | |
55 | |
… | |
… | |
30 | |
64 | |
31 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
65 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
32 | |
66 | |
33 | Or specified as a X resource: |
67 | Or specified as a X resource: |
34 | |
68 | |
35 | URxvt.background-expr: scale keep { load "/path/to/mybg.png" } |
69 | URxvt.background.expr: scale keep { load "/path/to/mybg.png" } |
36 | |
70 | |
37 | =head1 THEORY OF OPERATION |
71 | =head1 THEORY OF OPERATION |
38 | |
72 | |
39 | At startup, just before the window is mapped for the first time, the |
73 | At startup, just before the window is mapped for the first time, the |
40 | expression is evaluated and must yield an image. The image is then |
74 | expression is evaluated and must yield an image. The image is then |
… | |
… | |
73 | } else { |
107 | } else { |
74 | return load "$HOME/sunday.png"; |
108 | return load "$HOME/sunday.png"; |
75 | } |
109 | } |
76 | } |
110 | } |
77 | |
111 | |
78 | This expression is evaluated once per hour. It will set F<sunday.png> as |
112 | This inner expression is evaluated once per hour (and whenever the |
|
|
113 | terminal window is resized). It sets F<sunday.png> as background on |
79 | background on Sundays, and F<weekday.png> on all other days. |
114 | Sundays, and F<weekday.png> on all other days. |
80 | |
115 | |
81 | Fortunately, we expect that most expressions will be much simpler, with |
116 | Fortunately, we expect that most expressions will be much simpler, with |
82 | little Perl knowledge needed. |
117 | little Perl knowledge needed. |
83 | |
118 | |
84 | Basically, you always start with a function that "generates" an image |
119 | Basically, you always start with a function that "generates" an image |
… | |
… | |
107 | get a percentage): |
142 | get a percentage): |
108 | |
143 | |
109 | scale 2, load "$HOME/mypic.png" |
144 | scale 2, load "$HOME/mypic.png" |
110 | |
145 | |
111 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
146 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
112 | has now two arguments, the C<200> and the C<load> expression, while |
147 | has now two arguments, the C<2> and the C<load> expression, while |
113 | C<load> only has one argument. Arguments are separated from each other by |
148 | C<load> only has one argument. Arguments are separated from each other by |
114 | commas. |
149 | commas. |
115 | |
150 | |
116 | Scale also accepts two arguments, which are then separate factors for both |
151 | Scale also accepts two arguments, which are then separate factors for both |
117 | horizontal and vertical dimensions. For example, this halves the image |
152 | horizontal and vertical dimensions. For example, this halves the image |
118 | width and doubles the image height: |
153 | width and doubles the image height: |
119 | |
154 | |
120 | scale 0.5, 2, load "$HOME/mypic.png" |
155 | scale 0.5, 2, load "$HOME/mypic.png" |
121 | |
156 | |
122 | IF you try out these expressions, you might suffer from sluggishness, |
157 | IF you try out these expressions, you might suffer from some sluggishness, |
123 | because each time the terminal is resized, it again loads the PNG image |
158 | because each time the terminal is resized, it loads the PNG image again |
124 | and scales it. Scaling is usually fast, but loading the image can be quite |
159 | and scales it. Scaling is usually fast (and unavoidable), but loading the |
125 | time consuming. This is where C<keep> comes in handy: |
160 | image can be quite time consuming. This is where C<keep> comes in handy: |
126 | |
161 | |
127 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
162 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
128 | |
163 | |
129 | The C<keep> operator executes all the statements inside the braces only |
164 | The C<keep> operator executes all the statements inside the braces only |
130 | once, or when it thinks the outcome might change. In other cases it |
165 | once, or when it thinks the outcome might change. In other cases it |
… | |
… | |
155 | |
190 | |
156 | This one first takes a snapshot of the screen background image, and then |
191 | This one first takes a snapshot of the screen background image, and then |
157 | moves it to the upper left corner of the screen (as opposed to the upper |
192 | moves it to the upper left corner of the screen (as opposed to the upper |
158 | left corner of the terminal window)- the result is pseudo-transparency: |
193 | left corner of the terminal window)- the result is pseudo-transparency: |
159 | the image seems to be static while the window is moved around. |
194 | the image seems to be static while the window is moved around. |
|
|
195 | |
|
|
196 | =head2 COLOUR SPECIFICATIONS |
|
|
197 | |
|
|
198 | Whenever an operator expects a "colour", then this can be specified in one |
|
|
199 | of two ways: Either as string with an X11 colour specification, such as: |
|
|
200 | |
|
|
201 | "red" # named colour |
|
|
202 | "#f00" # simple rgb |
|
|
203 | "[50]red" # red with 50% alpha |
|
|
204 | "TekHVC:300/50/50" # anything goes |
|
|
205 | |
|
|
206 | OR as an array reference with one, three or four components: |
|
|
207 | |
|
|
208 | [0.5] # 50% gray, 100% alpha |
|
|
209 | [0.5, 0, 0] # dark red, no green or blur, 100% alpha |
|
|
210 | [0.5, 0, 0, 0.7] # same with explicit 70% alpha |
160 | |
211 | |
161 | =head2 CACHING AND SENSITIVITY |
212 | =head2 CACHING AND SENSITIVITY |
162 | |
213 | |
163 | Since some operations (such as C<load> and C<blur>) can take a long time, |
214 | Since some operations (such as C<load> and C<blur>) can take a long time, |
164 | caching results can be very important for a smooth operation. Caching can |
215 | caching results can be very important for a smooth operation. Caching can |
… | |
… | |
183 | When such an event happens, C<keep> will automatically trigger a |
234 | When such an event happens, C<keep> will automatically trigger a |
184 | reevaluation of the whole expression with the new value of the expression. |
235 | reevaluation of the whole expression with the new value of the expression. |
185 | |
236 | |
186 | C<keep> is most useful for expensive operations, such as C<blur>: |
237 | C<keep> is most useful for expensive operations, such as C<blur>: |
187 | |
238 | |
188 | rootalign once { blur 20, root } |
239 | rootalign keep { blur 20, root } |
189 | |
240 | |
190 | This makes a blurred copy of the root background once, and on subsequent |
241 | This makes a blurred copy of the root background once, and on subsequent |
191 | calls, just root-aligns it. Since C<blur> is usually quite slow and |
242 | calls, just root-aligns it. Since C<blur> is usually quite slow and |
192 | C<rootalign> is quite fast, this trades extra memory (for the cached |
243 | C<rootalign> is quite fast, this trades extra memory (for the cached |
193 | blurred pixmap) with speed (blur only needs to be redone when root |
244 | blurred pixmap) with speed (blur only needs to be redone when root |
… | |
… | |
238 | =cut |
289 | =cut |
239 | |
290 | |
240 | our %_IMG_CACHE; |
291 | our %_IMG_CACHE; |
241 | our $HOME; |
292 | our $HOME; |
242 | our ($self, $frame); |
293 | our ($self, $frame); |
243 | our ($x, $y, $w, $h); |
294 | our ($x, $y, $w, $h, $focus); |
244 | |
295 | |
245 | # enforce at least this interval between updates |
296 | # enforce at least this interval between updates |
246 | our $MIN_INTERVAL = 6/59.951; |
297 | our $MIN_INTERVAL = 6/59.951; |
247 | |
298 | |
248 | { |
299 | { |
… | |
… | |
267 | |
318 | |
268 | Loads the image at the given C<$path>. The image is set to plane tiling |
319 | Loads the image at the given C<$path>. The image is set to plane tiling |
269 | mode. |
320 | mode. |
270 | |
321 | |
271 | If the image is already in memory (e.g. because another terminal instance |
322 | If the image is already in memory (e.g. because another terminal instance |
272 | uses it), then the in-memory copy us returned instead. |
323 | uses it), then the in-memory copy is returned instead. |
273 | |
324 | |
274 | =item load_uc $path |
325 | =item load_uc $path |
275 | |
326 | |
276 | Load uncached - same as load, but does not cache the image, which means it |
327 | Load uncached - same as load, but does not cache the image, which means it |
277 | is I<always> loaded from the filesystem again. |
328 | is I<always> loaded from the filesystem again, even if another copy of it |
|
|
329 | is in memory at the time. |
278 | |
330 | |
279 | =cut |
331 | =cut |
280 | |
332 | |
281 | sub load_uc($) { |
333 | sub load_uc($) { |
282 | $self->new_img_from_file ($path) |
334 | $self->new_img_from_file ($_[0]) |
283 | } |
335 | } |
284 | |
336 | |
285 | sub load($) { |
337 | sub load($) { |
286 | my ($path) = @_; |
338 | my ($path) = @_; |
287 | |
339 | |
… | |
… | |
380 | for @_; |
432 | for @_; |
381 | |
433 | |
382 | $base |
434 | $base |
383 | } |
435 | } |
384 | |
436 | |
|
|
437 | =back |
|
|
438 | |
385 | =head2 TILING MODES |
439 | =head2 TILING MODES |
386 | |
440 | |
387 | The following operators modify the tiling mode of an image, that is, the |
441 | The following operators modify the tiling mode of an image, that is, the |
388 | way that pixels outside the image area are painted when the image is used. |
442 | way that pixels outside the image area are painted when the image is used. |
389 | |
443 | |
… | |
… | |
480 | |
534 | |
481 | Return the X and Y coordinates of the terminal window (the terminal |
535 | Return the X and Y coordinates of the terminal window (the terminal |
482 | window is the full window by default, and the character area only when in |
536 | window is the full window by default, and the character area only when in |
483 | border-respect mode). |
537 | border-respect mode). |
484 | |
538 | |
485 | Using these functions make your expression sensitive to window moves. |
539 | Using these functions makes your expression sensitive to window moves. |
486 | |
540 | |
487 | These functions are mainly useful to align images to the root window. |
541 | These functions are mainly useful to align images to the root window. |
488 | |
542 | |
489 | Example: load an image and align it so it looks as if anchored to the |
543 | Example: load an image and align it so it looks as if anchored to the |
490 | background (that's exactly what C<rootalign> does btw.): |
544 | background (that's exactly what C<rootalign> does btw.): |
491 | |
545 | |
492 | move -TX, -TY, keep { load "mybg.png" } |
546 | move -TX, -TY, keep { load "mybg.png" } |
493 | |
547 | |
494 | =item TW |
548 | =item TW |
|
|
549 | |
|
|
550 | =item TH |
495 | |
551 | |
496 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
552 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
497 | terminal window is the full window by default, and the character area only |
553 | terminal window is the full window by default, and the character area only |
498 | when in border-respect mode). |
554 | when in border-respect mode). |
499 | |
555 | |
500 | Using these functions make your expression sensitive to window resizes. |
556 | Using these functions makes your expression sensitive to window resizes. |
501 | |
557 | |
502 | These functions are mainly useful to scale images, or to clip images to |
558 | These functions are mainly useful to scale images, or to clip images to |
503 | the window size to conserve memory. |
559 | the window size to conserve memory. |
504 | |
560 | |
505 | Example: take the screen background, clip it to the window size, blur it a |
561 | Example: take the screen background, clip it to the window size, blur it a |
506 | bit, align it to the window position and use it as background. |
562 | bit, align it to the window position and use it as background. |
507 | |
563 | |
508 | clip move -TX, -TY, keep { blur 5, root } |
564 | clip move -TX, -TY, keep { blur 5, root } |
509 | |
565 | |
510 | =cut |
566 | =item FOCUS |
511 | |
567 | |
|
|
568 | Returns a boolean indicating whether the terminal window has keyboard |
|
|
569 | focus, in which case it returns true. |
|
|
570 | |
|
|
571 | Using this function makes your expression sensitive to focus changes. |
|
|
572 | |
|
|
573 | A common use case is to fade the background image when the terminal loses |
|
|
574 | focus, often together with the C<-fade> command line option. In fact, |
|
|
575 | there is a special function for just that use case: C<focus_fade>. |
|
|
576 | |
|
|
577 | Example: use two entirely different background images, depending on |
|
|
578 | whether the window has focus. |
|
|
579 | |
|
|
580 | FOCUS ? keep { load "has_focus.jpg" } : keep { load "no_focus.jpg" } |
|
|
581 | |
|
|
582 | =cut |
|
|
583 | |
512 | sub TX() { $frame->[FR_AGAIN]{position} = 1; $x } |
584 | sub TX () { $frame->[FR_AGAIN]{position} = 1; $x } |
513 | sub TY() { $frame->[FR_AGAIN]{position} = 1; $y } |
585 | sub TY () { $frame->[FR_AGAIN]{position} = 1; $y } |
514 | sub TW() { $frame->[FR_AGAIN]{size} = 1; $w } |
586 | sub TW () { $frame->[FR_AGAIN]{size} = 1; $w } |
515 | sub TH() { $frame->[FR_AGAIN]{size} = 1; $h } |
587 | sub TH () { $frame->[FR_AGAIN]{size} = 1; $h } |
|
|
588 | sub FOCUS() { $frame->[FR_AGAIN]{focus} = 1; $focus } |
516 | |
589 | |
517 | =item now |
590 | =item now |
518 | |
591 | |
519 | Returns the current time as (fractional) seconds since the epoch. |
592 | Returns the current time as (fractional) seconds since the epoch. |
520 | |
593 | |
… | |
… | |
567 | Clips an image to the given rectangle. If the rectangle is outside the |
640 | Clips an image to the given rectangle. If the rectangle is outside the |
568 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
641 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
569 | larger than the image, then the tiling mode defines how the extra pixels |
642 | larger than the image, then the tiling mode defines how the extra pixels |
570 | will be filled. |
643 | will be filled. |
571 | |
644 | |
572 | If C<$x> an C<$y> are missing, then C<0> is assumed for both. |
645 | If C<$x> and C<$y> are missing, then C<0> is assumed for both. |
573 | |
646 | |
574 | If C<$width> and C<$height> are missing, then the window size will be |
647 | If C<$width> and C<$height> are missing, then the window size will be |
575 | assumed. |
648 | assumed. |
576 | |
649 | |
577 | Example: load an image, blur it, and clip it to the window size to save |
650 | Example: load an image, blur it, and clip it to the window size to save |
… | |
… | |
595 | =item scale $width_factor, $height_factor, $img |
668 | =item scale $width_factor, $height_factor, $img |
596 | |
669 | |
597 | Scales the image by the given factors in horizontal |
670 | Scales the image by the given factors in horizontal |
598 | (C<$width>) and vertical (C<$height>) direction. |
671 | (C<$width>) and vertical (C<$height>) direction. |
599 | |
672 | |
600 | If only one factor is give, it is used for both directions. |
673 | If only one factor is given, it is used for both directions. |
601 | |
674 | |
602 | If no factors are given, scales the image to the window size without |
675 | If no factors are given, scales the image to the window size without |
603 | keeping aspect. |
676 | keeping aspect. |
604 | |
677 | |
605 | =item resize $width, $height, $img |
678 | =item resize $width, $height, $img |
… | |
… | |
730 | =item rotate $center_x, $center_y, $degrees, $img |
803 | =item rotate $center_x, $center_y, $degrees, $img |
731 | |
804 | |
732 | Rotates the image clockwise by C<$degrees> degrees, around the point at |
805 | Rotates the image clockwise by C<$degrees> degrees, around the point at |
733 | C<$center_x> and C<$center_y> (specified as factor of image width/height). |
806 | C<$center_x> and C<$center_y> (specified as factor of image width/height). |
734 | |
807 | |
735 | Example: rotate the image by 90 degrees around it's center. |
808 | Example: rotate the image by 90 degrees around its center. |
736 | |
809 | |
737 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
810 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
738 | |
811 | |
739 | =cut |
812 | =cut |
740 | |
813 | |
… | |
… | |
753 | |
826 | |
754 | The following operators change the pixels of the image. |
827 | The following operators change the pixels of the image. |
755 | |
828 | |
756 | =over 4 |
829 | =over 4 |
757 | |
830 | |
|
|
831 | =item tint $color, $img |
|
|
832 | |
|
|
833 | Tints the image in the given colour. |
|
|
834 | |
|
|
835 | Example: tint the image red. |
|
|
836 | |
|
|
837 | tint "red", load "rgb.png" |
|
|
838 | |
|
|
839 | Example: the same, but specify the colour by component. |
|
|
840 | |
|
|
841 | tint [1, 0, 0], load "rgb.png" |
|
|
842 | |
|
|
843 | =cut |
|
|
844 | |
|
|
845 | sub tint($$) { |
|
|
846 | $_[1]->tint ($_[0]) |
|
|
847 | } |
|
|
848 | |
|
|
849 | =item shade $factor, $img |
|
|
850 | |
|
|
851 | Shade the image by the given factor. |
|
|
852 | |
|
|
853 | =cut |
|
|
854 | |
|
|
855 | sub shade($$) { |
|
|
856 | $_[1]->shade ($_[0]) |
|
|
857 | } |
|
|
858 | |
758 | =item contrast $factor, $img |
859 | =item contrast $factor, $img |
759 | |
860 | |
760 | =item contrast $r, $g, $b, $img |
861 | =item contrast $r, $g, $b, $img |
761 | |
862 | |
762 | =item contrast $r, $g, $b, $a, $img |
863 | =item contrast $r, $g, $b, $a, $img |
… | |
… | |
791 | latter in a white picture. |
892 | latter in a white picture. |
792 | |
893 | |
793 | Due to idiosyncrasies in the underlying XRender extension, biases less |
894 | Due to idiosyncrasies in the underlying XRender extension, biases less |
794 | than zero can be I<very> slow. |
895 | than zero can be I<very> slow. |
795 | |
896 | |
|
|
897 | You can also try the experimental(!) C<muladd> operator. |
|
|
898 | |
796 | =cut |
899 | =cut |
797 | |
900 | |
798 | sub contrast($$;$$;$) { |
901 | sub contrast($$;$$;$) { |
799 | my $img = pop; |
902 | my $img = pop; |
800 | my ($r, $g, $b, $a) = @_; |
903 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
815 | $a = 1 if @_ < 4; |
918 | $a = 1 if @_ < 4; |
816 | |
919 | |
817 | $img = $img->clone; |
920 | $img = $img->clone; |
818 | $img->brightness ($r, $g, $b, $a); |
921 | $img->brightness ($r, $g, $b, $a); |
819 | $img |
922 | $img |
|
|
923 | } |
|
|
924 | |
|
|
925 | =item muladd $mul, $add, $img # EXPERIMENTAL |
|
|
926 | |
|
|
927 | First multiplies the pixels by C<$mul>, then adds C<$add>. This can be used |
|
|
928 | to implement brightness and contrast at the same time, with a wider value |
|
|
929 | range than contrast and brightness operators. |
|
|
930 | |
|
|
931 | Due to numerous bugs in XRender implementations, it can also introduce a |
|
|
932 | number of visual artifacts. |
|
|
933 | |
|
|
934 | Example: increase contrast by a factor of C<$c> without changing image |
|
|
935 | brightness too much. |
|
|
936 | |
|
|
937 | muladd $c, (1 - $c) * 0.5, $img |
|
|
938 | |
|
|
939 | =cut |
|
|
940 | |
|
|
941 | sub muladd($$$) { |
|
|
942 | $_[2]->muladd ($_[0], $_[1]) |
820 | } |
943 | } |
821 | |
944 | |
822 | =item blur $radius, $img |
945 | =item blur $radius, $img |
823 | |
946 | |
824 | =item blur $radius_horz, $radius_vert, $img |
947 | =item blur $radius_horz, $radius_vert, $img |
… | |
… | |
836 | sub blur($$;$) { |
959 | sub blur($$;$) { |
837 | my $img = pop; |
960 | my $img = pop; |
838 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
961 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
839 | } |
962 | } |
840 | |
963 | |
|
|
964 | =item focus_fade $img |
|
|
965 | |
|
|
966 | =item focus_fade $factor, $img |
|
|
967 | |
|
|
968 | =item focus_fade $factor, $color, $img |
|
|
969 | |
|
|
970 | Fades the image by the given factor (and colour) when focus is lost (the |
|
|
971 | same as the C<-fade>/C<-fadecolor> command line options, which also supply |
|
|
972 | the default values for C<factor> and C<$color>. Unlike with C<-fade>, the |
|
|
973 | C<$factor> is a real value, not a percentage value (that is, 0..1, not |
|
|
974 | 0..100). |
|
|
975 | |
|
|
976 | Example: do the right thing when focus fading is requested. |
|
|
977 | |
|
|
978 | focus_fade load "mybg.jpg"; |
|
|
979 | |
|
|
980 | =cut |
|
|
981 | |
|
|
982 | sub focus_fade($;$$) { |
|
|
983 | my $img = pop; |
|
|
984 | |
|
|
985 | return $img |
|
|
986 | if FOCUS; |
|
|
987 | |
|
|
988 | my $fade = @_ >= 1 ? $_[0] : defined $self->resource ("fade") ? $self->resource ("fade") * 0.01 : 0; |
|
|
989 | my $color = @_ >= 2 ? $_[1] : $self->resource ("color+" . urxvt::Color_fade); |
|
|
990 | |
|
|
991 | $img = $img->tint ($color) if $color ne "rgb:00/00/00"; |
|
|
992 | $img = $img->muladd (1 - $fade, 0) if $fade; |
|
|
993 | |
|
|
994 | $img |
|
|
995 | } |
|
|
996 | |
841 | =back |
997 | =back |
842 | |
998 | |
843 | =head2 OTHER STUFF |
999 | =head2 OTHER STUFF |
844 | |
1000 | |
845 | Anything that didn't fit any of the other categories, even after applying |
1001 | Anything that didn't fit any of the other categories, even after applying |
… | |
… | |
847 | |
1003 | |
848 | =over 4 |
1004 | =over 4 |
849 | |
1005 | |
850 | =item keep { ... } |
1006 | =item keep { ... } |
851 | |
1007 | |
852 | #TODO# |
|
|
853 | |
|
|
854 | This operator takes a code block as argument, that is, one or more |
1008 | This operator takes a code block as argument, that is, one or more |
855 | statements enclosed by braces. |
1009 | statements enclosed by braces. |
856 | |
1010 | |
857 | The trick is that this code block is only evaluated once - future calls |
1011 | The trick is that this code block is only evaluated when the outcome |
858 | will simply return the original image (yes, it should only be used with |
1012 | changes - on other calls the C<keep> simply returns the image it computed |
859 | images). |
1013 | previously (yes, it should only be used with images). Or in other words, |
|
|
1014 | C<keep> I<caches> the result of the code block so it doesn't need to be |
|
|
1015 | computed again. |
860 | |
1016 | |
861 | This can be extremely useful to avoid redoing the same slow operations |
1017 | This can be extremely useful to avoid redoing slow operations - for |
862 | again and again- for example, if your background expression takes the root |
1018 | example, if your background expression takes the root background, blurs it |
863 | background, blurs it and then root-aligns it it would have to blur the |
1019 | and then root-aligns it it would have to blur the root background on every |
864 | root background on every window move or resize. |
1020 | window move or resize. |
|
|
1021 | |
|
|
1022 | Another example is C<load>, which can be quite slow. |
865 | |
1023 | |
866 | In fact, urxvt itself encloses the whole expression in some kind of |
1024 | In fact, urxvt itself encloses the whole expression in some kind of |
867 | C<once> block so it only is reevaluated as required. |
1025 | C<keep> block so it only is reevaluated as required. |
868 | |
1026 | |
869 | Putting the blur into a C<once> block will make sure the blur is only done |
1027 | Putting the blur into a C<keep> block will make sure the blur is only done |
870 | once: |
1028 | once, while the C<rootalign> is still done each time the window moves. |
871 | |
1029 | |
872 | rootlign keep { blur 10, root } |
1030 | rootalign keep { blur 10, root } |
873 | |
1031 | |
874 | This leaves the question of how to force reevaluation of the block, |
1032 | This leaves the question of how to force reevaluation of the block, |
875 | in case the root background changes: If expression inside the block |
1033 | in case the root background changes: If expression inside the block |
876 | is sensitive to some event (root background changes, window geometry |
1034 | is sensitive to some event (root background changes, window geometry |
877 | changes), then it will be reevaluated automatically as needed. |
1035 | changes), then it will be reevaluated automatically as needed. |
878 | |
1036 | |
879 | =item once_again |
1037 | =back |
880 | |
1038 | |
881 | Resets all C<once> block as if they had never been called, i.e. on the |
1039 | =head1 OLD BACKGROUND IMAGE SETTINGS |
882 | next call they will be reevaluated again. |
|
|
883 | |
1040 | |
884 | =cut |
1041 | This extension also provides support for the old options/resources and |
|
|
1042 | OSC sequences for setting a background image. These settings are |
|
|
1043 | B<deprecated> and will be removed in future versions. |
885 | |
1044 | |
|
|
1045 | =head2 OPTIONS AND RESOURCES |
|
|
1046 | |
|
|
1047 | =over 4 |
|
|
1048 | |
|
|
1049 | =item B<-pixmap> I<file[;oplist]> |
|
|
1050 | |
|
|
1051 | =item B<backgroundPixmap:> I<file[;oplist]> |
|
|
1052 | |
|
|
1053 | Use the specified image file as the window's background and also |
|
|
1054 | optionally specify a colon separated list of operations to modify it. |
|
|
1055 | Note that you may need to quote the C<;> character when using the |
|
|
1056 | command line option, as C<;> is usually a metacharacter in shells. |
|
|
1057 | Supported operations are: |
|
|
1058 | |
|
|
1059 | =over 4 |
|
|
1060 | |
|
|
1061 | =item B<WxH+X+Y> |
|
|
1062 | |
|
|
1063 | sets scale and position. B<"W" / "H"> specify the horizontal/vertical |
|
|
1064 | scale (percent), and B<"X" / "Y"> locate the image centre (percent). A |
|
|
1065 | scale of 0 disables scaling. |
|
|
1066 | |
|
|
1067 | =item B<op=tile> |
|
|
1068 | |
|
|
1069 | enables tiling |
|
|
1070 | |
|
|
1071 | =item B<op=keep-aspect> |
|
|
1072 | |
|
|
1073 | maintain the image aspect ratio when scaling |
|
|
1074 | |
|
|
1075 | =item B<op=root-align> |
|
|
1076 | |
|
|
1077 | use the position of the terminal window relative to the root window as |
|
|
1078 | the image offset, simulating a root window background |
|
|
1079 | |
|
|
1080 | =back |
|
|
1081 | |
|
|
1082 | The default scale and position setting is C<100x100+50+50>. |
|
|
1083 | Alternatively, a predefined set of templates can be used to achieve |
|
|
1084 | the most common setups: |
|
|
1085 | |
|
|
1086 | =over 4 |
|
|
1087 | |
|
|
1088 | =item B<style=tiled> |
|
|
1089 | |
|
|
1090 | the image is tiled with no scaling. Equivalent to 0x0+0+0:op=tile |
|
|
1091 | |
|
|
1092 | =item B<style=aspect-stretched> |
|
|
1093 | |
|
|
1094 | the image is scaled to fill the whole window maintaining the aspect |
|
|
1095 | ratio and centered. Equivalent to 100x100+50+50:op=keep-aspect |
|
|
1096 | |
|
|
1097 | =item B<style=stretched> |
|
|
1098 | |
|
|
1099 | the image is scaled to fill the whole window. Equivalent to 100x100 |
|
|
1100 | |
|
|
1101 | =item B<style=centered> |
|
|
1102 | |
|
|
1103 | the image is centered with no scaling. Equivalent to 0x0+50+50 |
|
|
1104 | |
|
|
1105 | =item B<style=root-tiled> |
|
|
1106 | |
|
|
1107 | the image is tiled with no scaling and using 'root' positioning. |
|
|
1108 | Equivalent to 0x0:op=tile:op=root-align |
|
|
1109 | |
|
|
1110 | =back |
|
|
1111 | |
|
|
1112 | If multiple templates are specified the last one wins. Note that a |
|
|
1113 | template overrides all the scale, position and operations settings. |
|
|
1114 | |
|
|
1115 | If used in conjunction with pseudo-transparency, the specified image |
|
|
1116 | will be blended over the transparent background using alpha-blending. |
|
|
1117 | |
|
|
1118 | =item B<-tr>|B<+tr> |
|
|
1119 | |
|
|
1120 | =item B<transparent:> I<boolean> |
|
|
1121 | |
|
|
1122 | Turn on/off pseudo-transparency by using the root pixmap as background. |
|
|
1123 | |
|
|
1124 | =item B<-tint> I<colour> |
|
|
1125 | |
|
|
1126 | =item B<tintColor:> I<colour> |
|
|
1127 | |
|
|
1128 | Tint the transparent background with the given colour. Note that a |
|
|
1129 | black tint yields a completely black image while a white tint yields |
|
|
1130 | the image unchanged. |
|
|
1131 | |
|
|
1132 | =item B<-sh> I<number> |
|
|
1133 | |
|
|
1134 | =item B<shading:> I<number> |
|
|
1135 | |
|
|
1136 | Darken (0 .. 99) or lighten (101 .. 200) the transparent background. |
|
|
1137 | A value of 100 means no shading. |
|
|
1138 | |
|
|
1139 | =item B<-blr> I<HxV> |
|
|
1140 | |
|
|
1141 | =item B<blurRadius:> I<HxV> |
|
|
1142 | |
|
|
1143 | Apply gaussian blur with the specified radius to the transparent |
|
|
1144 | background. If a single number is specified, the vertical and |
|
|
1145 | horizontal radii are considered to be the same. Setting one of the |
|
|
1146 | radii to 1 and the other to a large number creates interesting effects |
|
|
1147 | on some backgrounds. The maximum radius value is 128. An horizontal or |
|
|
1148 | vertical radius of 0 disables blurring. |
|
|
1149 | |
|
|
1150 | =back |
|
|
1151 | |
|
|
1152 | =head2 OSC sequences |
|
|
1153 | |
|
|
1154 | =over 4 |
|
|
1155 | |
|
|
1156 | =item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>. |
|
|
1157 | |
|
|
1158 | =item B<< C<ESC ] 20 ; Pt ST> >> Change/Query background image |
|
|
1159 | parameters: the value of B<< C<Pt> >> can be one of the following |
|
|
1160 | commands: |
|
|
1161 | |
|
|
1162 | =over 4 |
|
|
1163 | |
|
|
1164 | =item B<< C<?> >> |
|
|
1165 | |
|
|
1166 | display scale and position in the title |
|
|
1167 | |
|
|
1168 | =item B<< C<;WxH+X+Y> >> |
|
|
1169 | |
|
|
1170 | change scale and/or position |
|
|
1171 | |
|
|
1172 | =item B<< C<FILE;WxH+X+Y> >> |
|
|
1173 | |
|
|
1174 | change background image |
|
|
1175 | |
|
|
1176 | =back |
|
|
1177 | |
|
|
1178 | =cut |
|
|
1179 | |
886 | sub once(&) { |
1180 | sub keep(&) { |
887 | my $id = $_[0]+0; |
1181 | my $id = $_[0]+0; |
888 | |
1182 | |
889 | local $frame = $self->{frame_cache}{$id} ||= [$frame]; |
1183 | local $frame = $self->{frame_cache}{$id} ||= [$frame]; |
890 | |
1184 | |
891 | unless ($frame->[FR_CACHE]) { |
1185 | unless ($frame->[FR_CACHE]) { |
… | |
… | |
909 | wantarray |
1203 | wantarray |
910 | ? @{ $frame->[FR_CACHE] } |
1204 | ? @{ $frame->[FR_CACHE] } |
911 | : $frame->[FR_CACHE][0] |
1205 | : $frame->[FR_CACHE][0] |
912 | } |
1206 | } |
913 | |
1207 | |
914 | sub once_again() { |
1208 | # sub keep_clear() { |
915 | delete $self->{frame_cache}; |
1209 | # delete $self->{frame_cache}; |
916 | } |
1210 | # } |
917 | |
1211 | |
918 | =back |
1212 | =back |
919 | |
1213 | |
920 | =cut |
1214 | =cut |
921 | |
1215 | |
… | |
… | |
934 | |
1228 | |
935 | # compiles a parsed expression |
1229 | # compiles a parsed expression |
936 | sub set_expr { |
1230 | sub set_expr { |
937 | my ($self, $expr) = @_; |
1231 | my ($self, $expr) = @_; |
938 | |
1232 | |
939 | $self->{root} = []; |
1233 | $self->{root} = []; # the outermost frame |
940 | $self->{expr} = $expr; |
1234 | $self->{expr} = $expr; |
941 | $self->recalculate; |
1235 | $self->recalculate; |
942 | } |
1236 | } |
943 | |
1237 | |
944 | # takes a hash of sensitivity indicators and installs watchers |
1238 | # takes a hash of sensitivity indicators and installs watchers |
… | |
… | |
985 | if ($again->{rootpmap}) { |
1279 | if ($again->{rootpmap}) { |
986 | $state->{rootpmap} = $self->on (rootpmap_change => $cb); |
1280 | $state->{rootpmap} = $self->on (rootpmap_change => $cb); |
987 | } else { |
1281 | } else { |
988 | delete $state->{rootpmap}; |
1282 | delete $state->{rootpmap}; |
989 | } |
1283 | } |
|
|
1284 | |
|
|
1285 | if ($again->{focus}) { |
|
|
1286 | $state->{focus} = $self->on (focus_in => $cb, focus_out => $cb); |
|
|
1287 | } else { |
|
|
1288 | delete $state->{focus}; |
|
|
1289 | } |
990 | } |
1290 | } |
991 | |
1291 | |
992 | # evaluate the current bg expression |
1292 | # evaluate the current bg expression |
993 | sub recalculate { |
1293 | sub recalculate { |
994 | my ($arg_self) = @_; |
1294 | my ($arg_self) = @_; |
… | |
… | |
1006 | |
1306 | |
1007 | # set environment to evaluate user expression |
1307 | # set environment to evaluate user expression |
1008 | |
1308 | |
1009 | local $self = $arg_self; |
1309 | local $self = $arg_self; |
1010 | local $HOME = $ENV{HOME}; |
1310 | local $HOME = $ENV{HOME}; |
1011 | local $frame = []; |
1311 | local $frame = $self->{root}; |
1012 | |
1312 | |
1013 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
1313 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
|
|
1314 | $focus = $self->focus; |
1014 | |
1315 | |
1015 | # evaluate user expression |
1316 | # evaluate user expression |
1016 | |
1317 | |
1017 | my @img = eval { $self->{expr}->() }; |
1318 | my @img = eval { $self->{expr}->() }; |
1018 | die $@ if $@; |
1319 | die $@ if $@; |
… | |
… | |
1036 | # } |
1337 | # } |
1037 | |
1338 | |
1038 | # set background pixmap |
1339 | # set background pixmap |
1039 | |
1340 | |
1040 | $self->set_background ($img, $self->{border}); |
1341 | $self->set_background ($img, $self->{border}); |
1041 | $self->scr_recolour (0); |
1342 | $self->scr_recolor (0); |
1042 | $self->want_refresh; |
1343 | $self->want_refresh; |
1043 | } |
1344 | } |
1044 | |
1345 | |
|
|
1346 | sub old_bg_opts { |
|
|
1347 | my ($self, $arg) = @_; |
|
|
1348 | |
|
|
1349 | $arg or return; |
|
|
1350 | |
|
|
1351 | my @str = split /;/, $arg; |
|
|
1352 | |
|
|
1353 | return unless $str[0] or $self->{bg_opts}->{path}; |
|
|
1354 | |
|
|
1355 | my $bg_opts = $self->{bg_opts}; |
|
|
1356 | |
|
|
1357 | if ($str[0]) { |
|
|
1358 | $bg_opts->{tile} = 0; |
|
|
1359 | $bg_opts->{keep_aspect} = 0; |
|
|
1360 | $bg_opts->{root_align} = 0; |
|
|
1361 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
|
|
1362 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1363 | $bg_opts->{path} = unpack "H*", $str[0]; |
|
|
1364 | } |
|
|
1365 | |
|
|
1366 | my @oplist = split /:/, $str[1]; |
|
|
1367 | |
|
|
1368 | for (@oplist) { |
|
|
1369 | if (/style=tiled/i) { |
|
|
1370 | $bg_opts->{tile} = 1; |
|
|
1371 | $bg_opts->{keep_aspect} = 0; |
|
|
1372 | $bg_opts->{root_align} = 0; |
|
|
1373 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0; |
|
|
1374 | $bg_opts->{h_align} = $bg_opts->{v_align} = 0; |
|
|
1375 | } elsif (/style=aspect-stretched/i) { |
|
|
1376 | $bg_opts->{tile} = 0; |
|
|
1377 | $bg_opts->{keep_aspect} = 1; |
|
|
1378 | $bg_opts->{root_align} = 0; |
|
|
1379 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
|
|
1380 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1381 | } elsif (/style=stretched/i) { |
|
|
1382 | $bg_opts->{tile} = 0; |
|
|
1383 | $bg_opts->{keep_aspect} = 0; |
|
|
1384 | $bg_opts->{root_align} = 0; |
|
|
1385 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
|
|
1386 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1387 | } elsif (/style=centered/i) { |
|
|
1388 | $bg_opts->{tile} = 0; |
|
|
1389 | $bg_opts->{keep_aspect} = 0; |
|
|
1390 | $bg_opts->{root_align} = 0; |
|
|
1391 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0; |
|
|
1392 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1393 | } elsif (/style=root-tiled/i) { |
|
|
1394 | $bg_opts->{tile} = 1; |
|
|
1395 | $bg_opts->{keep_aspect} = 0; |
|
|
1396 | $bg_opts->{root_align} = 1; |
|
|
1397 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0; |
|
|
1398 | $bg_opts->{h_align} = $bg_opts->{v_align} = 0; |
|
|
1399 | } elsif (/op=tile/i) { |
|
|
1400 | $bg_opts->{tile} = 1; |
|
|
1401 | } elsif (/op=keep-aspect/i) { |
|
|
1402 | $bg_opts->{keep_aspect} = 1; |
|
|
1403 | } elsif (/op=root-align/i) { |
|
|
1404 | $bg_opts->{root_align} = 1; |
|
|
1405 | } elsif (/^ =? ([0-9]+)? (?:[xX] ([0-9]+))? ([+-][0-9]+)? ([+-][0-9]+)? $/x) { |
|
|
1406 | my ($w, $h, $x, $y) = ($1, $2, $3, $4); |
|
|
1407 | |
|
|
1408 | if ($str[0]) { |
|
|
1409 | $w = $h unless defined $w; |
|
|
1410 | $h = $w unless defined $h; |
|
|
1411 | $y = $x unless defined $y; |
|
|
1412 | } |
|
|
1413 | |
|
|
1414 | $bg_opts->{h_scale} = $w if defined $w; |
|
|
1415 | $bg_opts->{v_scale} = $h if defined $h; |
|
|
1416 | $bg_opts->{h_align} = $x if defined $x; |
|
|
1417 | $bg_opts->{v_align} = $y if defined $y; |
|
|
1418 | } |
|
|
1419 | } |
|
|
1420 | } |
|
|
1421 | |
|
|
1422 | sub old_bg_expr { |
|
|
1423 | my ($self) = @_; |
|
|
1424 | |
|
|
1425 | my $expr; |
|
|
1426 | |
|
|
1427 | my $bg_opts = $self->{bg_opts}; |
|
|
1428 | |
|
|
1429 | if ($bg_opts->{root} =~ /^\s*(?:true|yes|on|1)\s*$/i) { |
|
|
1430 | $expr .= "tile ("; |
|
|
1431 | |
|
|
1432 | my $shade = $bg_opts->{shade}; |
|
|
1433 | |
|
|
1434 | if ($shade) { |
|
|
1435 | $shade = List::Util::min $shade, 200; |
|
|
1436 | $shade = List::Util::max $shade, -100; |
|
|
1437 | $shade = 200 - (100 + $shade) if $shade < 0; |
|
|
1438 | |
|
|
1439 | $shade = $shade * 0.01 - 1; |
|
|
1440 | $expr .= "shade $shade, "; |
|
|
1441 | } |
|
|
1442 | |
|
|
1443 | my $tint = $bg_opts->{tint}; |
|
|
1444 | |
|
|
1445 | if ($tint) { |
|
|
1446 | $expr .= "tint $tint, "; |
|
|
1447 | } |
|
|
1448 | |
|
|
1449 | my $blur = $bg_opts->{blur}; |
|
|
1450 | |
|
|
1451 | if ($blur and $blur =~ /^ =? ([0-9]+)? (?:[xX] ([0-9]+))? $/x) { |
|
|
1452 | my $hr = defined $1 ? $1 : 1; |
|
|
1453 | my $vr = defined $2 ? $2 : $hr; |
|
|
1454 | |
|
|
1455 | if ($hr != 0 and $vr != 0) { |
|
|
1456 | $expr .= "blur $hr, $vr, "; |
|
|
1457 | } |
|
|
1458 | } |
|
|
1459 | |
|
|
1460 | $expr .= "rootalign root)"; |
|
|
1461 | } |
|
|
1462 | |
|
|
1463 | if ($bg_opts->{path}) { |
|
|
1464 | my $file_expr; |
|
|
1465 | my $h_scale = $bg_opts->{h_scale} * 0.01; |
|
|
1466 | my $v_scale = $bg_opts->{v_scale} * 0.01; |
|
|
1467 | my $h_align = $bg_opts->{h_align} * 0.01; |
|
|
1468 | my $v_align = $bg_opts->{v_align} * 0.01; |
|
|
1469 | |
|
|
1470 | if (!$bg_opts->{tile}) { |
|
|
1471 | $file_expr .= "pad ("; |
|
|
1472 | } else { |
|
|
1473 | $file_expr .= "tile ("; |
|
|
1474 | } |
|
|
1475 | |
|
|
1476 | if ($bg_opts->{root_align}) { |
|
|
1477 | $file_expr .= "rootalign "; |
|
|
1478 | } else { |
|
|
1479 | $file_expr .= "align $h_align, $v_align, "; |
|
|
1480 | } |
|
|
1481 | |
|
|
1482 | if ($h_scale != 0 and $v_scale != 0) { |
|
|
1483 | my $op = $bg_opts->{keep_aspect} ? "fit" : "resize"; |
|
|
1484 | $file_expr .= "$op TW * $h_scale, TH * $v_scale, "; |
|
|
1485 | } |
|
|
1486 | |
|
|
1487 | $file_expr .= "keep { load pack \"H*\", \"$bg_opts->{path}\" })"; |
|
|
1488 | |
|
|
1489 | if ($expr) { |
|
|
1490 | $expr .= ", tint (\"[50]white\", $file_expr)"; |
|
|
1491 | } else { |
|
|
1492 | $expr = $file_expr; |
|
|
1493 | } |
|
|
1494 | } |
|
|
1495 | |
|
|
1496 | $expr |
|
|
1497 | } |
|
|
1498 | |
|
|
1499 | sub on_osc_seq { |
|
|
1500 | my ($self, $op, $arg) = @_; |
|
|
1501 | |
|
|
1502 | $self->{bg_opts} or return; |
|
|
1503 | |
|
|
1504 | $op =~ /^(20|705)$/ or return; |
|
|
1505 | |
|
|
1506 | if ($op eq "20") { |
|
|
1507 | if ($arg eq "?") { |
|
|
1508 | my $h_scale = $self->{bg_opts}->{h_scale}; |
|
|
1509 | my $v_scale = $self->{bg_opts}->{v_scale}; |
|
|
1510 | my $h_align = $self->{bg_opts}->{h_align}; |
|
|
1511 | my $v_align = $self->{bg_opts}->{v_align}; |
|
|
1512 | $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007"); |
|
|
1513 | } else { |
|
|
1514 | $self->old_bg_opts ($arg); |
|
|
1515 | my $expr = $self->old_bg_expr; |
|
|
1516 | $self->set_expr (parse_expr $expr) if $expr; |
|
|
1517 | } |
|
|
1518 | } elsif ($op eq "705") { |
|
|
1519 | $self->{bg_opts}->{tint} = $arg; |
|
|
1520 | my $expr = $self->old_bg_expr; |
|
|
1521 | $self->set_expr (parse_expr $expr) if $expr; |
|
|
1522 | } |
|
|
1523 | |
|
|
1524 | 1 |
|
|
1525 | } |
|
|
1526 | |
|
|
1527 | sub find_resource { |
|
|
1528 | my ($self, $res, $opt) = @_; |
|
|
1529 | |
|
|
1530 | my $v = $self->x_resource ($opt); |
|
|
1531 | $v = $self->x_resource ($res) unless defined $v; |
|
|
1532 | |
|
|
1533 | $v |
|
|
1534 | } |
|
|
1535 | |
1045 | sub on_start { |
1536 | sub on_start { |
1046 | my ($self) = @_; |
1537 | my ($self) = @_; |
1047 | |
1538 | |
1048 | my $expr = $self->x_resource ("%.expr") |
1539 | my $expr = $self->x_resource ("%.expr"); |
|
|
1540 | |
|
|
1541 | if (!$expr) { |
|
|
1542 | $self->{bg_opts} = { h_scale => 100, v_scale => 100, |
|
|
1543 | h_align => 50, v_align => 50 }; |
|
|
1544 | |
|
|
1545 | $self->{bg_opts}->{shade} = $self->find_resource ("shading", "sh"); |
|
|
1546 | $self->{bg_opts}->{tint} = $self->find_resource ("tintColor", "tint"); |
|
|
1547 | $self->{bg_opts}->{blur} = $self->find_resource ("blurRadius", "blr"); |
|
|
1548 | $self->{bg_opts}->{root} = $self->find_resource ("transparent", "tr"); |
|
|
1549 | |
|
|
1550 | $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap")); |
|
|
1551 | $expr = $self->old_bg_expr; |
|
|
1552 | } |
|
|
1553 | |
1049 | or return; |
1554 | $expr or return; |
1050 | |
1555 | |
1051 | $self->has_render |
1556 | $self->has_render |
1052 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
1557 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
1053 | |
1558 | |
1054 | $self->set_expr (parse_expr $expr); |
1559 | $self->set_expr (parse_expr $expr); |