… | |
… | |
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 | #:META:X_RESOURCE:%.interval:seconds:minimum time between updates |
6 | |
6 | |
7 | =head1 NAME |
7 | =head1 NAME |
8 | |
8 | |
9 | background - manage terminal background |
9 | background - manage terminal background |
10 | |
10 | |
11 | =head1 SYNOPSIS |
11 | =head1 SYNOPSIS |
12 | |
12 | |
13 | urxvt --background-expr 'background expression' |
13 | urxvt --background-expr 'background expression' |
14 | --background-border |
14 | --background-border |
15 | --background-interval seconds |
15 | --background-interval seconds |
|
|
16 | |
|
|
17 | =head1 QUICK AND DIRTY CHEAT SHEET |
|
|
18 | |
|
|
19 | Just load a random jpeg image and tile the background with it without |
|
|
20 | scaling or anything else: |
|
|
21 | |
|
|
22 | load "/path/to/img.jpg" |
|
|
23 | |
|
|
24 | The same, but use mirroring/reflection instead of tiling: |
|
|
25 | |
|
|
26 | mirror load "/path/to/img.jpg" |
|
|
27 | |
|
|
28 | Load an image and scale it to exactly fill the terminal window: |
|
|
29 | |
|
|
30 | scale keep { load "/path/to/img.jpg" } |
|
|
31 | |
|
|
32 | Implement pseudo-transparency by using a suitably-aligned root pixmap |
|
|
33 | as window background: |
|
|
34 | |
|
|
35 | rootalign root |
|
|
36 | |
|
|
37 | Likewise, but keep a blurred copy: |
|
|
38 | |
|
|
39 | rootalign keep { blur 10, root } |
16 | |
40 | |
17 | =head1 DESCRIPTION |
41 | =head1 DESCRIPTION |
18 | |
42 | |
19 | This extension manages the terminal background by creating a picture that |
43 | This extension manages the terminal background by creating a picture that |
20 | is behind the text, replacing the normal background colour. |
44 | is behind the text, replacing the normal background colour. |
… | |
… | |
284 | |
308 | |
285 | Loads the image at the given C<$path>. The image is set to plane tiling |
309 | Loads the image at the given C<$path>. The image is set to plane tiling |
286 | mode. |
310 | mode. |
287 | |
311 | |
288 | If the image is already in memory (e.g. because another terminal instance |
312 | If the image is already in memory (e.g. because another terminal instance |
289 | uses it), then the in-memory copy us returned instead. |
313 | uses it), then the in-memory copy is returned instead. |
290 | |
314 | |
291 | =item load_uc $path |
315 | =item load_uc $path |
292 | |
316 | |
293 | Load uncached - same as load, but does not cache the image, which means it |
317 | Load uncached - same as load, but does not cache the image, which means it |
294 | is I<always> loaded from the filesystem again, even if another copy of it |
318 | is I<always> loaded from the filesystem again, even if another copy of it |
… | |
… | |
398 | for @_; |
422 | for @_; |
399 | |
423 | |
400 | $base |
424 | $base |
401 | } |
425 | } |
402 | |
426 | |
|
|
427 | =back |
|
|
428 | |
403 | =head2 TILING MODES |
429 | =head2 TILING MODES |
404 | |
430 | |
405 | The following operators modify the tiling mode of an image, that is, the |
431 | The following operators modify the tiling mode of an image, that is, the |
406 | way that pixels outside the image area are painted when the image is used. |
432 | way that pixels outside the image area are painted when the image is used. |
407 | |
433 | |
… | |
… | |
509 | |
535 | |
510 | move -TX, -TY, keep { load "mybg.png" } |
536 | move -TX, -TY, keep { load "mybg.png" } |
511 | |
537 | |
512 | =item TW |
538 | =item TW |
513 | |
539 | |
|
|
540 | =item TH |
|
|
541 | |
514 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
542 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
515 | terminal window is the full window by default, and the character area only |
543 | terminal window is the full window by default, and the character area only |
516 | when in border-respect mode). |
544 | when in border-respect mode). |
517 | |
545 | |
518 | Using these functions make your expression sensitive to window resizes. |
546 | Using these functions make your expression sensitive to window resizes. |
… | |
… | |
585 | Clips an image to the given rectangle. If the rectangle is outside the |
613 | Clips an image to the given rectangle. If the rectangle is outside the |
586 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
614 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
587 | larger than the image, then the tiling mode defines how the extra pixels |
615 | larger than the image, then the tiling mode defines how the extra pixels |
588 | will be filled. |
616 | will be filled. |
589 | |
617 | |
590 | If C<$x> an C<$y> are missing, then C<0> is assumed for both. |
618 | If C<$x> and C<$y> are missing, then C<0> is assumed for both. |
591 | |
619 | |
592 | If C<$width> and C<$height> are missing, then the window size will be |
620 | If C<$width> and C<$height> are missing, then the window size will be |
593 | assumed. |
621 | assumed. |
594 | |
622 | |
595 | Example: load an image, blur it, and clip it to the window size to save |
623 | Example: load an image, blur it, and clip it to the window size to save |
… | |
… | |
613 | =item scale $width_factor, $height_factor, $img |
641 | =item scale $width_factor, $height_factor, $img |
614 | |
642 | |
615 | Scales the image by the given factors in horizontal |
643 | Scales the image by the given factors in horizontal |
616 | (C<$width>) and vertical (C<$height>) direction. |
644 | (C<$width>) and vertical (C<$height>) direction. |
617 | |
645 | |
618 | If only one factor is give, it is used for both directions. |
646 | If only one factor is given, it is used for both directions. |
619 | |
647 | |
620 | If no factors are given, scales the image to the window size without |
648 | If no factors are given, scales the image to the window size without |
621 | keeping aspect. |
649 | keeping aspect. |
622 | |
650 | |
623 | =item resize $width, $height, $img |
651 | =item resize $width, $height, $img |
… | |
… | |
748 | =item rotate $center_x, $center_y, $degrees, $img |
776 | =item rotate $center_x, $center_y, $degrees, $img |
749 | |
777 | |
750 | Rotates the image clockwise by C<$degrees> degrees, around the point at |
778 | Rotates the image clockwise by C<$degrees> degrees, around the point at |
751 | C<$center_x> and C<$center_y> (specified as factor of image width/height). |
779 | C<$center_x> and C<$center_y> (specified as factor of image width/height). |
752 | |
780 | |
753 | Example: rotate the image by 90 degrees around it's center. |
781 | Example: rotate the image by 90 degrees around its center. |
754 | |
782 | |
755 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
783 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
756 | |
784 | |
757 | =cut |
785 | =cut |
758 | |
786 | |
… | |
… | |
789 | |
817 | |
790 | sub tint($$) { |
818 | sub tint($$) { |
791 | $_[1]->tint ($_[0]) |
819 | $_[1]->tint ($_[0]) |
792 | } |
820 | } |
793 | |
821 | |
|
|
822 | =item shade $factor, $img |
|
|
823 | |
|
|
824 | Shade the image by the given factor. |
|
|
825 | |
|
|
826 | =cut |
|
|
827 | |
|
|
828 | sub shade($$) { |
|
|
829 | $_[1]->shade ($_[0]) |
|
|
830 | } |
|
|
831 | |
794 | =item contrast $factor, $img |
832 | =item contrast $factor, $img |
795 | |
833 | |
796 | =item contrast $r, $g, $b, $img |
834 | =item contrast $r, $g, $b, $img |
797 | |
835 | |
798 | =item contrast $r, $g, $b, $a, $img |
836 | =item contrast $r, $g, $b, $a, $img |
… | |
… | |
827 | latter in a white picture. |
865 | latter in a white picture. |
828 | |
866 | |
829 | Due to idiosyncrasies in the underlying XRender extension, biases less |
867 | Due to idiosyncrasies in the underlying XRender extension, biases less |
830 | than zero can be I<very> slow. |
868 | than zero can be I<very> slow. |
831 | |
869 | |
|
|
870 | You can also try the experimental(!) C<muladd> operator. |
|
|
871 | |
832 | =cut |
872 | =cut |
833 | |
873 | |
834 | sub contrast($$;$$;$) { |
874 | sub contrast($$;$$;$) { |
835 | my $img = pop; |
875 | my $img = pop; |
836 | my ($r, $g, $b, $a) = @_; |
876 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
851 | $a = 1 if @_ < 4; |
891 | $a = 1 if @_ < 4; |
852 | |
892 | |
853 | $img = $img->clone; |
893 | $img = $img->clone; |
854 | $img->brightness ($r, $g, $b, $a); |
894 | $img->brightness ($r, $g, $b, $a); |
855 | $img |
895 | $img |
|
|
896 | } |
|
|
897 | |
|
|
898 | =item muladd $mul, $add, $img # EXPERIMENTAL |
|
|
899 | |
|
|
900 | First multiplies the pixels by C<$mul>, then adds C<$add>. This can be used |
|
|
901 | to implement brightness and contrast at the same time, with a wider value |
|
|
902 | range than contrast and brightness operators. |
|
|
903 | |
|
|
904 | Due to numerous bugs in XRender implementations, it can also introduce a |
|
|
905 | number of visual artifacts. |
|
|
906 | |
|
|
907 | Example: increase contrast by a factor of C<$c> without changing image |
|
|
908 | brightness too much. |
|
|
909 | |
|
|
910 | muladd $c, (1 - $c) * 0.5, $img |
|
|
911 | |
|
|
912 | =cut |
|
|
913 | |
|
|
914 | sub muladd($$$) { |
|
|
915 | $_[2]->muladd ($_[0], $_[1]) |
856 | } |
916 | } |
857 | |
917 | |
858 | =item blur $radius, $img |
918 | =item blur $radius, $img |
859 | |
919 | |
860 | =item blur $radius_horz, $radius_vert, $img |
920 | =item blur $radius_horz, $radius_vert, $img |
… | |
… | |
967 | |
1027 | |
968 | # compiles a parsed expression |
1028 | # compiles a parsed expression |
969 | sub set_expr { |
1029 | sub set_expr { |
970 | my ($self, $expr) = @_; |
1030 | my ($self, $expr) = @_; |
971 | |
1031 | |
972 | $self->{root} = []; |
1032 | $self->{root} = []; # the outermost frame |
973 | $self->{expr} = $expr; |
1033 | $self->{expr} = $expr; |
974 | $self->recalculate; |
1034 | $self->recalculate; |
975 | } |
1035 | } |
976 | |
1036 | |
977 | # takes a hash of sensitivity indicators and installs watchers |
1037 | # takes a hash of sensitivity indicators and installs watchers |
… | |
… | |
1039 | |
1099 | |
1040 | # set environment to evaluate user expression |
1100 | # set environment to evaluate user expression |
1041 | |
1101 | |
1042 | local $self = $arg_self; |
1102 | local $self = $arg_self; |
1043 | local $HOME = $ENV{HOME}; |
1103 | local $HOME = $ENV{HOME}; |
1044 | local $frame = []; |
1104 | local $frame = $self->{root}; |
1045 | |
1105 | |
1046 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
1106 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
1047 | |
1107 | |
1048 | # evaluate user expression |
1108 | # evaluate user expression |
1049 | |
1109 | |