… | |
… | |
73 | } else { |
73 | } else { |
74 | return load "$HOME/sunday.png"; |
74 | return load "$HOME/sunday.png"; |
75 | } |
75 | } |
76 | } |
76 | } |
77 | |
77 | |
78 | This expression is evaluated once per hour. It will set F<sunday.png> as |
78 | This inner expression is evaluated once per hour (and whenever the |
|
|
79 | temrinal window is resized). It sets F<sunday.png> as background on |
79 | background on Sundays, and F<weekday.png> on all other days. |
80 | Sundays, and F<weekday.png> on all other days. |
80 | |
81 | |
81 | Fortunately, we expect that most expressions will be much simpler, with |
82 | Fortunately, we expect that most expressions will be much simpler, with |
82 | little Perl knowledge needed. |
83 | little Perl knowledge needed. |
83 | |
84 | |
84 | Basically, you always start with a function that "generates" an image |
85 | Basically, you always start with a function that "generates" an image |
… | |
… | |
117 | horizontal and vertical dimensions. For example, this halves the image |
118 | horizontal and vertical dimensions. For example, this halves the image |
118 | width and doubles the image height: |
119 | width and doubles the image height: |
119 | |
120 | |
120 | scale 0.5, 2, load "$HOME/mypic.png" |
121 | scale 0.5, 2, load "$HOME/mypic.png" |
121 | |
122 | |
122 | IF you try out these expressions, you might suffer from sluggishness, |
123 | 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 |
124 | because each time the terminal is resized, it loads the PNG image agin |
124 | and scales it. Scaling is usually fast, but loading the image can be quite |
125 | and scales it. Scaling is usually fast (and unavoidable), but loading the |
125 | time consuming. This is where C<keep> comes in handy: |
126 | image can be quite time consuming. This is where C<keep> comes in handy: |
126 | |
127 | |
127 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
128 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
128 | |
129 | |
129 | The C<keep> operator executes all the statements inside the braces only |
130 | 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 |
131 | once, or when it thinks the outcome might change. In other cases it |
… | |
… | |
183 | When such an event happens, C<keep> will automatically trigger a |
184 | When such an event happens, C<keep> will automatically trigger a |
184 | reevaluation of the whole expression with the new value of the expression. |
185 | reevaluation of the whole expression with the new value of the expression. |
185 | |
186 | |
186 | C<keep> is most useful for expensive operations, such as C<blur>: |
187 | C<keep> is most useful for expensive operations, such as C<blur>: |
187 | |
188 | |
188 | rootalign once { blur 20, root } |
189 | rootalign keep { blur 20, root } |
189 | |
190 | |
190 | This makes a blurred copy of the root background once, and on subsequent |
191 | 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 |
192 | 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 |
193 | 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 |
194 | blurred pixmap) with speed (blur only needs to be redone when root |
… | |
… | |
276 | Load uncached - same as load, but does not cache the image, which means it |
277 | Load uncached - same as load, but does not cache the image, which means it |
277 | is I<always> loaded from the filesystem again. |
278 | is I<always> loaded from the filesystem again. |
278 | |
279 | |
279 | =cut |
280 | =cut |
280 | |
281 | |
281 | sub load_uc($) { |
|
|
282 | $self->new_img_from_file ($path) |
|
|
283 | } |
|
|
284 | |
|
|
285 | sub load($) { |
282 | sub load($) { |
286 | my ($path) = @_; |
283 | my ($path) = @_; |
287 | |
284 | |
288 | $_IMG_CACHE{$path} || do { |
285 | $_IMG_CACHE{$path} || do { |
289 | my $img = load_uc $path; |
286 | my $img = $self->new_img_from_file ($path); |
290 | Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); |
287 | Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); |
291 | $img |
288 | $img |
292 | } |
289 | } |
293 | } |
290 | } |
294 | |
291 | |
… | |
… | |
753 | |
750 | |
754 | The following operators change the pixels of the image. |
751 | The following operators change the pixels of the image. |
755 | |
752 | |
756 | =over 4 |
753 | =over 4 |
757 | |
754 | |
|
|
755 | =item tint $color, $img |
|
|
756 | |
|
|
757 | Tints the image in the given colour. |
|
|
758 | |
|
|
759 | Example: tint the image red. |
|
|
760 | |
|
|
761 | tint "red", load "rgb.png" |
|
|
762 | |
|
|
763 | Example: the same, but specify the colour by component. |
|
|
764 | |
|
|
765 | tint [1, 0, 0], load "rgb.png" |
|
|
766 | |
|
|
767 | =cut |
|
|
768 | |
|
|
769 | sub tint($$) { |
|
|
770 | $_[1]->tint ($_[0]) |
|
|
771 | } |
|
|
772 | |
758 | =item contrast $factor, $img |
773 | =item contrast $factor, $img |
759 | |
774 | |
760 | =item contrast $r, $g, $b, $img |
775 | =item contrast $r, $g, $b, $img |
761 | |
776 | |
762 | =item contrast $r, $g, $b, $a, $img |
777 | =item contrast $r, $g, $b, $a, $img |
… | |
… | |
847 | |
862 | |
848 | =over 4 |
863 | =over 4 |
849 | |
864 | |
850 | =item keep { ... } |
865 | =item keep { ... } |
851 | |
866 | |
852 | #TODO# |
|
|
853 | |
|
|
854 | This operator takes a code block as argument, that is, one or more |
867 | This operator takes a code block as argument, that is, one or more |
855 | statements enclosed by braces. |
868 | statements enclosed by braces. |
856 | |
869 | |
857 | The trick is that this code block is only evaluated once - future calls |
870 | 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 |
871 | changes - on other calls the C<keep> simply returns the image it computed |
859 | images). |
872 | previously (yes, it should only be used with images). Or in other words, |
|
|
873 | C<keep> I<caches> the result of the code block so it doesn't need to be |
|
|
874 | computed again. |
860 | |
875 | |
861 | This can be extremely useful to avoid redoing the same slow operations |
876 | This can be extremely useful to avoid redoing slow operations - for |
862 | again and again- for example, if your background expression takes the root |
877 | 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 |
878 | and then root-aligns it it would have to blur the root background on every |
864 | root background on every window move or resize. |
879 | window move or resize. |
|
|
880 | |
|
|
881 | Another example is C<load>, which can be quite slow. |
865 | |
882 | |
866 | In fact, urxvt itself encloses the whole expression in some kind of |
883 | In fact, urxvt itself encloses the whole expression in some kind of |
867 | C<once> block so it only is reevaluated as required. |
884 | C<keep> block so it only is reevaluated as required. |
868 | |
885 | |
869 | Putting the blur into a C<once> block will make sure the blur is only done |
886 | Putting the blur into a C<keep> block will make sure the blur is only done |
870 | once: |
887 | once, while the C<rootalign> is still done each time the window moves. |
871 | |
888 | |
872 | rootlign keep { blur 10, root } |
889 | rootlign keep { blur 10, root } |
873 | |
890 | |
874 | This leaves the question of how to force reevaluation of the block, |
891 | This leaves the question of how to force reevaluation of the block, |
875 | in case the root background changes: If expression inside the block |
892 | in case the root background changes: If expression inside the block |
876 | is sensitive to some event (root background changes, window geometry |
893 | is sensitive to some event (root background changes, window geometry |
877 | changes), then it will be reevaluated automatically as needed. |
894 | changes), then it will be reevaluated automatically as needed. |
878 | |
895 | |
879 | =item once_again |
|
|
880 | |
|
|
881 | Resets all C<once> block as if they had never been called, i.e. on the |
|
|
882 | next call they will be reevaluated again. |
|
|
883 | |
|
|
884 | =cut |
896 | =cut |
885 | |
897 | |
886 | sub once(&) { |
898 | sub keep(&) { |
887 | my $id = $_[0]+0; |
899 | my $id = $_[0]+0; |
888 | |
900 | |
889 | local $frame = $self->{frame_cache}{$id} ||= [$frame]; |
901 | local $frame = $self->{frame_cache}{$id} ||= [$frame]; |
890 | |
902 | |
891 | unless ($frame->[FR_CACHE]) { |
903 | unless ($frame->[FR_CACHE]) { |
… | |
… | |
909 | wantarray |
921 | wantarray |
910 | ? @{ $frame->[FR_CACHE] } |
922 | ? @{ $frame->[FR_CACHE] } |
911 | : $frame->[FR_CACHE][0] |
923 | : $frame->[FR_CACHE][0] |
912 | } |
924 | } |
913 | |
925 | |
914 | sub once_again() { |
926 | # sub keep_clear() { |
915 | delete $self->{frame_cache}; |
927 | # delete $self->{frame_cache}; |
916 | } |
928 | # } |
917 | |
929 | |
918 | =back |
930 | =back |
919 | |
931 | |
920 | =cut |
932 | =cut |
921 | |
933 | |