… | |
… | |
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. |
… | |
… | |
74 | return load "$HOME/sunday.png"; |
98 | return load "$HOME/sunday.png"; |
75 | } |
99 | } |
76 | } |
100 | } |
77 | |
101 | |
78 | This inner expression is evaluated once per hour (and whenever the |
102 | This inner expression is evaluated once per hour (and whenever the |
79 | temrinal window is resized). It sets F<sunday.png> as background on |
103 | terminal window is resized). It sets F<sunday.png> as background on |
80 | Sundays, and F<weekday.png> on all other days. |
104 | Sundays, and F<weekday.png> on all other days. |
81 | |
105 | |
82 | Fortunately, we expect that most expressions will be much simpler, with |
106 | Fortunately, we expect that most expressions will be much simpler, with |
83 | little Perl knowledge needed. |
107 | little Perl knowledge needed. |
84 | |
108 | |
… | |
… | |
119 | width and doubles the image height: |
143 | width and doubles the image height: |
120 | |
144 | |
121 | scale 0.5, 2, load "$HOME/mypic.png" |
145 | scale 0.5, 2, load "$HOME/mypic.png" |
122 | |
146 | |
123 | IF you try out these expressions, you might suffer from some sluggishness, |
147 | IF you try out these expressions, you might suffer from some sluggishness, |
124 | because each time the terminal is resized, it loads the PNG image agin |
148 | because each time the terminal is resized, it loads the PNG image again |
125 | and scales it. Scaling is usually fast (and unavoidable), but loading the |
149 | and scales it. Scaling is usually fast (and unavoidable), but loading the |
126 | image can be quite time consuming. This is where C<keep> comes in handy: |
150 | image can be quite time consuming. This is where C<keep> comes in handy: |
127 | |
151 | |
128 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
152 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
129 | |
153 | |
… | |
… | |
156 | |
180 | |
157 | This one first takes a snapshot of the screen background image, and then |
181 | This one first takes a snapshot of the screen background image, and then |
158 | moves it to the upper left corner of the screen (as opposed to the upper |
182 | moves it to the upper left corner of the screen (as opposed to the upper |
159 | left corner of the terminal window)- the result is pseudo-transparency: |
183 | left corner of the terminal window)- the result is pseudo-transparency: |
160 | the image seems to be static while the window is moved around. |
184 | the image seems to be static while the window is moved around. |
|
|
185 | |
|
|
186 | =head2 COLOUR SPECIFICATIONS |
|
|
187 | |
|
|
188 | Whenever an operator expects a "colour", then this can be specified in one |
|
|
189 | of two ways: Either as string with an X11 colour specification, such as: |
|
|
190 | |
|
|
191 | "red" # named colour |
|
|
192 | "#f00" # simple rgb |
|
|
193 | "[50]red" # red with 50% alpha |
|
|
194 | "TekHVC:300/50/50" # anything goes |
|
|
195 | |
|
|
196 | OR as an array reference with one, three or four components: |
|
|
197 | |
|
|
198 | [0.5] # 50% gray, 100% alpha |
|
|
199 | [0.5, 0, 0] # dark red, no green or blur, 100% alpha |
|
|
200 | [0.5, 0, 0, 0.7] # same with explicit 70% alpha |
161 | |
201 | |
162 | =head2 CACHING AND SENSITIVITY |
202 | =head2 CACHING AND SENSITIVITY |
163 | |
203 | |
164 | Since some operations (such as C<load> and C<blur>) can take a long time, |
204 | Since some operations (such as C<load> and C<blur>) can take a long time, |
165 | caching results can be very important for a smooth operation. Caching can |
205 | caching results can be very important for a smooth operation. Caching can |
… | |
… | |
273 | uses it), then the in-memory copy us returned instead. |
313 | uses it), then the in-memory copy us returned instead. |
274 | |
314 | |
275 | =item load_uc $path |
315 | =item load_uc $path |
276 | |
316 | |
277 | 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 |
278 | is I<always> loaded from the filesystem again. |
318 | is I<always> loaded from the filesystem again, even if another copy of it |
|
|
319 | is in memory at the time. |
279 | |
320 | |
280 | =cut |
321 | =cut |
281 | |
322 | |
282 | sub load_uc($) { |
323 | sub load_uc($) { |
283 | $self->new_img_from_file ($path) |
324 | $self->new_img_from_file ($_[0]) |
284 | } |
325 | } |
285 | |
326 | |
286 | sub load($) { |
327 | sub load($) { |
287 | my ($path) = @_; |
328 | my ($path) = @_; |
288 | |
329 | |
… | |
… | |
381 | for @_; |
422 | for @_; |
382 | |
423 | |
383 | $base |
424 | $base |
384 | } |
425 | } |
385 | |
426 | |
|
|
427 | =back |
|
|
428 | |
386 | =head2 TILING MODES |
429 | =head2 TILING MODES |
387 | |
430 | |
388 | 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 |
389 | 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. |
390 | |
433 | |
… | |
… | |
492 | |
535 | |
493 | move -TX, -TY, keep { load "mybg.png" } |
536 | move -TX, -TY, keep { load "mybg.png" } |
494 | |
537 | |
495 | =item TW |
538 | =item TW |
496 | |
539 | |
|
|
540 | =item TH |
|
|
541 | |
497 | 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 |
498 | 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 |
499 | when in border-respect mode). |
544 | when in border-respect mode). |
500 | |
545 | |
501 | Using these functions make your expression sensitive to window resizes. |
546 | Using these functions make your expression sensitive to window resizes. |
… | |
… | |
568 | 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 |
569 | 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 |
570 | 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 |
571 | will be filled. |
616 | will be filled. |
572 | |
617 | |
573 | 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. |
574 | |
619 | |
575 | 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 |
576 | assumed. |
621 | assumed. |
577 | |
622 | |
578 | 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 |
… | |
… | |
596 | =item scale $width_factor, $height_factor, $img |
641 | =item scale $width_factor, $height_factor, $img |
597 | |
642 | |
598 | Scales the image by the given factors in horizontal |
643 | Scales the image by the given factors in horizontal |
599 | (C<$width>) and vertical (C<$height>) direction. |
644 | (C<$width>) and vertical (C<$height>) direction. |
600 | |
645 | |
601 | 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. |
602 | |
647 | |
603 | 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 |
604 | keeping aspect. |
649 | keeping aspect. |
605 | |
650 | |
606 | =item resize $width, $height, $img |
651 | =item resize $width, $height, $img |
… | |
… | |
731 | =item rotate $center_x, $center_y, $degrees, $img |
776 | =item rotate $center_x, $center_y, $degrees, $img |
732 | |
777 | |
733 | 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 |
734 | 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). |
735 | |
780 | |
736 | Example: rotate the image by 90 degrees around it's center. |
781 | Example: rotate the image by 90 degrees around its center. |
737 | |
782 | |
738 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
783 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
739 | |
784 | |
740 | =cut |
785 | =cut |
741 | |
786 | |
… | |
… | |
754 | |
799 | |
755 | The following operators change the pixels of the image. |
800 | The following operators change the pixels of the image. |
756 | |
801 | |
757 | =over 4 |
802 | =over 4 |
758 | |
803 | |
|
|
804 | =item tint $color, $img |
|
|
805 | |
|
|
806 | Tints the image in the given colour. |
|
|
807 | |
|
|
808 | Example: tint the image red. |
|
|
809 | |
|
|
810 | tint "red", load "rgb.png" |
|
|
811 | |
|
|
812 | Example: the same, but specify the colour by component. |
|
|
813 | |
|
|
814 | tint [1, 0, 0], load "rgb.png" |
|
|
815 | |
|
|
816 | =cut |
|
|
817 | |
|
|
818 | sub tint($$) { |
|
|
819 | $_[1]->tint ($_[0]) |
|
|
820 | } |
|
|
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 | |
759 | =item contrast $factor, $img |
832 | =item contrast $factor, $img |
760 | |
833 | |
761 | =item contrast $r, $g, $b, $img |
834 | =item contrast $r, $g, $b, $img |
762 | |
835 | |
763 | =item contrast $r, $g, $b, $a, $img |
836 | =item contrast $r, $g, $b, $a, $img |
… | |
… | |
792 | latter in a white picture. |
865 | latter in a white picture. |
793 | |
866 | |
794 | Due to idiosyncrasies in the underlying XRender extension, biases less |
867 | Due to idiosyncrasies in the underlying XRender extension, biases less |
795 | than zero can be I<very> slow. |
868 | than zero can be I<very> slow. |
796 | |
869 | |
|
|
870 | You can also try the experimental(!) C<muladd> operator. |
|
|
871 | |
797 | =cut |
872 | =cut |
798 | |
873 | |
799 | sub contrast($$;$$;$) { |
874 | sub contrast($$;$$;$) { |
800 | my $img = pop; |
875 | my $img = pop; |
801 | my ($r, $g, $b, $a) = @_; |
876 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
816 | $a = 1 if @_ < 4; |
891 | $a = 1 if @_ < 4; |
817 | |
892 | |
818 | $img = $img->clone; |
893 | $img = $img->clone; |
819 | $img->brightness ($r, $g, $b, $a); |
894 | $img->brightness ($r, $g, $b, $a); |
820 | $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]) |
821 | } |
916 | } |
822 | |
917 | |
823 | =item blur $radius, $img |
918 | =item blur $radius, $img |
824 | |
919 | |
825 | =item blur $radius_horz, $radius_vert, $img |
920 | =item blur $radius_horz, $radius_vert, $img |
… | |
… | |
870 | C<keep> block so it only is reevaluated as required. |
965 | C<keep> block so it only is reevaluated as required. |
871 | |
966 | |
872 | Putting the blur into a C<keep> block will make sure the blur is only done |
967 | Putting the blur into a C<keep> block will make sure the blur is only done |
873 | once, while the C<rootalign> is still done each time the window moves. |
968 | once, while the C<rootalign> is still done each time the window moves. |
874 | |
969 | |
875 | rootlign keep { blur 10, root } |
970 | rootalign keep { blur 10, root } |
876 | |
971 | |
877 | This leaves the question of how to force reevaluation of the block, |
972 | This leaves the question of how to force reevaluation of the block, |
878 | in case the root background changes: If expression inside the block |
973 | in case the root background changes: If expression inside the block |
879 | is sensitive to some event (root background changes, window geometry |
974 | is sensitive to some event (root background changes, window geometry |
880 | changes), then it will be reevaluated automatically as needed. |
975 | changes), then it will be reevaluated automatically as needed. |
… | |
… | |
932 | |
1027 | |
933 | # compiles a parsed expression |
1028 | # compiles a parsed expression |
934 | sub set_expr { |
1029 | sub set_expr { |
935 | my ($self, $expr) = @_; |
1030 | my ($self, $expr) = @_; |
936 | |
1031 | |
937 | $self->{root} = []; |
1032 | $self->{root} = []; # the outermost frame |
938 | $self->{expr} = $expr; |
1033 | $self->{expr} = $expr; |
939 | $self->recalculate; |
1034 | $self->recalculate; |
940 | } |
1035 | } |
941 | |
1036 | |
942 | # takes a hash of sensitivity indicators and installs watchers |
1037 | # takes a hash of sensitivity indicators and installs watchers |
… | |
… | |
1004 | |
1099 | |
1005 | # set environment to evaluate user expression |
1100 | # set environment to evaluate user expression |
1006 | |
1101 | |
1007 | local $self = $arg_self; |
1102 | local $self = $arg_self; |
1008 | local $HOME = $ENV{HOME}; |
1103 | local $HOME = $ENV{HOME}; |
1009 | local $frame = []; |
1104 | local $frame = $self->{root}; |
1010 | |
1105 | |
1011 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
1106 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
1012 | |
1107 | |
1013 | # evaluate user expression |
1108 | # evaluate user expression |
1014 | |
1109 | |