… | |
… | |
203 | =back |
203 | =back |
204 | |
204 | |
205 | =cut |
205 | =cut |
206 | |
206 | |
207 | our %_IMG_CACHE; |
207 | our %_IMG_CACHE; |
208 | our %_ONCE_CACHE; |
|
|
209 | our $HOME; |
208 | our $HOME; |
210 | our ($self, $old, $new); |
209 | our ($self, $old, $new); |
211 | our ($x, $y, $w, $h); |
210 | our ($x, $y, $w, $h); |
212 | |
211 | |
213 | # enforce at least this interval between updates |
212 | # enforce at least this interval between updates |
… | |
… | |
267 | reevaluated when the bg image changes. |
266 | reevaluated when the bg image changes. |
268 | |
267 | |
269 | =cut |
268 | =cut |
270 | |
269 | |
271 | sub root() { |
270 | sub root() { |
272 | $new->{rootpmap_sensitive} = 1; |
271 | $new->{again}{rootpmap} = 1; |
273 | $self->new_img_from_root |
272 | $self->new_img_from_root |
274 | } |
273 | } |
275 | |
274 | |
276 | =item solid $colour |
275 | =item solid $colour |
277 | |
276 | |
… | |
… | |
300 | |
299 | |
301 | =cut |
300 | =cut |
302 | |
301 | |
303 | sub clone($) { |
302 | sub clone($) { |
304 | $_[0]->clone |
303 | $_[0]->clone |
|
|
304 | } |
|
|
305 | |
|
|
306 | =item merge $img ... |
|
|
307 | |
|
|
308 | Takes any number of images and merges them together, creating a single |
|
|
309 | image containing them all. |
|
|
310 | |
|
|
311 | =cut |
|
|
312 | |
|
|
313 | sub merge(@) { |
|
|
314 | # rather annoyingly clumsy, but optimisation is for another time |
|
|
315 | |
|
|
316 | my $x0 = 1e9; |
|
|
317 | my $y0 = 1e9; |
|
|
318 | my $x1 = -1e9; |
|
|
319 | my $y1 = -1e9; |
|
|
320 | |
|
|
321 | for (@_) { |
|
|
322 | my ($x, $y, $w, $h) = $_->geometry; |
|
|
323 | |
|
|
324 | $x0 = $x if $x0 > $x; |
|
|
325 | $y0 = $y if $y0 > $y; |
|
|
326 | |
|
|
327 | $x += $w; |
|
|
328 | $y += $h; |
|
|
329 | |
|
|
330 | $x1 = $x if $x1 > $x; |
|
|
331 | $y1 = $y if $y1 > $y; |
|
|
332 | } |
|
|
333 | |
|
|
334 | my $base = $self->new_img ($x0, $y0, $x1 - $x0, $y1 - $y0); |
|
|
335 | $base->fill ([0, 0, 0, 0]); |
|
|
336 | |
|
|
337 | $base->blend (1., $_) |
|
|
338 | for @_; |
|
|
339 | |
|
|
340 | $base |
305 | } |
341 | } |
306 | |
342 | |
307 | =head2 TILING MODES |
343 | =head2 TILING MODES |
308 | |
344 | |
309 | The following operators modify the tiling mode of an image, that is, the |
345 | The following operators modify the tiling mode of an image, that is, the |
… | |
… | |
425 | the window size to conserve memory. |
461 | the window size to conserve memory. |
426 | |
462 | |
427 | Example: take the screen background, clip it to the window size, blur it a |
463 | Example: take the screen background, clip it to the window size, blur it a |
428 | bit, align it to the window position and use it as background. |
464 | bit, align it to the window position and use it as background. |
429 | |
465 | |
430 | clip move -TX, -TY, blur 5, root |
466 | clip move -TX, -TY, once { blur 5, root } |
431 | |
467 | |
432 | =cut |
468 | =cut |
433 | |
469 | |
434 | sub TX() { $new->{position_sensitive} = 1; $x } |
470 | sub TX() { $new->{again}{position} = 1; $x } |
435 | sub TY() { $new->{position_sensitive} = 1; $y } |
471 | sub TY() { $new->{again}{position} = 1; $y } |
436 | sub TW() { $new->{size_sensitive} = 1; $w } |
472 | sub TW() { $new->{again}{size} = 1; $w } |
437 | sub TH() { $new->{size_sensitive} = 1; $h } |
473 | sub TH() { $new->{again}{size} = 1; $h } |
438 | |
474 | |
439 | =item now |
475 | =item now |
440 | |
476 | |
441 | Returns the current time as (fractional) seconds since the epoch. |
477 | Returns the current time as (fractional) seconds since the epoch. |
442 | |
478 | |
… | |
… | |
461 | =cut |
497 | =cut |
462 | |
498 | |
463 | sub now() { urxvt::NOW } |
499 | sub now() { urxvt::NOW } |
464 | |
500 | |
465 | sub again($) { |
501 | sub again($) { |
466 | $new->{again} = $_[0]; |
502 | $new->{again}{time} = $_[0]; |
467 | } |
503 | } |
468 | |
504 | |
469 | sub counter($) { |
505 | sub counter($) { |
470 | $new->{again} = $_[0]; |
506 | $new->{again}{time} = $_[0]; |
471 | $self->{counter} + 0 |
507 | $self->{counter} + 0 |
472 | } |
508 | } |
473 | |
509 | |
474 | =back |
510 | =back |
475 | |
511 | |
… | |
… | |
762 | |
798 | |
763 | =back |
799 | =back |
764 | |
800 | |
765 | =head2 OTHER STUFF |
801 | =head2 OTHER STUFF |
766 | |
802 | |
767 | Anything that didn't fit any of the other categories, even after appliyng |
803 | Anything that didn't fit any of the other categories, even after applying |
768 | force and closing our eyes. |
804 | force and closing our eyes. |
769 | |
805 | |
770 | =over 4 |
806 | =over 4 |
771 | |
807 | |
772 | =item once { ... } |
808 | =item once { ... } |
… | |
… | |
799 | next call they will be reevaluated again. |
835 | next call they will be reevaluated again. |
800 | |
836 | |
801 | =cut |
837 | =cut |
802 | |
838 | |
803 | sub once(&) { |
839 | sub once(&) { |
804 | $_ONCE_CACHE{$_[0]+0} ||= $_[0]() |
840 | my $once = $self->{once_cache}{$_[0]+0} ||= do { |
|
|
841 | local $new->{again}; |
|
|
842 | my @res = $_[0](); |
|
|
843 | [$new->{again}, \@res] |
|
|
844 | }; |
|
|
845 | |
|
|
846 | $new->{again} = { |
|
|
847 | %{ $new->{again} }, |
|
|
848 | %{ $once->[0] } |
|
|
849 | }; |
|
|
850 | |
|
|
851 | # in scalar context we always return the first original result, which |
|
|
852 | # is not quite how perl works. |
|
|
853 | wantarray |
|
|
854 | ? @{ $once->[1] } |
|
|
855 | : $once->[1][0] |
805 | } |
856 | } |
806 | |
857 | |
807 | sub once_again() { |
858 | sub once_again() { |
808 | %_ONCE_CACHE = (); |
859 | delete $self->{once_cache}; |
809 | } |
860 | } |
810 | |
861 | |
811 | =back |
862 | =back |
812 | |
863 | |
813 | =cut |
864 | =cut |
… | |
… | |
858 | |
909 | |
859 | my $img = eval { $self->{expr}->() }; |
910 | my $img = eval { $self->{expr}->() }; |
860 | warn $@ if $@;#d# |
911 | warn $@ if $@;#d# |
861 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
912 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
862 | |
913 | |
863 | $state->{size_sensitive} = 1 |
914 | # if the expression is sensitive to external events, prepare reevaluation then |
|
|
915 | |
|
|
916 | my $again = delete $state->{again}; |
|
|
917 | |
|
|
918 | $again->{size} = 1 |
864 | if $img->repeat_mode != urxvt::RepeatNormal; |
919 | if $img->repeat_mode != urxvt::RepeatNormal; |
865 | |
920 | |
866 | # if the expression is sensitive to external events, prepare reevaluation then |
|
|
867 | |
|
|
868 | my $repeat; |
|
|
869 | |
|
|
870 | if (my $again = $state->{again}) { |
921 | if (my $again = $again->{time}) { |
871 | $repeat = 1; |
|
|
872 | my $self = $self; |
922 | my $self = $self; |
873 | $state->{timer} = $again == $old->{again} |
923 | $state->{timer} = $again == $old->{again} |
874 | ? $old->{timer} |
924 | ? $old->{timer} |
875 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
925 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
876 | ++$self->{counter}; |
926 | ++$self->{counter}; |
877 | $self->recalculate |
927 | $self->recalculate |
878 | }); |
928 | }); |
879 | } |
929 | } |
880 | |
930 | |
881 | if (delete $state->{position_sensitive}) { |
931 | if ($again->{position}) { |
882 | $repeat = 1; |
|
|
883 | $self->enable (position_change => sub { $_[0]->recalculate }); |
932 | $self->enable (position_change => sub { $_[0]->recalculate }); |
884 | } else { |
933 | } else { |
885 | $self->disable ("position_change"); |
934 | $self->disable ("position_change"); |
886 | } |
935 | } |
887 | |
936 | |
888 | if (delete $state->{size_sensitive}) { |
937 | if ($again->{size}) { |
889 | $repeat = 1; |
|
|
890 | $self->enable (size_change => sub { $_[0]->recalculate }); |
938 | $self->enable (size_change => sub { $_[0]->recalculate }); |
891 | } else { |
939 | } else { |
892 | $self->disable ("size_change"); |
940 | $self->disable ("size_change"); |
893 | } |
941 | } |
894 | |
942 | |
895 | if (delete $state->{rootpmap_sensitive}) { |
943 | if ($again->{rootpmap}) { |
896 | $repeat = 1; |
|
|
897 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
944 | $self->enable (rootpmap_change => sub { |
|
|
945 | delete $_[0]{once_cache}; # this will override once-block values from |
|
|
946 | $_[0]->recalculate; |
|
|
947 | }); |
898 | } else { |
948 | } else { |
899 | $self->disable ("rootpmap_change"); |
949 | $self->disable ("rootpmap_change"); |
900 | } |
950 | } |
901 | |
951 | |
902 | # clear stuff we no longer need |
952 | # clear stuff we no longer need |
903 | |
953 | |
904 | %$old = (); |
954 | %$old = (); |
905 | |
955 | |
906 | unless ($repeat) { |
956 | unless (%$again) { |
907 | delete $self->{state}; |
957 | delete $self->{state}; |
908 | delete $self->{expr}; |
958 | delete $self->{expr}; |
909 | } |
959 | } |
910 | |
960 | |
911 | # set background pixmap |
961 | # set background pixmap |