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.62 by root, Sun Jun 17 21:58:18 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
259 } 258 }
260 259
261=item root 260=item root
262 261
263Returns the root window pixmap, that is, hopefully, the background image 262Returns the root window pixmap, that is, hopefully, the background image
264of your screen. The image is set to extend mode. 263of your screen.
265 264
266This function makes your expression root sensitive, that means it will be 265This function makes your expression root sensitive, that means it will be
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
286=cut 285=cut
287 286
288 sub solid($;$$) { 287 sub solid($;$$) {
289 my $colour = pop; 288 my $colour = pop;
290 289
291 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); 290 my $img = $self->new_img (urxvt::PictStandardARGB32, 0, 0, $_[0] || 1, $_[1] || 1);
292 $img->fill ($colour); 291 $img->fill ($colour);
293 $img 292 $img
294 } 293 }
295 294
296=item clone $img 295=item clone $img
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. The tiling mode of the first image is used as
310the tiling mdoe of the resulting image.
311
312This function is called automatically when an expression returns multiple
313images.
314
315=cut
316
317 sub merge(@) {
318 return $_[0] unless $#_;
319
320 # rather annoyingly clumsy, but optimisation is for another time
321
322 my $x0 = +1e9;
323 my $y0 = +1e9;
324 my $x1 = -1e9;
325 my $y1 = -1e9;
326
327 for (@_) {
328 my ($x, $y, $w, $h) = $_->geometry;
329
330 $x0 = $x if $x0 > $x;
331 $y0 = $y if $y0 > $y;
332
333 $x += $w;
334 $y += $h;
335
336 $x1 = $x if $x1 < $x;
337 $y1 = $y if $y1 < $y;
338 }
339
340 my $base = $self->new_img (urxvt::PictStandardARGB32, $x0, $y0, $x1 - $x0, $y1 - $y0);
341 $base->repeat_mode ($_[0]->repeat_mode);
342 $base->fill ([0, 0, 0, 0]);
343
344 $base->draw ($_)
345 for @_;
346
347 $base
305 } 348 }
306 349
307=head2 TILING MODES 350=head2 TILING MODES
308 351
309The following operators modify the tiling mode of an image, that is, the 352The following operators modify the tiling mode of an image, that is, the
425the window size to conserve memory. 468the window size to conserve memory.
426 469
427Example: take the screen background, clip it to the window size, blur it a 470Example: 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. 471bit, align it to the window position and use it as background.
429 472
430 clip move -TX, -TY, blur 5, root 473 clip move -TX, -TY, once { blur 5, root }
431 474
432=cut 475=cut
433 476
434 sub TX() { $new->{position_sensitive} = 1; $x } 477 sub TX() { $new->{again}{position} = 1; $x }
435 sub TY() { $new->{position_sensitive} = 1; $y } 478 sub TY() { $new->{again}{position} = 1; $y }
436 sub TW() { $new->{size_sensitive} = 1; $w } 479 sub TW() { $new->{again}{size} = 1; $w }
437 sub TH() { $new->{size_sensitive} = 1; $h } 480 sub TH() { $new->{again}{size} = 1; $h }
438 481
439=item now 482=item now
440 483
441Returns the current time as (fractional) seconds since the epoch. 484Returns the current time as (fractional) seconds since the epoch.
442 485
461=cut 504=cut
462 505
463 sub now() { urxvt::NOW } 506 sub now() { urxvt::NOW }
464 507
465 sub again($) { 508 sub again($) {
466 $new->{again} = $_[0]; 509 $new->{again}{time} = $_[0];
467 } 510 }
468 511
469 sub counter($) { 512 sub counter($) {
470 $new->{again} = $_[0]; 513 $new->{again}{time} = $_[0];
471 $self->{counter} + 0 514 $self->{counter} + 0
472 } 515 }
473 516
474=back 517=back
475 518
661=cut 704=cut
662 705
663 sub rotate($$$$) { 706 sub rotate($$$$) {
664 my $img = pop; 707 my $img = pop;
665 $img->rotate ( 708 $img->rotate (
666 $_[0] * $img->w, 709 $_[0] * ($img->w + $img->x),
667 $_[1] * $img->h, 710 $_[1] * ($img->h + $img->y),
668 $_[2] * (3.14159265 / 180), 711 $_[2] * (3.14159265 / 180),
669 ) 712 )
670 } 713 }
671 714
672=back 715=back
762 805
763=back 806=back
764 807
765=head2 OTHER STUFF 808=head2 OTHER STUFF
766 809
767Anything that didn't fit any of the other categories, even after appliyng 810Anything that didn't fit any of the other categories, even after applying
768force and closing our eyes. 811force and closing our eyes.
769 812
770=over 4 813=over 4
771 814
772=item once { ... } 815=item once { ... }
799next call they will be reevaluated again. 842next call they will be reevaluated again.
800 843
801=cut 844=cut
802 845
803 sub once(&) { 846 sub once(&) {
804 $_ONCE_CACHE{$_[0]+0} ||= $_[0]() 847 my $once = $self->{once_cache}{$_[0]+0} ||= do {
848 local $new->{again};
849 my @res = $_[0]();
850 [$new->{again}, \@res]
851 };
852
853 $new->{again} = {
854 %{ $new->{again} },
855 %{ $once->[0] }
856 };
857
858 # in scalar context we always return the first original result, which
859 # is not quite how perl works.
860 wantarray
861 ? @{ $once->[1] }
862 : $once->[1][0]
805 } 863 }
806 864
807 sub once_again() { 865 sub once_again() {
808 %_ONCE_CACHE = (); 866 delete $self->{once_cache};
809 } 867 }
810 868
811=back 869=back
812 870
813=cut 871=cut
854 ($x, $y, $w, $h) = 912 ($x, $y, $w, $h) =
855 $self->background_geometry ($self->{border}); 913 $self->background_geometry ($self->{border});
856 914
857 # evaluate user expression 915 # evaluate user expression
858 916
859 my $img = eval { $self->{expr}->() }; 917 my $img = eval { urxvt::bgdsl::merge $self->{expr}->() };
860 warn $@ if $@;#d# 918 die $@ if $@;
861 die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; 919 die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img";
862 920
863 $state->{size_sensitive} = 1 921 # if the expression is sensitive to external events, prepare reevaluation then
922
923 my $again = delete $state->{again};
924
925 $again->{size} = 1
864 if $img->repeat_mode != urxvt::RepeatNormal; 926 if $img->repeat_mode != urxvt::RepeatNormal;
865 927
866 # if the expression is sensitive to external events, prepare reevaluation then
867
868 my $repeat;
869
870 if (my $again = $state->{again}) { 928 if (my $again = $again->{time}) {
871 $repeat = 1;
872 my $self = $self; 929 my $self = $self;
873 $state->{timer} = $again == $old->{again} 930 $state->{timer} = $again == $old->{again}
874 ? $old->{timer} 931 ? $old->{timer}
875 : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { 932 : urxvt::timer->new->after ($again)->interval ($again)->cb (sub {
876 ++$self->{counter}; 933 ++$self->{counter};
877 $self->recalculate 934 $self->recalculate
878 }); 935 });
879 } 936 }
880 937
881 if (delete $state->{position_sensitive}) { 938 if ($again->{position}) {
882 $repeat = 1;
883 $self->enable (position_change => sub { $_[0]->recalculate }); 939 $self->enable (position_change => sub { $_[0]->recalculate });
884 } else { 940 } else {
885 $self->disable ("position_change"); 941 $self->disable ("position_change");
886 } 942 }
887 943
888 if (delete $state->{size_sensitive}) { 944 if ($again->{size}) {
889 $repeat = 1;
890 $self->enable (size_change => sub { $_[0]->recalculate }); 945 $self->enable (size_change => sub { $_[0]->recalculate });
891 } else { 946 } else {
892 $self->disable ("size_change"); 947 $self->disable ("size_change");
893 } 948 }
894 949
895 if (delete $state->{rootpmap_sensitive}) { 950 if ($again->{rootpmap}) {
896 $repeat = 1;
897 $self->enable (rootpmap_change => sub { $_[0]->recalculate }); 951 $self->enable (rootpmap_change => sub {
952 delete $_[0]{once_cache}; # this will override once-block values from
953 $_[0]->recalculate;
954 });
898 } else { 955 } else {
899 $self->disable ("rootpmap_change"); 956 $self->disable ("rootpmap_change");
900 } 957 }
901 958
902 # clear stuff we no longer need 959 # clear stuff we no longer need
903 960
904 %$old = (); 961 %$old = ();
905 962
906 unless ($repeat) { 963 unless (%$again) {
907 delete $self->{state}; 964 delete $self->{state};
908 delete $self->{expr}; 965 delete $self->{expr};
909 } 966 }
910 967
911 # set background pixmap 968 # set background pixmap

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines