… | |
… | |
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 | |
… | |
… | |
425 | the window size to conserve memory. |
424 | the window size to conserve memory. |
426 | |
425 | |
427 | Example: take the screen background, clip it to the window size, blur it a |
426 | 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. |
427 | bit, align it to the window position and use it as background. |
429 | |
428 | |
430 | clip move -TX, -TY, blur 5, root |
429 | clip move -TX, -TY, once { blur 5, root } |
431 | |
430 | |
432 | =cut |
431 | =cut |
433 | |
432 | |
434 | sub TX() { $new->{position_sensitive} = 1; $x } |
433 | sub TX() { $new->{again}{position} = 1; $x } |
435 | sub TY() { $new->{position_sensitive} = 1; $y } |
434 | sub TY() { $new->{again}{position} = 1; $y } |
436 | sub TW() { $new->{size_sensitive} = 1; $w } |
435 | sub TW() { $new->{again}{size} = 1; $w } |
437 | sub TH() { $new->{size_sensitive} = 1; $h } |
436 | sub TH() { $new->{again}{size} = 1; $h } |
438 | |
437 | |
439 | =item now |
438 | =item now |
440 | |
439 | |
441 | Returns the current time as (fractional) seconds since the epoch. |
440 | Returns the current time as (fractional) seconds since the epoch. |
442 | |
441 | |
… | |
… | |
461 | =cut |
460 | =cut |
462 | |
461 | |
463 | sub now() { urxvt::NOW } |
462 | sub now() { urxvt::NOW } |
464 | |
463 | |
465 | sub again($) { |
464 | sub again($) { |
466 | $new->{again} = $_[0]; |
465 | $new->{again}{time} = $_[0]; |
467 | } |
466 | } |
468 | |
467 | |
469 | sub counter($) { |
468 | sub counter($) { |
470 | $new->{again} = $_[0]; |
469 | $new->{again}{time} = $_[0]; |
471 | $self->{counter} + 0 |
470 | $self->{counter} + 0 |
472 | } |
471 | } |
473 | |
472 | |
474 | =back |
473 | =back |
475 | |
474 | |
… | |
… | |
799 | next call they will be reevaluated again. |
798 | next call they will be reevaluated again. |
800 | |
799 | |
801 | =cut |
800 | =cut |
802 | |
801 | |
803 | sub once(&) { |
802 | sub once(&) { |
804 | $_ONCE_CACHE{$_[0]+0} ||= $_[0]() |
803 | my $once = $self->{once_cache}{$_[0]+0} ||= do { |
|
|
804 | local $new->{again}; |
|
|
805 | my @res = $_[0](); |
|
|
806 | [$new->{again}, \@res] |
|
|
807 | }; |
|
|
808 | |
|
|
809 | $new->{again} = { |
|
|
810 | %{ $new->{again} }, |
|
|
811 | %{ $once->[0] } |
|
|
812 | }; |
|
|
813 | |
|
|
814 | # in scalar context we always return the first original result, which |
|
|
815 | # is not quite how perl works. |
|
|
816 | wantarray |
|
|
817 | ? @{ $once->[1] } |
|
|
818 | : $once->[1][0] |
805 | } |
819 | } |
806 | |
820 | |
807 | sub once_again() { |
821 | sub once_again() { |
808 | %_ONCE_CACHE = (); |
822 | delete $self->{once_cache}; |
809 | } |
823 | } |
810 | |
824 | |
811 | =back |
825 | =back |
812 | |
826 | |
813 | =cut |
827 | =cut |
… | |
… | |
858 | |
872 | |
859 | my $img = eval { $self->{expr}->() }; |
873 | my $img = eval { $self->{expr}->() }; |
860 | warn $@ if $@;#d# |
874 | warn $@ if $@;#d# |
861 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
875 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
862 | |
876 | |
863 | $state->{size_sensitive} = 1 |
877 | # if the expression is sensitive to external events, prepare reevaluation then |
|
|
878 | |
|
|
879 | my $again = delete $state->{again}; |
|
|
880 | |
|
|
881 | $again->{size} = 1 |
864 | if $img->repeat_mode != urxvt::RepeatNormal; |
882 | if $img->repeat_mode != urxvt::RepeatNormal; |
865 | |
883 | |
866 | # if the expression is sensitive to external events, prepare reevaluation then |
|
|
867 | |
|
|
868 | my $repeat; |
|
|
869 | |
|
|
870 | if (my $again = $state->{again}) { |
884 | if (my $again = $again->{time}) { |
871 | $repeat = 1; |
|
|
872 | my $self = $self; |
885 | my $self = $self; |
873 | $state->{timer} = $again == $old->{again} |
886 | $state->{timer} = $again == $old->{again} |
874 | ? $old->{timer} |
887 | ? $old->{timer} |
875 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
888 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
876 | ++$self->{counter}; |
889 | ++$self->{counter}; |
877 | $self->recalculate |
890 | $self->recalculate |
878 | }); |
891 | }); |
879 | } |
892 | } |
880 | |
893 | |
881 | if (delete $state->{position_sensitive}) { |
894 | if ($again->{position}) { |
882 | $repeat = 1; |
|
|
883 | $self->enable (position_change => sub { $_[0]->recalculate }); |
895 | $self->enable (position_change => sub { $_[0]->recalculate }); |
884 | } else { |
896 | } else { |
885 | $self->disable ("position_change"); |
897 | $self->disable ("position_change"); |
886 | } |
898 | } |
887 | |
899 | |
888 | if (delete $state->{size_sensitive}) { |
900 | if ($again->{size}) { |
889 | $repeat = 1; |
|
|
890 | $self->enable (size_change => sub { $_[0]->recalculate }); |
901 | $self->enable (size_change => sub { $_[0]->recalculate }); |
891 | } else { |
902 | } else { |
892 | $self->disable ("size_change"); |
903 | $self->disable ("size_change"); |
893 | } |
904 | } |
894 | |
905 | |
895 | if (delete $state->{rootpmap_sensitive}) { |
906 | if ($again->{rootpmap}) { |
896 | $repeat = 1; |
|
|
897 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
907 | $self->enable (rootpmap_change => sub { |
|
|
908 | delete $_[0]{once_cache}; # this will override once-block values from |
|
|
909 | $_[0]->recalculate; |
|
|
910 | }); |
898 | } else { |
911 | } else { |
899 | $self->disable ("rootpmap_change"); |
912 | $self->disable ("rootpmap_change"); |
900 | } |
913 | } |
901 | |
914 | |
902 | # clear stuff we no longer need |
915 | # clear stuff we no longer need |
903 | |
916 | |
904 | %$old = (); |
917 | %$old = (); |
905 | |
918 | |
906 | unless ($repeat) { |
919 | unless (%$again) { |
907 | delete $self->{state}; |
920 | delete $self->{state}; |
908 | delete $self->{expr}; |
921 | delete $self->{expr}; |
909 | } |
922 | } |
910 | |
923 | |
911 | # set background pixmap |
924 | # set background pixmap |