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 | |
|
|
209 | our %_IMGCACHE; |
198 | our $HOME; |
210 | our $HOME; |
199 | our ($self, $old, $new); |
211 | our ($self, $old, $new); |
200 | our ($x, $y, $w, $h); |
212 | our ($x, $y, $w, $h); |
201 | |
213 | |
202 | # enforce at least this interval between updates |
214 | # enforce at least this interval between updates |
203 | our $MIN_INTERVAL = 1/100; |
215 | our $MIN_INTERVAL = 6/59.951; |
204 | |
216 | |
205 | { |
217 | { |
206 | package urxvt::bgdsl; # background language |
218 | package urxvt::bgdsl; # background language |
207 | |
219 | |
208 | use List::Util qw(min max sum shuffle); |
220 | use List::Util qw(min max sum shuffle); |
… | |
… | |
553 | |
565 | |
554 | Example: move the image right by 20 pixels and down by 30. |
566 | Example: move the image right by 20 pixels and down by 30. |
555 | |
567 | |
556 | move 20, 30, ... |
568 | move 20, 30, ... |
557 | |
569 | |
|
|
570 | =item align $xalign, $yalign, $img |
|
|
571 | |
|
|
572 | Aligns the image according to a factor - C<0> means the image is moved to |
|
|
573 | the left or top edge (for C<$xalign> or C<$yalign>), C<0.5> means it is |
|
|
574 | exactly centered and C<1> means it touches the right or bottom edge. |
|
|
575 | |
|
|
576 | Example: remove any visible border around an image, center it vertically but move |
|
|
577 | it to the right hand side. |
|
|
578 | |
|
|
579 | align 1, 0.5, pad $img |
|
|
580 | |
558 | =item center $img |
581 | =item center $img |
559 | |
582 | |
560 | =item center $width, $height, $img |
583 | =item center $width, $height, $img |
561 | |
584 | |
562 | Centers the image, i.e. the center of the image is moved to the center of |
585 | 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 |
586 | the terminal window (or the box specified by C<$width> and C<$height> if |
564 | given). |
587 | given). |
|
|
588 | |
|
|
589 | Example: load an image and center it. |
|
|
590 | |
|
|
591 | center pad load "mybg.png" |
565 | |
592 | |
566 | =item rootalign $img |
593 | =item rootalign $img |
567 | |
594 | |
568 | Moves the image so that it appears glued to the screen as opposed to the |
595 | 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 |
596 | window. This gives the illusion of a larger area behind the window. It is |
… | |
… | |
575 | rootalign mirror load "mybg.png" |
602 | rootalign mirror load "mybg.png" |
576 | |
603 | |
577 | Example: take the screen background and align it, giving the illusion of |
604 | 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. |
605 | transparency as long as the window isn't in front of other windows. |
579 | |
606 | |
580 | rootalign root |
607 | rootalign root |
581 | |
608 | |
582 | =cut |
609 | =cut |
583 | |
610 | |
584 | sub move($$;$) { |
611 | sub move($$;$) { |
585 | my $img = pop->clone; |
612 | my $img = pop->clone; |
586 | $img->move ($_[0], $_[1]); |
613 | $img->move ($_[0], $_[1]); |
587 | $img |
614 | $img |
588 | } |
615 | } |
589 | |
616 | |
|
|
617 | sub align($;$$) { |
|
|
618 | my $img = pop; |
|
|
619 | |
|
|
620 | move $_[0] * (TW - $img->w), |
|
|
621 | $_[1] * (TH - $img->h), |
|
|
622 | $img |
|
|
623 | } |
|
|
624 | |
590 | sub center($;$$) { |
625 | sub center($;$$) { |
591 | my $img = pop; |
626 | my $img = pop; |
592 | my $w = $_[0] || TW; |
627 | my $w = $_[0] || TW; |
593 | my $h = $_[0] || TH; |
628 | my $h = $_[1] || TH; |
594 | |
629 | |
595 | move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img |
630 | move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img |
596 | } |
631 | } |
597 | |
632 | |
598 | sub rootalign($) { |
633 | sub rootalign($) { |
… | |
… | |
649 | |
684 | |
650 | sub contrast($$;$$;$) { |
685 | sub contrast($$;$$;$) { |
651 | my $img = pop; |
686 | my $img = pop; |
652 | my ($r, $g, $b, $a) = @_; |
687 | my ($r, $g, $b, $a) = @_; |
653 | |
688 | |
654 | ($g, $b) = ($r, $r) if @_ < 4; |
689 | ($g, $b) = ($r, $r) if @_ < 3; |
655 | $a = 1 if @_ < 5; |
690 | $a = 1 if @_ < 4; |
656 | |
691 | |
657 | $img = $img->clone; |
692 | $img = $img->clone; |
658 | $img->contrast ($r, $g, $b, $a); |
693 | $img->contrast ($r, $g, $b, $a); |
659 | $img |
694 | $img |
660 | } |
695 | } |
661 | |
696 | |
662 | sub brightness($$;$$;$) { |
697 | sub brightness($$;$$;$) { |
663 | my $img = pop; |
698 | my $img = pop; |
664 | my ($r, $g, $b, $a) = @_; |
699 | my ($r, $g, $b, $a) = @_; |
665 | |
700 | |
666 | ($g, $b) = ($r, $r) if @_ < 4; |
701 | ($g, $b) = ($r, $r) if @_ < 3; |
667 | $a = 1 if @_ < 5; |
702 | $a = 1 if @_ < 4; |
668 | |
703 | |
669 | $img = $img->clone; |
704 | $img = $img->clone; |
670 | $img->brightness ($r, $g, $b, $a); |
705 | $img->brightness ($r, $g, $b, $a); |
671 | $img |
706 | $img |
672 | } |
707 | } |
… | |
… | |
762 | |
797 | |
763 | # evaluate user expression |
798 | # evaluate user expression |
764 | |
799 | |
765 | my $img = eval { $self->{expr}->() }; |
800 | my $img = eval { $self->{expr}->() }; |
766 | warn $@ if $@;#d# |
801 | warn $@ if $@;#d# |
767 | die if !UNIVERSAL::isa $img, "urxvt::img"; |
802 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
768 | |
803 | |
769 | $state->{size_sensitive} = 1 |
804 | $state->{size_sensitive} = 1 |
770 | if $img->repeat_mode != urxvt::RepeatNormal; |
805 | if $img->repeat_mode != urxvt::RepeatNormal; |
771 | |
806 | |
772 | # if the expression is sensitive to external events, prepare reevaluation then |
807 | # if the expression is sensitive to external events, prepare reevaluation then |
… | |
… | |
822 | } |
857 | } |
823 | |
858 | |
824 | sub on_start { |
859 | sub on_start { |
825 | my ($self) = @_; |
860 | my ($self) = @_; |
826 | |
861 | |
827 | my $expr = $self->x_resource ("background.expr") |
862 | my $expr = $self->x_resource ("%.expr") |
828 | or return; |
863 | or return; |
829 | |
864 | |
|
|
865 | $self->has_render |
|
|
866 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
|
|
867 | |
830 | $self->set_expr (parse_expr $expr); |
868 | $self->set_expr (parse_expr $expr); |
831 | $self->{border} = $self->x_resource_boolean ("background.border"); |
869 | $self->{border} = $self->x_resource_boolean ("%.border"); |
|
|
870 | |
|
|
871 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
832 | |
872 | |
833 | () |
873 | () |
834 | } |
874 | } |
835 | |
875 | |