--- rxvt-unicode/src/perl/background 2012/06/14 17:06:57 1.56 +++ rxvt-unicode/src/perl/background 2012/06/17 21:58:18 1.62 @@ -260,7 +260,7 @@ =item root Returns the root window pixmap, that is, hopefully, the background image -of your screen. The image is set to extend mode. +of your screen. This function makes your expression root sensitive, that means it will be reevaluated when the bg image changes. @@ -287,7 +287,7 @@ sub solid($;$$) { my $colour = pop; - my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); + my $img = $self->new_img (urxvt::PictStandardARGB32, 0, 0, $_[0] || 1, $_[1] || 1); $img->fill ($colour); $img } @@ -305,12 +305,46 @@ =item merge $img ... -Takes any number of images and merges them together, creating a single image containing them all. +Takes any number of images and merges them together, creating a single +image containing them all. The tiling mode of the first image is used as +the tiling mdoe of the resulting image. + +This function is called automatically when an expression returns multiple +images. =cut sub merge(@) { - #TODO + return $_[0] unless $#_; + + # rather annoyingly clumsy, but optimisation is for another time + + my $x0 = +1e9; + my $y0 = +1e9; + my $x1 = -1e9; + my $y1 = -1e9; + + for (@_) { + my ($x, $y, $w, $h) = $_->geometry; + + $x0 = $x if $x0 > $x; + $y0 = $y if $y0 > $y; + + $x += $w; + $y += $h; + + $x1 = $x if $x1 < $x; + $y1 = $y if $y1 < $y; + } + + my $base = $self->new_img (urxvt::PictStandardARGB32, $x0, $y0, $x1 - $x0, $y1 - $y0); + $base->repeat_mode ($_[0]->repeat_mode); + $base->fill ([0, 0, 0, 0]); + + $base->draw ($_) + for @_; + + $base } =head2 TILING MODES @@ -672,8 +706,8 @@ sub rotate($$$$) { my $img = pop; $img->rotate ( - $_[0] * $img->w, - $_[1] * $img->h, + $_[0] * ($img->w + $img->x), + $_[1] * ($img->h + $img->y), $_[2] * (3.14159265 / 180), ) } @@ -880,8 +914,8 @@ # evaluate user expression - my $img = eval { $self->{expr}->() }; - warn $@ if $@;#d# + my $img = eval { urxvt::bgdsl::merge $self->{expr}->() }; + die $@ if $@; die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; # if the expression is sensitive to external events, prepare reevaluation then