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.45 by root, Sun Jun 10 11:53:32 2012 UTC vs.
Revision 1.49 by root, Sun Jun 10 15:29:18 2012 UTC

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
19This extension manages the terminal background by creating a picture that 21This extension manages the terminal background by creating a picture that
20is behind the text, replacing the normal background colour. 22is behind the text, replacing the normal background colour.
189overwriting borders and any other areas, such as the scrollbar. 191overwriting borders and any other areas, such as the scrollbar.
190 192
191Specifying this flag changes the behaviour, so that the image only 193Specifying this flag changes the behaviour, so that the image only
192replaces the background of the character area. 194replaces the background of the character area.
193 195
196=item --background-interval seconds
197
198Since some operations in the underlying XRender extension can effetively
199freeze your X-server for prolonged time, this extension enforces a minimum
200time between updates, which is normally about 0.1 seconds.
201
202If you want to do updates more often, you can decrease this safety
203interval with this switch.
204
194=back 205=back
195 206
196=cut 207=cut
197 208
209our %_IMGCACHE;
198our $HOME; 210our $HOME;
199our ($self, $old, $new); 211our ($self, $old, $new);
200our ($x, $y, $w, $h); 212our ($x, $y, $w, $h);
201 213
202# enforce at least this interval between updates 214# enforce at least this interval between updates
203our $MIN_INTERVAL = 1/100; 215our $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
554Example: move the image right by 20 pixels and down by 30. 566Example: 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
572Aligns the image according to a factor - C<0> means the image is moved to
573the left or top edge (for C<$xalign> or C<$yalign>), C<0.5> means it is
574exactly centered and C<1> means it touches the right or bottom edge.
575
576Example: remove any visible border around an image, center it vertically but move
577it 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
562Centers the image, i.e. the center of the image is moved to the center of 585Centers the image, i.e. the center of the image is moved to the center of
563the terminal window (or the box specified by C<$width> and C<$height> if 586the terminal window (or the box specified by C<$width> and C<$height> if
564given). 587given).
588
589Example: 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
568Moves the image so that it appears glued to the screen as opposed to the 595Moves the image so that it appears glued to the screen as opposed to the
569window. This gives the illusion of a larger area behind the window. It is 596window. 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
577Example: take the screen background and align it, giving the illusion of 604Example: take the screen background and align it, giving the illusion of
578transparency as long as the window isn't in front of other windows. 605transparency 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
824sub on_start { 859sub 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines