1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
4 | #:META:X_RESOURCE:%.border.:boolean:respect the terminal border |
4 | #:META:X_RESOURCE:%.border:boolean:respect the terminal border |
|
|
5 | #:META:X_RESOURCE:%.interval:seconds:minimum time between updates |
5 | |
6 | |
6 | #TODO: once, rootalign |
7 | #TODO: once, rootalign |
7 | |
8 | |
8 | =head1 NAME |
9 | =head1 NAME |
9 | |
10 | |
… | |
… | |
11 | |
12 | |
12 | =head1 SYNOPSIS |
13 | =head1 SYNOPSIS |
13 | |
14 | |
14 | urxvt --background-expr 'background expression' |
15 | urxvt --background-expr 'background expression' |
15 | --background-border |
16 | --background-border |
|
|
17 | --background-interval seconds |
16 | |
18 | |
17 | =head1 DESCRIPTION |
19 | =head1 DESCRIPTION |
18 | |
20 | |
19 | This extension manages the terminal background by creating a picture that |
21 | This extension manages the terminal background by creating a picture that |
20 | is behind the text, replacing the normal background colour. |
22 | is behind the text, replacing the normal background colour. |
… | |
… | |
189 | overwriting borders and any other areas, such as the scrollbar. |
191 | overwriting borders and any other areas, such as the scrollbar. |
190 | |
192 | |
191 | Specifying this flag changes the behaviour, so that the image only |
193 | Specifying this flag changes the behaviour, so that the image only |
192 | replaces the background of the character area. |
194 | replaces the background of the character area. |
193 | |
195 | |
|
|
196 | =item --background-interval seconds |
|
|
197 | |
|
|
198 | Since some operations in the underlying XRender extension can effetively |
|
|
199 | freeze your X-server for prolonged time, this extension enforces a minimum |
|
|
200 | time between updates, which is normally about 0.1 seconds. |
|
|
201 | |
|
|
202 | If you want to do updates more often, you can decrease this safety |
|
|
203 | interval with this switch. |
|
|
204 | |
194 | =back |
205 | =back |
195 | |
206 | |
196 | =cut |
207 | =cut |
197 | |
208 | |
198 | our $HOME; |
209 | our $HOME; |
199 | our ($self, $old, $new); |
210 | our ($self, $old, $new); |
200 | our ($x, $y, $w, $h); |
211 | our ($x, $y, $w, $h); |
201 | |
212 | |
202 | # enforce at least this interval between updates |
213 | # enforce at least this interval between updates |
203 | our $MIN_INTERVAL = 1/100; |
214 | our $MIN_INTERVAL = 6/59.951; |
204 | |
215 | |
205 | { |
216 | { |
206 | package urxvt::bgdsl; # background language |
217 | package urxvt::bgdsl; # background language |
207 | |
218 | |
208 | use List::Util qw(min max sum shuffle); |
219 | use List::Util qw(min max sum shuffle); |
… | |
… | |
553 | |
564 | |
554 | Example: move the image right by 20 pixels and down by 30. |
565 | Example: move the image right by 20 pixels and down by 30. |
555 | |
566 | |
556 | move 20, 30, ... |
567 | move 20, 30, ... |
557 | |
568 | |
|
|
569 | =item align $xalign, $yalign, $img |
|
|
570 | |
|
|
571 | Aligns the image according to a factor - C<0> means the image is moved to |
|
|
572 | the left or top edge (for C<$xalign> or C<$yalign>), C<0.5> means it is |
|
|
573 | exactly centered and C<1> means it touches the right or bottom edge. |
|
|
574 | |
|
|
575 | Example: remove any visible border around an image, center it vertically but move |
|
|
576 | it to the right hand side. |
|
|
577 | |
|
|
578 | align 1, 0.5, pad $img |
|
|
579 | |
558 | =item center $img |
580 | =item center $img |
559 | |
581 | |
560 | =item center $width, $height, $img |
582 | =item center $width, $height, $img |
561 | |
583 | |
562 | Centers the image, i.e. the center of the image is moved to the center of |
584 | Centers the image, i.e. the center of the image is moved to the center of |
563 | the terminal window (or the box specified by C<$width> and C<$height> if |
585 | the terminal window (or the box specified by C<$width> and C<$height> if |
564 | given). |
586 | given). |
|
|
587 | |
|
|
588 | Example: load an image and center it. |
|
|
589 | |
|
|
590 | center pad load "mybg.png" |
565 | |
591 | |
566 | =item rootalign $img |
592 | =item rootalign $img |
567 | |
593 | |
568 | Moves the image so that it appears glued to the screen as opposed to the |
594 | Moves the image so that it appears glued to the screen as opposed to the |
569 | window. This gives the illusion of a larger area behind the window. It is |
595 | window. This gives the illusion of a larger area behind the window. It is |
… | |
… | |
575 | rootalign mirror load "mybg.png" |
601 | rootalign mirror load "mybg.png" |
576 | |
602 | |
577 | Example: take the screen background and align it, giving the illusion of |
603 | Example: take the screen background and align it, giving the illusion of |
578 | transparency as long as the window isn't in front of other windows. |
604 | transparency as long as the window isn't in front of other windows. |
579 | |
605 | |
580 | rootalign root |
606 | rootalign root |
581 | |
607 | |
582 | =cut |
608 | =cut |
583 | |
609 | |
584 | sub move($$;$) { |
610 | sub move($$;$) { |
585 | my $img = pop->clone; |
611 | my $img = pop->clone; |
586 | $img->move ($_[0], $_[1]); |
612 | $img->move ($_[0], $_[1]); |
587 | $img |
613 | $img |
588 | } |
614 | } |
589 | |
615 | |
|
|
616 | sub align($;$$) { |
|
|
617 | my $img = pop; |
|
|
618 | |
|
|
619 | move $_[0] * (TW - $img->w), |
|
|
620 | $_[1] * (TH - $img->h), |
|
|
621 | $img |
|
|
622 | } |
|
|
623 | |
590 | sub center($;$$) { |
624 | sub center($;$$) { |
591 | my $img = pop; |
625 | my $img = pop; |
592 | my $w = $_[0] || TW; |
626 | my $w = $_[0] || TW; |
593 | my $h = $_[0] || TH; |
627 | my $h = $_[1] || TH; |
594 | |
628 | |
595 | move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img |
629 | move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img |
596 | } |
630 | } |
597 | |
631 | |
598 | sub rootalign($) { |
632 | sub rootalign($) { |
… | |
… | |
828 | or return; |
862 | or return; |
829 | |
863 | |
830 | $self->set_expr (parse_expr $expr); |
864 | $self->set_expr (parse_expr $expr); |
831 | $self->{border} = $self->x_resource_boolean ("background.border"); |
865 | $self->{border} = $self->x_resource_boolean ("background.border"); |
832 | |
866 | |
|
|
867 | $MIN_INTERVAL = $self->x_resource ("background.interval"); |
|
|
868 | |
833 | () |
869 | () |
834 | } |
870 | } |
835 | |
871 | |