ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
(Generate patch)

Comparing rxvt-unicode/src/perl/background (file contents):
Revision 1.54 by root, Thu Jun 14 16:22:20 2012 UTC vs.
Revision 1.58 by root, Thu Jun 14 18:13:19 2012 UTC

203=back 203=back
204 204
205=cut 205=cut
206 206
207our %_IMG_CACHE; 207our %_IMG_CACHE;
208our %_ONCE_CACHE;
209our $HOME; 208our $HOME;
210our ($self, $old, $new); 209our ($self, $old, $new);
211our ($x, $y, $w, $h); 210our ($x, $y, $w, $h);
212 211
213# enforce at least this interval between updates 212# enforce at least this interval between updates
267reevaluated when the bg image changes. 266reevaluated 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
308Takes any number of images and merges them together, creating a single
309image 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
309The following operators modify the tiling mode of an image, that is, the 345The following operators modify the tiling mode of an image, that is, the
425the window size to conserve memory. 461the window size to conserve memory.
426 462
427Example: take the screen background, clip it to the window size, blur it a 463Example: take the screen background, clip it to the window size, blur it a
428bit, align it to the window position and use it as background. 464bit, 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
441Returns the current time as (fractional) seconds since the epoch. 477Returns 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
767Anything that didn't fit any of the other categories, even after appliyng 803Anything that didn't fit any of the other categories, even after applying
768force and closing our eyes. 804force and closing our eyes.
769 805
770=over 4 806=over 4
771 807
772=item once { ... } 808=item once { ... }
799next call they will be reevaluated again. 835next 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines