… | |
… | |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
4 | #:META:X_RESOURCE:%.enable:boolean:some boolean |
4 | #:META:X_RESOURCE:%.enable:boolean:some boolean |
5 | #:META:X_RESOURCE:%.extra.:value:extra config |
5 | #:META:X_RESOURCE:%.extra.:value:extra config |
6 | |
6 | |
|
|
7 | our $EXPR; |
|
|
8 | #$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"'; |
7 | our $EXPR = 'move X, Y, load "MagnoliaAlpha.png"'; |
9 | $EXPR = 'move -X, -Y, load "argb.png"'; |
8 | #$EXPR = ' |
10 | #$EXPR = ' |
9 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
11 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
10 | # clip X, Y, W, H, repeat_mirror, |
12 | # clip X, Y, W, H, repeat_mirror, |
11 | # load "/root/pix/das_fette_schwein.jpg" |
13 | # load "/root/pix/das_fette_schwein.jpg" |
12 | #'; |
14 | #'; |
… | |
… | |
16 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
18 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
17 | |
19 | |
18 | use Safe; |
20 | use Safe; |
19 | |
21 | |
20 | our ($bgdsl_self, $old, $new); |
22 | our ($bgdsl_self, $old, $new); |
21 | our ($l, $t, $w, $h); |
23 | our ($x, $y, $w, $h); |
22 | |
24 | |
23 | # enforce at least this interval between updates |
25 | # enforce at least this interval between updates |
24 | our $MIN_INTERVAL = 1/100; |
26 | our $MIN_INTERVAL = 1/100; |
25 | |
27 | |
26 | { |
28 | { |
27 | package urxvt::bgdsl; # background language |
29 | package urxvt::bgdsl; # background language |
28 | |
30 | |
29 | *repeat_empty = \&urxvt::RepeatNone; |
|
|
30 | *repeat_tile = \&urxvt::RepeatNormal; |
|
|
31 | *repeat_pad = \&urxvt::RepeatPad; |
|
|
32 | *repeat_mirror = \&urxvt::RepeatReflect; |
|
|
33 | |
|
|
34 | =head2 PROVIDERS/GENERATORS |
31 | =head2 PROVIDERS/GENERATORS |
35 | |
32 | |
36 | =over 4 |
33 | =over 4 |
37 | |
34 | |
38 | =item load $path |
35 | =item load $path |
|
|
36 | |
|
|
37 | Loads the image at the given C<$path>. The image is set to plane tiling |
|
|
38 | mode. |
|
|
39 | |
|
|
40 | |
39 | |
41 | |
40 | =cut |
42 | =cut |
41 | |
43 | |
42 | sub load($) { |
44 | sub load($) { |
43 | my ($path) = @_; |
45 | my ($path) = @_; |
… | |
… | |
56 | $img |
58 | $img |
57 | } |
59 | } |
58 | |
60 | |
59 | =back |
61 | =back |
60 | |
62 | |
61 | =head2 OPERATORS |
63 | =head2 VARIABLES |
62 | |
64 | |
63 | =over 4 |
65 | =over 4 |
64 | |
66 | |
65 | =cut |
67 | =cut |
66 | |
68 | |
|
|
69 | sub X() { $new->{position_sensitive} = 1; $x } |
|
|
70 | sub Y() { $new->{position_sensitive} = 1; $y } |
|
|
71 | sub W() { $new->{size_sensitive} = 1; $w } |
|
|
72 | sub H() { $new->{size_sensitive} = 1; $h } |
|
|
73 | |
|
|
74 | sub now() { urxvt::NOW } |
|
|
75 | |
|
|
76 | sub again($) { |
|
|
77 | $new->{again} = $_[0]; |
|
|
78 | } |
|
|
79 | |
|
|
80 | sub counter($) { |
|
|
81 | $new->{again} = $_[0]; |
|
|
82 | $bgdsl_self->{counter} + 0 |
|
|
83 | } |
|
|
84 | |
|
|
85 | =back |
|
|
86 | |
|
|
87 | =head2 TILING MODES |
|
|
88 | |
|
|
89 | The following operators modify the tiling mode of an image, that is, the |
|
|
90 | way that pixels outside the image area are painted when the image is used. |
|
|
91 | |
|
|
92 | =over 4 |
|
|
93 | |
|
|
94 | =item tile $img |
|
|
95 | |
|
|
96 | Tiles the whole plane with the image and returns this new image - or in |
|
|
97 | other words, it returns a copy of the image in plane tiling mode. |
|
|
98 | |
|
|
99 | =item mirror $img |
|
|
100 | |
|
|
101 | Similar to tile, but reflects the image each time it uses a new copy, so |
|
|
102 | that top edges always touch top edges, right edges always touch right |
|
|
103 | edges and so on (with normal tiling, left edges always touch right edges |
|
|
104 | and top always touch bottom edges). |
|
|
105 | |
|
|
106 | =item pad $img |
|
|
107 | |
|
|
108 | Takes an image and modifies it so that all pixels outside the image area |
|
|
109 | become transparent. This mode is most useful when you want to place an |
|
|
110 | image over another image or the background colour while leaving all |
|
|
111 | background pixels outside the image unchanged. |
|
|
112 | |
|
|
113 | =item extend $img |
|
|
114 | |
|
|
115 | Extends the image over the whole plane, using the closest pixel in the |
|
|
116 | area outside the image. This mode is mostly useful when you more complex |
|
|
117 | filtering operations and want the pixels outside the image to have the |
|
|
118 | same values as the pixels near the edge. |
|
|
119 | |
|
|
120 | =cut |
|
|
121 | |
|
|
122 | sub pad($) { |
|
|
123 | my $img = $_[0]->clone; |
|
|
124 | $img->repeat_mode (urxvt::RepeatNone); |
|
|
125 | $img |
|
|
126 | } |
|
|
127 | |
|
|
128 | sub tile($) { |
|
|
129 | my $img = $_[0]->clone; |
|
|
130 | $img->repeat_mode (urxvt::RepeatNormal); |
|
|
131 | $img |
|
|
132 | } |
|
|
133 | |
|
|
134 | sub mirror($) { |
|
|
135 | my $img = $_[0]->clone; |
|
|
136 | $img->repeat_mode (urxvt::RepeatReflect); |
|
|
137 | $img |
|
|
138 | } |
|
|
139 | |
|
|
140 | sub extend($) { |
|
|
141 | my $img = $_[0]->clone; |
|
|
142 | $img->repeat_mode (urxvt::RepeatPad); |
|
|
143 | $img |
|
|
144 | } |
|
|
145 | |
|
|
146 | =back |
|
|
147 | |
|
|
148 | =head2 PIXEL OPERATORS |
|
|
149 | |
|
|
150 | The following operators modify the image pixels in various ways. |
|
|
151 | |
|
|
152 | =over 4 |
|
|
153 | |
|
|
154 | =item clone $img |
|
|
155 | |
|
|
156 | Returns an exact copy of the image. |
|
|
157 | |
|
|
158 | =cut |
|
|
159 | |
67 | # sub clone($) { |
160 | sub clone($) { |
68 | # $_[0]->clone |
161 | $_[0]->clone |
69 | # } |
162 | } |
70 | |
163 | |
|
|
164 | =item clip $img |
|
|
165 | |
|
|
166 | =item clip $width, $height, $img |
|
|
167 | |
|
|
168 | =item clip $x, $y, $width, $height, $img |
|
|
169 | |
|
|
170 | Clips an image to the given rectangle. If the rectangle is outside the |
|
|
171 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
|
|
172 | larger than the image, then the tiling mode defines how the extra pixels |
|
|
173 | will be filled. |
|
|
174 | |
|
|
175 | If C<$x> an C<$y> are missing, then C<0> is assumed for both. |
|
|
176 | |
|
|
177 | If C<$width> and C<$height> are missing, then the window size will be |
|
|
178 | assumed. |
|
|
179 | |
|
|
180 | Example: load an image, blur it, and clip it to the window size to save |
|
|
181 | memory. |
|
|
182 | |
|
|
183 | clip blur 10, load "mybg.png" |
|
|
184 | |
|
|
185 | =cut |
|
|
186 | |
71 | sub clip($$$$$;$) { |
187 | sub clip($;$$;$$) { |
|
|
188 | my $img = pop; |
72 | my $img = pop; |
189 | my $h = pop || H; |
|
|
190 | my $w = pop || W; |
73 | $img->sub_rect ($_[0], $_[1], $_[2], $_[3], $_[4]) |
191 | $img->sub_rect ($_[0], $_[1], $w, $h) |
|
|
192 | } |
|
|
193 | |
|
|
194 | =item scale $img |
|
|
195 | |
|
|
196 | =item scale $size_percent, $img |
|
|
197 | |
|
|
198 | =item scale $width_percent, $height_percent, $img |
|
|
199 | |
|
|
200 | Scales the image by the given percentages in horizontal |
|
|
201 | (C<$width_percent>) and vertical (C<$height_percent>) direction. |
|
|
202 | |
|
|
203 | If only one percentage is give, it is used for both directions. |
|
|
204 | |
|
|
205 | If no percentages are given, scales the image to the window size without |
|
|
206 | keeping aspect. |
|
|
207 | |
|
|
208 | =item resize $width, $height, $img |
|
|
209 | |
|
|
210 | Resizes the image to exactly C<$width> times C<$height> pixels. |
|
|
211 | |
|
|
212 | =cut |
|
|
213 | |
|
|
214 | #TODO: maximise, maximise_fill? |
|
|
215 | |
|
|
216 | sub scale($$$) { |
|
|
217 | my $img = pop; |
|
|
218 | |
|
|
219 | @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) |
|
|
220 | : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) |
|
|
221 | : $img->scale (W, H) |
74 | } |
222 | } |
75 | |
223 | |
76 | sub resize($$$) { |
224 | sub resize($$$) { |
77 | my $img = pop; |
225 | my $img = pop; |
78 | $img->scale ($_[0], $_[1]) |
226 | $img->scale ($_[0], $_[1]) |
79 | } |
227 | } |
80 | |
228 | |
81 | # TODO: ugly |
229 | # TODO: ugly |
82 | sub move($$;$) { |
230 | sub move($$;$) { |
|
|
231 | my $img = pop->clone; |
|
|
232 | $img->move ($_[0], $_[1]); |
|
|
233 | $img |
83 | my $img = pop; |
234 | # my $img = pop; |
84 | $img->sub_rect ( |
235 | # $img->sub_rect ( |
85 | $_[0], $_[1], |
236 | # $_[0], $_[1], |
86 | $img->w, $img->h, |
237 | # $img->w, $img->h, |
87 | $_[2], |
238 | # $_[2], |
88 | ) |
239 | # ) |
89 | } |
240 | } |
90 | |
241 | |
91 | sub rotate($$$$$$;$) { |
242 | sub rotate($$$$$$) { |
92 | my $img = pop; |
243 | my $img = pop; |
93 | $img->rotate ( |
244 | $img->rotate ( |
94 | $_[0], |
245 | $_[0], |
95 | $_[1], |
246 | $_[1], |
96 | $_[2] * $img->w * .01, |
247 | $_[2] * $img->w * .01, |
97 | $_[3] * $img->h * .01, |
248 | $_[3] * $img->h * .01, |
98 | $_[4] * (3.14159265 / 180), |
249 | $_[4] * (3.14159265 / 180), |
99 | $_[5], |
|
|
100 | ) |
250 | ) |
101 | } |
251 | } |
102 | |
252 | |
103 | sub blur($$$) { |
253 | sub blur($$;$) { |
104 | my ($rh, $rv, $img) = @_; |
254 | my $img = pop; |
105 | |
255 | |
106 | $img->blur ($rh, $rv); |
256 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]); |
107 | } |
257 | } |
108 | |
258 | |
109 | sub contrast($$;$$;$) { |
259 | sub contrast($$;$$;$) { |
110 | my $img = pop; |
260 | my $img = pop; |
111 | my ($r, $g, $b, $a) = @_; |
261 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
126 | $a = 1 if @_ < 5; |
276 | $a = 1 if @_ < 5; |
127 | |
277 | |
128 | $img = $img->clone; |
278 | $img = $img->clone; |
129 | $img->brightness ($r, $g, $b, $a); |
279 | $img->brightness ($r, $g, $b, $a); |
130 | $img |
280 | $img |
131 | } |
|
|
132 | |
|
|
133 | sub X() { $new->{position_sensitive} = 1; $l } |
|
|
134 | sub Y() { $new->{position_sensitive} = 1; $t } |
|
|
135 | sub W() { $new->{size_sensitive} = 1; $w } |
|
|
136 | sub H() { $new->{size_sensitive} = 1; $h } |
|
|
137 | |
|
|
138 | sub now() { urxvt::NOW } |
|
|
139 | |
|
|
140 | sub again($) { |
|
|
141 | $new->{again} = $_[0]; |
|
|
142 | } |
|
|
143 | |
|
|
144 | sub counter($) { |
|
|
145 | $new->{again} = $_[0]; |
|
|
146 | $bgdsl_self->{counter} + 0 |
|
|
147 | } |
281 | } |
148 | |
282 | |
149 | =back |
283 | =back |
150 | |
284 | |
151 | =cut |
285 | =cut |
… | |
… | |
186 | local $bgdsl_self = $self; |
320 | local $bgdsl_self = $self; |
187 | |
321 | |
188 | local $old = $self->{state}; |
322 | local $old = $self->{state}; |
189 | local $new = my $state = $self->{state} = {}; |
323 | local $new = my $state = $self->{state} = {}; |
190 | |
324 | |
|
|
325 | my $border = 0; #d# |
|
|
326 | |
191 | ($l, $t, $w, $h) = |
327 | ($x, $y, $w, $h) = |
192 | $self->get_geometry; |
328 | $self->background_geometry ($border); |
193 | |
329 | |
194 | # evaluate user expression |
330 | # evaluate user expression |
195 | |
331 | |
196 | my $img = eval { $self->{expr}->() }; |
332 | my $img = eval { $self->{expr}->() }; |
197 | warn $@ if $@;#d# |
333 | warn $@ if $@;#d# |
… | |
… | |
244 | # prepare and set background pixmap |
380 | # prepare and set background pixmap |
245 | |
381 | |
246 | $img = $img->sub_rect (0, 0, $w, $h) |
382 | $img = $img->sub_rect (0, 0, $w, $h) |
247 | if $img->w != $w || $img->h != $h; |
383 | if $img->w != $w || $img->h != $h; |
248 | |
384 | |
249 | $self->set_background ($img); |
385 | $self->set_background ($img, $border); |
250 | $self->scr_recolour (0); |
386 | $self->scr_recolour (0); |
251 | $self->want_refresh; |
387 | $self->want_refresh; |
252 | } |
388 | } |
253 | |
389 | |
254 | sub on_start { |
390 | sub on_start { |