1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
3 | #:META:RESOURCE:%.expr:string:background expression |
4 | #:META:X_RESOURCE:%.border:boolean:respect the terminal border |
4 | #:META:RESOURCE:%.border:boolean:respect the terminal border |
5 | #:META:X_RESOURCE:%.interval:seconds:minimum time between updates |
5 | #:META:RESOURCE:%.interval:seconds:minimum time between updates |
|
|
6 | #:META:RESOURCE:pixmap:file[;geom]:set image as background |
|
|
7 | #:META:RESOURCE:backgroundPixmap:file[;geom]:set image as background |
|
|
8 | #:META:RESOURCE:tr:boolean:set root pixmap as background |
|
|
9 | #:META:RESOURCE:transparent:boolean:set root pixmap as background |
|
|
10 | #:META:RESOURCE:tint:color:tint background with color |
|
|
11 | #:META:RESOURCE:tintColor:color:tint background with color |
|
|
12 | #:META:RESOURCE:sh:number:shade background by number % |
|
|
13 | #:META:RESOURCE:shading:number:shade background by number % |
|
|
14 | #:META:RESOURCE:blr:HxV:gaussian-blur background with radii |
|
|
15 | #:META:RESOURCE:blurRadius:HxV:gaussian-blur background with radii |
|
|
16 | #:META:OSC:20:change/query background image |
|
|
17 | #:META:OSC:705:change transparent background tint colour |
6 | |
18 | |
7 | =head1 NAME |
19 | =head1 NAME |
8 | |
20 | |
9 | background - manage terminal background |
21 | background - manage terminal background |
10 | |
22 | |
… | |
… | |
14 | --background-border |
26 | --background-border |
15 | --background-interval seconds |
27 | --background-interval seconds |
16 | |
28 | |
17 | =head1 QUICK AND DIRTY CHEAT SHEET |
29 | =head1 QUICK AND DIRTY CHEAT SHEET |
18 | |
30 | |
19 | Just load a random jpeg image and tile the background with it without |
31 | Load a random jpeg image and tile the background with it without scaling |
20 | scaling or anything else: |
32 | or anything else: |
21 | |
33 | |
22 | load "/path/to/img.jpg" |
34 | load "/path/to/img.jpg" |
23 | |
35 | |
24 | The same, but use mirroring/reflection instead of tiling: |
36 | The same, but use mirroring/reflection instead of tiling: |
25 | |
37 | |
… | |
… | |
44 | is behind the text, replacing the normal background colour. |
56 | is behind the text, replacing the normal background colour. |
45 | |
57 | |
46 | It does so by evaluating a Perl expression that I<calculates> the image on |
58 | It does so by evaluating a Perl expression that I<calculates> the image on |
47 | the fly, for example, by grabbing the root background or loading a file. |
59 | the fly, for example, by grabbing the root background or loading a file. |
48 | |
60 | |
49 | While the full power of Perl is available, the operators have been design |
61 | While the full power of Perl is available, the operators have been |
50 | to be as simple as possible. |
62 | designed to be as simple as possible. |
51 | |
63 | |
52 | For example, to load an image and scale it to the window size, you would |
64 | For example, to load an image and scale it to the window size, you would |
53 | use: |
65 | use: |
54 | |
66 | |
55 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
67 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
56 | |
68 | |
57 | Or specified as a X resource: |
69 | Or specified as a X resource: |
58 | |
70 | |
59 | URxvt.background-expr: scale keep { load "/path/to/mybg.png" } |
71 | URxvt.background.expr: scale keep { load "/path/to/mybg.png" } |
60 | |
72 | |
61 | =head1 THEORY OF OPERATION |
73 | =head1 THEORY OF OPERATION |
62 | |
74 | |
63 | At startup, just before the window is mapped for the first time, the |
75 | At startup, just before the window is mapped for the first time, the |
64 | expression is evaluated and must yield an image. The image is then |
76 | expression is evaluated and must yield an image. The image is then |
… | |
… | |
132 | get a percentage): |
144 | get a percentage): |
133 | |
145 | |
134 | scale 2, load "$HOME/mypic.png" |
146 | scale 2, load "$HOME/mypic.png" |
135 | |
147 | |
136 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
148 | This enlarges the image by a factor of 2 (200%). As you can see, C<scale> |
137 | has now two arguments, the C<200> and the C<load> expression, while |
149 | has now two arguments, the C<2> and the C<load> expression, while |
138 | C<load> only has one argument. Arguments are separated from each other by |
150 | C<load> only has one argument. Arguments are separated from each other by |
139 | commas. |
151 | commas. |
140 | |
152 | |
141 | Scale also accepts two arguments, which are then separate factors for both |
153 | Scale also accepts two arguments, which are then separate factors for both |
142 | horizontal and vertical dimensions. For example, this halves the image |
154 | horizontal and vertical dimensions. For example, this halves the image |
… | |
… | |
249 | |
261 | |
250 | =head1 REFERENCE |
262 | =head1 REFERENCE |
251 | |
263 | |
252 | =head2 COMMAND LINE SWITCHES |
264 | =head2 COMMAND LINE SWITCHES |
253 | |
265 | |
254 | =over 4 |
266 | =over |
255 | |
267 | |
256 | =item --background-expr perl-expression |
268 | =item --background-expr perl-expression |
257 | |
269 | |
258 | Specifies the Perl expression to evaluate. |
270 | Specifies the Perl expression to evaluate. |
259 | |
271 | |
… | |
… | |
300 | |
312 | |
301 | These functions provide an image, by loading it from disk, grabbing it |
313 | These functions provide an image, by loading it from disk, grabbing it |
302 | from the root screen or by simply generating it. They are used as starting |
314 | from the root screen or by simply generating it. They are used as starting |
303 | points to get an image you can play with. |
315 | points to get an image you can play with. |
304 | |
316 | |
305 | =over 4 |
317 | =over |
306 | |
318 | |
307 | =item load $path |
319 | =item load $path |
308 | |
320 | |
309 | Loads the image at the given C<$path>. The image is set to plane tiling |
321 | Loads the image at the given C<$path>. The image is set to plane tiling |
310 | mode. |
322 | mode. |
… | |
… | |
429 | =head2 TILING MODES |
441 | =head2 TILING MODES |
430 | |
442 | |
431 | The following operators modify the tiling mode of an image, that is, the |
443 | The following operators modify the tiling mode of an image, that is, the |
432 | way that pixels outside the image area are painted when the image is used. |
444 | way that pixels outside the image area are painted when the image is used. |
433 | |
445 | |
434 | =over 4 |
446 | =over |
435 | |
447 | |
436 | =item tile $img |
448 | =item tile $img |
437 | |
449 | |
438 | Tiles the whole plane with the image and returns this new image - or in |
450 | Tiles the whole plane with the image and returns this new image - or in |
439 | other words, it returns a copy of the image in plane tiling mode. |
451 | other words, it returns a copy of the image in plane tiling mode. |
… | |
… | |
514 | dimensions. They are not (Perl-) variables, they just return stuff that |
526 | dimensions. They are not (Perl-) variables, they just return stuff that |
515 | varies. Most of them make your expression sensitive to some events, for |
527 | varies. Most of them make your expression sensitive to some events, for |
516 | example using C<TW> (terminal width) means your expression is evaluated |
528 | example using C<TW> (terminal width) means your expression is evaluated |
517 | again when the terminal is resized. |
529 | again when the terminal is resized. |
518 | |
530 | |
519 | =over 4 |
531 | =over |
520 | |
532 | |
521 | =item TX |
533 | =item TX |
522 | |
534 | |
523 | =item TY |
535 | =item TY |
524 | |
536 | |
… | |
… | |
562 | |
574 | |
563 | A common use case is to fade the background image when the terminal loses |
575 | A common use case is to fade the background image when the terminal loses |
564 | focus, often together with the C<-fade> command line option. In fact, |
576 | focus, often together with the C<-fade> command line option. In fact, |
565 | there is a special function for just that use case: C<focus_fade>. |
577 | there is a special function for just that use case: C<focus_fade>. |
566 | |
578 | |
567 | Example: use two entirely different bacckground images, depending on |
579 | Example: use two entirely different background images, depending on |
568 | whether the window has focus. |
580 | whether the window has focus. |
569 | |
581 | |
570 | FOCUS ? keep { load "has_focus.jpg" } : keep { load "no_focus.jpg" } |
582 | FOCUS ? keep { load "has_focus.jpg" } : keep { load "no_focus.jpg" } |
571 | |
583 | |
572 | =cut |
584 | =cut |
… | |
… | |
617 | |
629 | |
618 | =head2 SHAPE CHANGING OPERATORS |
630 | =head2 SHAPE CHANGING OPERATORS |
619 | |
631 | |
620 | The following operators modify the shape, size or position of the image. |
632 | The following operators modify the shape, size or position of the image. |
621 | |
633 | |
622 | =over 4 |
634 | =over |
623 | |
635 | |
624 | =item clip $img |
636 | =item clip $img |
625 | |
637 | |
626 | =item clip $width, $height, $img |
638 | =item clip $width, $height, $img |
627 | |
639 | |
… | |
… | |
814 | |
826 | |
815 | =head2 COLOUR MODIFICATIONS |
827 | =head2 COLOUR MODIFICATIONS |
816 | |
828 | |
817 | The following operators change the pixels of the image. |
829 | The following operators change the pixels of the image. |
818 | |
830 | |
819 | =over 4 |
831 | =over |
820 | |
832 | |
821 | =item tint $color, $img |
833 | =item tint $color, $img |
822 | |
834 | |
823 | Tints the image in the given colour. |
835 | Tints the image in the given colour. |
824 | |
836 | |
… | |
… | |
956 | =item focus_fade $factor, $img |
968 | =item focus_fade $factor, $img |
957 | |
969 | |
958 | =item focus_fade $factor, $color, $img |
970 | =item focus_fade $factor, $color, $img |
959 | |
971 | |
960 | Fades the image by the given factor (and colour) when focus is lost (the |
972 | Fades the image by the given factor (and colour) when focus is lost (the |
961 | same as the C<-fade>/C<-fadecolo> command line options, which also supply |
973 | same as the C<-fade>/C<-fadecolor> command line options, which also supply |
962 | the default values for C<factor> and C<$color>. Unlike with C<-fade>, the |
974 | the default values for C<factor> and C<$color>. Unlike with C<-fade>, the |
963 | C<$factor> is the real value, not a percentage value (that is, 0..1, not |
975 | C<$factor> is a real value, not a percentage value (that is, 0..1, not |
964 | 0..100). |
976 | 0..100). |
965 | |
977 | |
966 | Example: do the right thing when focus fading is requested. |
978 | Example: do the right thing when focus fading is requested. |
967 | |
979 | |
968 | focus_fade load "mybg.jpg"; |
980 | focus_fade load "mybg.jpg"; |
… | |
… | |
974 | |
986 | |
975 | return $img |
987 | return $img |
976 | if FOCUS; |
988 | if FOCUS; |
977 | |
989 | |
978 | my $fade = @_ >= 1 ? $_[0] : defined $self->resource ("fade") ? $self->resource ("fade") * 0.01 : 0; |
990 | my $fade = @_ >= 1 ? $_[0] : defined $self->resource ("fade") ? $self->resource ("fade") * 0.01 : 0; |
979 | my $color = @_ >= 2 ? $_[1] : $self->resource ("color+" . urxvt::Color_fade); |
991 | my $color = @_ >= 2 ? $_[1] : $self->resource ("color+" . &urxvt::Color_fade ()); # Color_fade not always available |
980 | |
992 | |
981 | $img = $img->tint ($color) if $color ne "rgb:00/00/00"; |
993 | $img = $img->tint ($color) if $color ne "rgb:00/00/00"; |
982 | $img = $img->muladd (1 - $fade, 0) if $fade; |
994 | $img = $img->muladd (1 - $fade, 0) if $fade; |
983 | |
995 | |
984 | $img |
996 | $img |
… | |
… | |
989 | =head2 OTHER STUFF |
1001 | =head2 OTHER STUFF |
990 | |
1002 | |
991 | Anything that didn't fit any of the other categories, even after applying |
1003 | Anything that didn't fit any of the other categories, even after applying |
992 | force and closing our eyes. |
1004 | force and closing our eyes. |
993 | |
1005 | |
994 | =over 4 |
1006 | =over |
995 | |
1007 | |
996 | =item keep { ... } |
1008 | =item keep { ... } |
997 | |
1009 | |
998 | This operator takes a code block as argument, that is, one or more |
1010 | This operator takes a code block as argument, that is, one or more |
999 | statements enclosed by braces. |
1011 | statements enclosed by braces. |
… | |
… | |
1021 | |
1033 | |
1022 | This leaves the question of how to force reevaluation of the block, |
1034 | This leaves the question of how to force reevaluation of the block, |
1023 | in case the root background changes: If expression inside the block |
1035 | in case the root background changes: If expression inside the block |
1024 | is sensitive to some event (root background changes, window geometry |
1036 | is sensitive to some event (root background changes, window geometry |
1025 | changes), then it will be reevaluated automatically as needed. |
1037 | changes), then it will be reevaluated automatically as needed. |
|
|
1038 | |
|
|
1039 | =back |
|
|
1040 | |
|
|
1041 | =head1 OLD BACKGROUND IMAGE SETTINGS |
|
|
1042 | |
|
|
1043 | This extension also provides support for the old options/resources and |
|
|
1044 | OSC sequences for setting a background image. These settings are |
|
|
1045 | B<deprecated> and will be removed in future versions. |
|
|
1046 | |
|
|
1047 | =head2 OPTIONS AND RESOURCES |
|
|
1048 | |
|
|
1049 | =over |
|
|
1050 | |
|
|
1051 | =item B<-pixmap> I<file[;oplist]> |
|
|
1052 | |
|
|
1053 | =item B<backgroundPixmap:> I<file[;oplist]> |
|
|
1054 | |
|
|
1055 | Use the specified image file as the window's background and also |
|
|
1056 | optionally specify a colon separated list of operations to modify it. |
|
|
1057 | Note that you may need to quote the C<;> character when using the |
|
|
1058 | command line option, as C<;> is usually a metacharacter in shells. |
|
|
1059 | Supported operations are: |
|
|
1060 | |
|
|
1061 | =over |
|
|
1062 | |
|
|
1063 | =item B<WxH+X+Y> |
|
|
1064 | |
|
|
1065 | sets scale and position. B<"W" / "H"> specify the horizontal/vertical |
|
|
1066 | scale (percent), and B<"X" / "Y"> locate the image centre (percent). A |
|
|
1067 | scale of 0 disables scaling. |
|
|
1068 | |
|
|
1069 | =item B<op=tile> |
|
|
1070 | |
|
|
1071 | enables tiling |
|
|
1072 | |
|
|
1073 | =item B<op=keep-aspect> |
|
|
1074 | |
|
|
1075 | maintain the image aspect ratio when scaling |
|
|
1076 | |
|
|
1077 | =item B<op=root-align> |
|
|
1078 | |
|
|
1079 | use the position of the terminal window relative to the root window as |
|
|
1080 | the image offset, simulating a root window background |
|
|
1081 | |
|
|
1082 | =back |
|
|
1083 | |
|
|
1084 | The default scale and position setting is C<100x100+50+50>. |
|
|
1085 | Alternatively, a predefined set of templates can be used to achieve |
|
|
1086 | the most common setups: |
|
|
1087 | |
|
|
1088 | =over |
|
|
1089 | |
|
|
1090 | =item B<style=tiled> |
|
|
1091 | |
|
|
1092 | the image is tiled with no scaling. Equivalent to 0x0+0+0:op=tile |
|
|
1093 | |
|
|
1094 | =item B<style=aspect-stretched> |
|
|
1095 | |
|
|
1096 | the image is scaled to fill the whole window maintaining the aspect |
|
|
1097 | ratio and centered. Equivalent to 100x100+50+50:op=keep-aspect |
|
|
1098 | |
|
|
1099 | =item B<style=stretched> |
|
|
1100 | |
|
|
1101 | the image is scaled to fill the whole window. Equivalent to 100x100 |
|
|
1102 | |
|
|
1103 | =item B<style=centered> |
|
|
1104 | |
|
|
1105 | the image is centered with no scaling. Equivalent to 0x0+50+50 |
|
|
1106 | |
|
|
1107 | =item B<style=root-tiled> |
|
|
1108 | |
|
|
1109 | the image is tiled with no scaling and using 'root' positioning. |
|
|
1110 | Equivalent to 0x0:op=tile:op=root-align |
|
|
1111 | |
|
|
1112 | =back |
|
|
1113 | |
|
|
1114 | If multiple templates are specified the last one wins. Note that a |
|
|
1115 | template overrides all the scale, position and operations settings. |
|
|
1116 | |
|
|
1117 | If used in conjunction with pseudo-transparency, the specified image |
|
|
1118 | will be blended over the transparent background using alpha-blending. |
|
|
1119 | |
|
|
1120 | =item B<-tr>|B<+tr> |
|
|
1121 | |
|
|
1122 | =item B<transparent:> I<boolean> |
|
|
1123 | |
|
|
1124 | Turn on/off pseudo-transparency by using the root pixmap as background. |
|
|
1125 | |
|
|
1126 | =item B<-tint> I<colour> |
|
|
1127 | |
|
|
1128 | =item B<tintColor:> I<colour> |
|
|
1129 | |
|
|
1130 | Tint the transparent background with the given colour. Note that a |
|
|
1131 | black tint yields a completely black image while a white tint yields |
|
|
1132 | the image unchanged. |
|
|
1133 | |
|
|
1134 | =item B<-sh> I<number> |
|
|
1135 | |
|
|
1136 | =item B<shading:> I<number> |
|
|
1137 | |
|
|
1138 | Darken (0 .. 99) or lighten (101 .. 200) the transparent background. |
|
|
1139 | A value of 100 means no shading. |
|
|
1140 | |
|
|
1141 | =item B<-blr> I<HxV> |
|
|
1142 | |
|
|
1143 | =item B<blurRadius:> I<HxV> |
|
|
1144 | |
|
|
1145 | Apply gaussian blur with the specified radius to the transparent |
|
|
1146 | background. If a single number is specified, the vertical and |
|
|
1147 | horizontal radii are considered to be the same. Setting one of the |
|
|
1148 | radii to 1 and the other to a large number creates interesting effects |
|
|
1149 | on some backgrounds. The maximum radius value is 128. An horizontal or |
|
|
1150 | vertical radius of 0 disables blurring. |
|
|
1151 | |
|
|
1152 | =back |
|
|
1153 | |
|
|
1154 | =head2 OSC sequences |
|
|
1155 | |
|
|
1156 | This extension will react to the following OSC sequences. Note that |
|
|
1157 | this extension will not be autoloaded when these are used currently, |
|
|
1158 | so to make urxvt recognize them, you have to enable the C<background> |
|
|
1159 | extension. One way to achieve that is to use the C<--background-expr ''> |
|
|
1160 | command line argument or by specifying an empty C<URxvt.background.expr:>> |
|
|
1161 | resource. |
|
|
1162 | |
|
|
1163 | =over |
|
|
1164 | |
|
|
1165 | =item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>. |
|
|
1166 | |
|
|
1167 | =item B<< C<ESC ] 20 ; Pt ST> >> Change/Query background image |
|
|
1168 | parameters: the value of B<< C<Pt> >> can be one of the following |
|
|
1169 | commands: |
|
|
1170 | |
|
|
1171 | =over |
|
|
1172 | |
|
|
1173 | =item B<< C<?> >> |
|
|
1174 | |
|
|
1175 | display scale and position in the title |
|
|
1176 | |
|
|
1177 | =item B<< C<;WxH+X+Y> >> |
|
|
1178 | |
|
|
1179 | change scale and/or position |
|
|
1180 | |
|
|
1181 | =item B<< C<FILE;WxH+X+Y> >> |
|
|
1182 | |
|
|
1183 | change background image |
|
|
1184 | |
|
|
1185 | =back |
1026 | |
1186 | |
1027 | =cut |
1187 | =cut |
1028 | |
1188 | |
1029 | sub keep(&) { |
1189 | sub keep(&) { |
1030 | my $id = $_[0]+0; |
1190 | my $id = $_[0]+0; |
… | |
… | |
1063 | =cut |
1223 | =cut |
1064 | |
1224 | |
1065 | } |
1225 | } |
1066 | |
1226 | |
1067 | sub parse_expr { |
1227 | sub parse_expr { |
|
|
1228 | my ($expr) = @_; |
|
|
1229 | |
|
|
1230 | # an empty expression is valid and represents the default background |
|
|
1231 | if ($expr !~ /\S/) { |
|
|
1232 | $expr = sub { |
|
|
1233 | undef |
|
|
1234 | }; |
|
|
1235 | } else { |
1068 | my $expr = eval |
1236 | $expr = eval |
1069 | "sub {\n" |
1237 | "sub {\n" |
1070 | . "package urxvt::bgdsl;\n" |
1238 | . "package urxvt::bgdsl;\n" |
1071 | . "#line 0 'background expression'\n" |
1239 | . "#line 0 'background expression'\n" |
1072 | . "$_[0]\n" |
1240 | . "$expr\n" |
1073 | . "}"; |
1241 | . "}"; |
1074 | die if $@; |
1242 | die if $@; |
|
|
1243 | } |
|
|
1244 | |
1075 | $expr |
1245 | $expr |
1076 | } |
1246 | } |
1077 | |
1247 | |
1078 | # compiles a parsed expression |
1248 | # compiles a parsed expression |
1079 | sub set_expr { |
1249 | sub set_expr { |
… | |
… | |
1151 | return; |
1321 | return; |
1152 | } |
1322 | } |
1153 | |
1323 | |
1154 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
1324 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
1155 | |
1325 | |
|
|
1326 | unless ($arg_self->has_render) { |
|
|
1327 | warn "background extension needs RENDER extension 0.11 or higher, ignoring background-expr.\n"; |
|
|
1328 | return; |
|
|
1329 | } |
|
|
1330 | |
1156 | # set environment to evaluate user expression |
1331 | # set environment to evaluate user expression |
1157 | |
1332 | |
1158 | local $self = $arg_self; |
1333 | local $self = $arg_self; |
1159 | local $HOME = $ENV{HOME}; |
1334 | local $HOME = $ENV{HOME}; |
1160 | local $frame = $self->{root}; |
1335 | local $frame = $self->{root}; |
… | |
… | |
1165 | # evaluate user expression |
1340 | # evaluate user expression |
1166 | |
1341 | |
1167 | my @img = eval { $self->{expr}->() }; |
1342 | my @img = eval { $self->{expr}->() }; |
1168 | die $@ if $@; |
1343 | die $@ if $@; |
1169 | die "background-expr did not return anything.\n" unless @img; |
1344 | die "background-expr did not return anything.\n" unless @img; |
|
|
1345 | |
|
|
1346 | if ($img[0]) { |
1170 | die "background-expr: expected image(s), got something else.\n" |
1347 | die "background-expr: expected image(s), got something else.\n" |
1171 | if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; |
1348 | if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; |
1172 | |
1349 | |
1173 | my $img = urxvt::bgdsl::merge @img; |
1350 | my $img = urxvt::bgdsl::merge @img; |
1174 | |
1351 | |
1175 | $frame->[FR_AGAIN]{size} = 1 |
1352 | $frame->[urxvt::bgdsl::FR_AGAIN]{size} = 1 |
1176 | if $img->repeat_mode != urxvt::RepeatNormal; |
1353 | if $img->repeat_mode != urxvt::RepeatNormal; |
1177 | |
1354 | |
1178 | # if the expression is sensitive to external events, prepare reevaluation then |
1355 | # if the expression is sensitive to external events, prepare reevaluation then |
1179 | $self->compile_frame ($frame, sub { $arg_self->recalculate }); |
1356 | $self->compile_frame ($frame, sub { $arg_self->recalculate }); |
1180 | |
1357 | |
1181 | # clear stuff we no longer need |
1358 | # clear stuff we no longer need |
1182 | |
1359 | |
1183 | # unless (%{ $frame->[FR_STATE] }) { |
1360 | # unless (%{ $frame->[FR_STATE] }) { |
1184 | # delete $self->{state}; |
1361 | # delete $self->{state}; |
1185 | # delete $self->{expr}; |
1362 | # delete $self->{expr}; |
1186 | # } |
1363 | # } |
1187 | |
1364 | |
1188 | # set background pixmap |
1365 | # set background pixmap |
1189 | |
1366 | |
1190 | $self->set_background ($img, $self->{border}); |
1367 | $self->set_background ($img, $self->{border}); |
|
|
1368 | } else { |
|
|
1369 | $self->clr_background; |
|
|
1370 | } |
|
|
1371 | |
1191 | $self->scr_recolour (0); |
1372 | $self->scr_recolor (0); |
1192 | $self->want_refresh; |
1373 | $self->want_refresh; |
1193 | } |
1374 | } |
1194 | |
1375 | |
|
|
1376 | sub old_bg_opts { |
|
|
1377 | my ($self, $arg) = @_; |
|
|
1378 | |
|
|
1379 | $arg or return; |
|
|
1380 | |
|
|
1381 | my @str = split /;/, $arg; |
|
|
1382 | |
|
|
1383 | return unless $str[0] or $self->{bg_opts}->{path}; |
|
|
1384 | |
|
|
1385 | my $bg_opts = $self->{bg_opts}; |
|
|
1386 | |
|
|
1387 | if ($str[0]) { |
|
|
1388 | $bg_opts->{tile} = 0; |
|
|
1389 | $bg_opts->{keep_aspect} = 0; |
|
|
1390 | $bg_opts->{root_align} = 0; |
|
|
1391 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
|
|
1392 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1393 | $bg_opts->{path} = $str[0]; |
|
|
1394 | } |
|
|
1395 | |
|
|
1396 | my @oplist = split /:/, $str[1]; |
|
|
1397 | |
|
|
1398 | for (@oplist) { |
|
|
1399 | if (/style=tiled/i) { |
|
|
1400 | $bg_opts->{tile} = 1; |
|
|
1401 | $bg_opts->{keep_aspect} = 0; |
|
|
1402 | $bg_opts->{root_align} = 0; |
|
|
1403 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0; |
|
|
1404 | $bg_opts->{h_align} = $bg_opts->{v_align} = 0; |
|
|
1405 | } elsif (/style=aspect-stretched/i) { |
|
|
1406 | $bg_opts->{tile} = 0; |
|
|
1407 | $bg_opts->{keep_aspect} = 1; |
|
|
1408 | $bg_opts->{root_align} = 0; |
|
|
1409 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
|
|
1410 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1411 | } elsif (/style=stretched/i) { |
|
|
1412 | $bg_opts->{tile} = 0; |
|
|
1413 | $bg_opts->{keep_aspect} = 0; |
|
|
1414 | $bg_opts->{root_align} = 0; |
|
|
1415 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
|
|
1416 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1417 | } elsif (/style=centered/i) { |
|
|
1418 | $bg_opts->{tile} = 0; |
|
|
1419 | $bg_opts->{keep_aspect} = 0; |
|
|
1420 | $bg_opts->{root_align} = 0; |
|
|
1421 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0; |
|
|
1422 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
|
|
1423 | } elsif (/style=root-tiled/i) { |
|
|
1424 | $bg_opts->{tile} = 1; |
|
|
1425 | $bg_opts->{keep_aspect} = 0; |
|
|
1426 | $bg_opts->{root_align} = 1; |
|
|
1427 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0; |
|
|
1428 | $bg_opts->{h_align} = $bg_opts->{v_align} = 0; |
|
|
1429 | } elsif (/op=tile/i) { |
|
|
1430 | $bg_opts->{tile} = 1; |
|
|
1431 | } elsif (/op=keep-aspect/i) { |
|
|
1432 | $bg_opts->{keep_aspect} = 1; |
|
|
1433 | } elsif (/op=root-align/i) { |
|
|
1434 | $bg_opts->{root_align} = 1; |
|
|
1435 | } elsif (/^ =? ([0-9]+)? (?:[xX] ([0-9]+))? ([+-][0-9]+)? ([+-][0-9]+)? $/x) { |
|
|
1436 | my ($w, $h, $x, $y) = ($1, $2, $3, $4); |
|
|
1437 | |
|
|
1438 | if ($str[0]) { |
|
|
1439 | $w = $h unless defined $w; |
|
|
1440 | $h = $w unless defined $h; |
|
|
1441 | $y = $x unless defined $y; |
|
|
1442 | } |
|
|
1443 | |
|
|
1444 | $bg_opts->{h_scale} = $w if defined $w; |
|
|
1445 | $bg_opts->{v_scale} = $h if defined $h; |
|
|
1446 | $bg_opts->{h_align} = $x if defined $x; |
|
|
1447 | $bg_opts->{v_align} = $y if defined $y; |
|
|
1448 | } |
|
|
1449 | } |
|
|
1450 | } |
|
|
1451 | |
|
|
1452 | # helper function, quote string as perl without allowing |
|
|
1453 | # any code execution or other shenanigans. |
|
|
1454 | sub q0 { |
|
|
1455 | "qq\x00\Q$_\E\x00" |
|
|
1456 | } |
|
|
1457 | |
|
|
1458 | sub old_bg_expr { |
|
|
1459 | my ($self) = @_; |
|
|
1460 | |
|
|
1461 | my $expr; |
|
|
1462 | |
|
|
1463 | my $bg_opts = $self->{bg_opts}; |
|
|
1464 | |
|
|
1465 | if ($bg_opts->{root} =~ /^\s*(?:true|yes|on|1)\s*$/i) { |
|
|
1466 | $expr .= "tile ("; |
|
|
1467 | |
|
|
1468 | my $shade = $bg_opts->{shade}; |
|
|
1469 | |
|
|
1470 | if ($shade) { |
|
|
1471 | $shade = List::Util::min $shade, 200; |
|
|
1472 | $shade = List::Util::max $shade, -100; |
|
|
1473 | $shade = 200 - (100 + $shade) if $shade < 0; |
|
|
1474 | |
|
|
1475 | $shade = $shade * 0.01 - 1; |
|
|
1476 | $expr .= "shade $shade, "; |
|
|
1477 | } |
|
|
1478 | |
|
|
1479 | my $tint = $bg_opts->{tint}; |
|
|
1480 | |
|
|
1481 | if ($tint) { |
|
|
1482 | $tint = q0 $tint; |
|
|
1483 | $expr .= "tint $tint,"; |
|
|
1484 | } |
|
|
1485 | |
|
|
1486 | my $blur = $bg_opts->{blur}; |
|
|
1487 | |
|
|
1488 | if ($blur and $blur =~ /^ =? ([0-9]+)? (?:[xX] ([0-9]+))? $/x) { |
|
|
1489 | my $hr = defined $1 ? $1 : 1; |
|
|
1490 | my $vr = defined $2 ? $2 : $hr; |
|
|
1491 | |
|
|
1492 | if ($hr != 0 and $vr != 0) { |
|
|
1493 | $expr .= "blur $hr, $vr, "; |
|
|
1494 | } |
|
|
1495 | } |
|
|
1496 | |
|
|
1497 | $expr .= "rootalign root)"; |
|
|
1498 | } |
|
|
1499 | |
|
|
1500 | if ($bg_opts->{path}) { |
|
|
1501 | my $file_expr; |
|
|
1502 | my $h_scale = $bg_opts->{h_scale} * 0.01; |
|
|
1503 | my $v_scale = $bg_opts->{v_scale} * 0.01; |
|
|
1504 | my $h_align = $bg_opts->{h_align} * 0.01; |
|
|
1505 | my $v_align = $bg_opts->{v_align} * 0.01; |
|
|
1506 | |
|
|
1507 | if (!$bg_opts->{tile}) { |
|
|
1508 | $file_expr .= "pad ("; |
|
|
1509 | } else { |
|
|
1510 | $file_expr .= "tile ("; |
|
|
1511 | } |
|
|
1512 | |
|
|
1513 | if ($bg_opts->{root_align}) { |
|
|
1514 | $file_expr .= "rootalign "; |
|
|
1515 | } else { |
|
|
1516 | $file_expr .= "align $h_align, $v_align, "; |
|
|
1517 | } |
|
|
1518 | |
|
|
1519 | if ($h_scale != 0 and $v_scale != 0) { |
|
|
1520 | my $op = $bg_opts->{keep_aspect} ? "fit" : "resize"; |
|
|
1521 | $file_expr .= "$op TW * $h_scale, TH * $v_scale, "; |
|
|
1522 | } |
|
|
1523 | |
|
|
1524 | my $path = q0 $bg_opts->{path}; |
|
|
1525 | |
|
|
1526 | $file_expr .= "keep { load $path })"; |
|
|
1527 | |
|
|
1528 | if ($expr) { |
|
|
1529 | $expr .= ", tint (\"[50]white\", $file_expr)"; |
|
|
1530 | } else { |
|
|
1531 | $expr = $file_expr; |
|
|
1532 | } |
|
|
1533 | } |
|
|
1534 | |
|
|
1535 | $expr |
|
|
1536 | } |
|
|
1537 | |
|
|
1538 | sub find_resource { |
|
|
1539 | my ($self, $res, $opt) = @_; |
|
|
1540 | |
|
|
1541 | my $v = $self->x_resource ($opt); |
|
|
1542 | $v = $self->x_resource ($res) unless defined $v; |
|
|
1543 | |
|
|
1544 | $v |
|
|
1545 | } |
|
|
1546 | |
|
|
1547 | sub parse_bgopts { |
|
|
1548 | my ($self) = @_; |
|
|
1549 | |
|
|
1550 | my $expr = $self->x_resource ("%.expr"); |
|
|
1551 | |
|
|
1552 | if (!$expr) { |
|
|
1553 | $self->{bg_opts} = { h_scale => 100, v_scale => 100, |
|
|
1554 | h_align => 50, v_align => 50 }; |
|
|
1555 | |
|
|
1556 | $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh"); |
|
|
1557 | $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint"); |
|
|
1558 | $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr"); |
|
|
1559 | $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr"); |
|
|
1560 | |
|
|
1561 | $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap")); |
|
|
1562 | $expr = $self->old_bg_expr; |
|
|
1563 | } |
|
|
1564 | |
|
|
1565 | $self->set_expr (parse_expr $expr); |
|
|
1566 | $self->{border} = $self->x_resource_boolean ("%.border"); |
|
|
1567 | |
|
|
1568 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
|
|
1569 | } |
|
|
1570 | |
1195 | sub on_start { |
1571 | sub on_start { |
1196 | my ($self) = @_; |
1572 | my ($self) = @_; |
1197 | |
1573 | |
1198 | my $expr = $self->x_resource ("%.expr") |
1574 | $self->parse_bgopts; |
1199 | or return; |
|
|
1200 | |
|
|
1201 | $self->has_render |
|
|
1202 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
|
|
1203 | |
|
|
1204 | $self->set_expr (parse_expr $expr); |
|
|
1205 | $self->{border} = $self->x_resource_boolean ("%.border"); |
|
|
1206 | |
|
|
1207 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
|
|
1208 | |
1575 | |
1209 | () |
1576 | () |
1210 | } |
1577 | } |
1211 | |
1578 | |
|
|
1579 | sub on_osc_seq { |
|
|
1580 | my ($self, $op, $arg) = @_; |
|
|
1581 | |
|
|
1582 | $op eq "20" or $op eq "706" |
|
|
1583 | or return; |
|
|
1584 | |
|
|
1585 | $self->{bg_opts} |
|
|
1586 | or $self->parse_bgopts; |
|
|
1587 | |
|
|
1588 | if ($op eq "20") { |
|
|
1589 | if ($arg eq "?") { |
|
|
1590 | my $h_scale = $self->{bg_opts}{h_scale}; |
|
|
1591 | my $v_scale = $self->{bg_opts}{v_scale}; |
|
|
1592 | my $h_align = $self->{bg_opts}{h_align}; |
|
|
1593 | my $v_align = $self->{bg_opts}{v_align}; |
|
|
1594 | $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007"); |
|
|
1595 | } else { |
|
|
1596 | $self->old_bg_opts ($arg); |
|
|
1597 | my $expr = $self->old_bg_expr; |
|
|
1598 | $self->set_expr (parse_expr $expr) if $expr; |
|
|
1599 | } |
|
|
1600 | } elsif ($op eq "705") { |
|
|
1601 | $self->{bg_opts}{tint} = $arg; |
|
|
1602 | my $expr = $self->old_bg_expr; |
|
|
1603 | $self->set_expr (parse_expr $expr) if $expr; |
|
|
1604 | } |
|
|
1605 | |
|
|
1606 | 1 |
|
|
1607 | } |
|
|
1608 | |