… | |
… | |
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; |
7 | our $EXPR; |
8 | #$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"'; |
8 | #$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"'; |
9 | $EXPR = 'border; move -X, -Y, load "argb.png"'; |
9 | $EXPR = 'move -TX, -TY, load "argb.png"'; |
10 | #$EXPR = ' |
10 | #$EXPR = ' |
11 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
11 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
12 | # clip X, Y, W, H, repeat_mirror, |
12 | # clip X, Y, W, H, repeat_mirror, |
13 | # load "/root/pix/das_fette_schwein.jpg" |
13 | # load "/root/pix/das_fette_schwein.jpg" |
14 | #'; |
14 | #'; |
… | |
… | |
17 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
17 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
18 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
18 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
19 | |
19 | |
20 | use Safe; |
20 | use Safe; |
21 | |
21 | |
22 | our $border; |
|
|
23 | our ($bgdsl_self, $old, $new); |
22 | our ($bgdsl_self, $old, $new); |
24 | our ($l, $t, $w, $h); |
23 | our ($x, $y, $w, $h); |
25 | |
24 | |
26 | # enforce at least this interval between updates |
25 | # enforce at least this interval between updates |
27 | our $MIN_INTERVAL = 1/100; |
26 | our $MIN_INTERVAL = 1/100; |
28 | |
27 | |
29 | { |
28 | { |
30 | package urxvt::bgdsl; # background language |
29 | package urxvt::bgdsl; # background language |
31 | |
30 | |
32 | # *repeat_empty = \&urxvt::RepeatNone; |
|
|
33 | # *repeat_tile = \&urxvt::RepeatNormal; |
|
|
34 | # *repeat_pad = \&urxvt::RepeatPad; |
|
|
35 | # *repeat_mirror = \&urxvt::RepeatReflect; |
|
|
36 | |
|
|
37 | =head2 PROVIDERS/GENERATORS |
31 | =head2 PROVIDERS/GENERATORS |
38 | |
32 | |
|
|
33 | These functions provide an image, by loading it from disk, grabbing it |
|
|
34 | from the root screen or by simply generating it. They are used as starting |
|
|
35 | points to get an image you can play with. |
|
|
36 | |
39 | =over 4 |
37 | =over 4 |
40 | |
38 | |
41 | =item load $path |
39 | =item load $path |
|
|
40 | |
|
|
41 | Loads the image at the given C<$path>. The image is set to plane tiling |
|
|
42 | mode. |
|
|
43 | |
|
|
44 | Loaded images will be cached for one cycle. |
42 | |
45 | |
43 | =cut |
46 | =cut |
44 | |
47 | |
45 | sub load($) { |
48 | sub load($) { |
46 | my ($path) = @_; |
49 | my ($path) = @_; |
47 | |
50 | |
48 | $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path); |
51 | $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path); |
49 | } |
52 | } |
|
|
53 | |
|
|
54 | =item root |
|
|
55 | |
|
|
56 | Returns the root window pixmap, that is, hopefully, the background image |
|
|
57 | of your screen. The image is set to extend mode. |
|
|
58 | |
|
|
59 | This function makes your expression root sensitive, that means it will be |
|
|
60 | reevaluated when the bg image changes. |
|
|
61 | |
|
|
62 | =cut |
50 | |
63 | |
51 | sub root() { |
64 | sub root() { |
52 | $new->{rootpmap_sensitive} = 1; |
65 | $new->{rootpmap_sensitive} = 1; |
53 | die "root op not supported, exg, we need you"; |
66 | die "root op not supported, exg, we need you"; |
54 | } |
67 | } |
55 | |
68 | |
|
|
69 | =item solid $colour |
|
|
70 | |
|
|
71 | =item solid $width, $height, $colour |
|
|
72 | |
|
|
73 | Creates a new image and completely fills it with the given colour. The |
|
|
74 | image is set to tiling mode. |
|
|
75 | |
|
|
76 | If <$width> and C<$height> are omitted, it creates a 1x1 image, which is |
|
|
77 | useful for solid backgrounds or for use in filtering effects. |
|
|
78 | |
|
|
79 | =cut |
|
|
80 | |
56 | sub solid($;$$) { |
81 | sub solid($$;$) { |
|
|
82 | my $colour = pop; |
|
|
83 | |
57 | my $img = $bgdsl_self->new_img (urxvt::PictStandardARGB32, $_[1] || 1, $_[2] || 1); |
84 | my $img = $bgdsl_self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); |
58 | $img->fill ($_[0]); |
85 | $img->fill ($colour); |
59 | $img |
86 | $img |
60 | } |
87 | } |
61 | |
88 | |
62 | =back |
89 | =back |
63 | |
90 | |
64 | =head2 VARIABLES |
91 | =head2 VARIABLES |
65 | |
92 | |
|
|
93 | The following functions provide variable data such as the terminal |
|
|
94 | window dimensions. Most of them make your expression sensitive to some |
|
|
95 | events, for example using C<TW> (terminal width) means your expression is |
|
|
96 | evaluated again when the terminal is resized. |
|
|
97 | |
66 | =over 4 |
98 | =over 4 |
67 | |
99 | |
68 | =cut |
100 | =item TX |
69 | |
101 | |
|
|
102 | =item TY |
|
|
103 | |
|
|
104 | Return the X and Y coordinates of the terminal window (the terminal |
|
|
105 | window is the full window by default, and the character area only when in |
|
|
106 | border-respect mode). |
|
|
107 | |
|
|
108 | Using these functions make your expression sensitive to window moves. |
|
|
109 | |
|
|
110 | These functions are mainly useful to align images to the root window. |
|
|
111 | |
|
|
112 | Example: load an image and align it so it looks as if anchored to the |
|
|
113 | background. |
|
|
114 | |
|
|
115 | move -TX, -TY, load "mybg.png" |
|
|
116 | |
|
|
117 | =item TW |
|
|
118 | |
|
|
119 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
|
|
120 | terminal window is the full window by default, and the character area only |
|
|
121 | when in border-respect mode). |
|
|
122 | |
|
|
123 | Using these functions make your expression sensitive to window resizes. |
|
|
124 | |
|
|
125 | These functions are mainly useful to scale images, or to clip images to |
|
|
126 | the window size to conserve memory. |
|
|
127 | |
|
|
128 | Example: take the screen background, clip it to the window size, blur it a |
|
|
129 | bit, align it to the window position and use it as background. |
|
|
130 | |
|
|
131 | clip move -TX, -TY, blur 5, root |
|
|
132 | |
|
|
133 | =cut |
|
|
134 | |
70 | sub X() { $new->{position_sensitive} = 1; $l } |
135 | sub TX() { $new->{position_sensitive} = 1; $x } |
71 | sub Y() { $new->{position_sensitive} = 1; $t } |
136 | sub TY() { $new->{position_sensitive} = 1; $y } |
72 | sub W() { $new->{size_sensitive} = 1; $w } |
137 | sub TW() { $new->{size_sensitive} = 1; $w } |
73 | sub H() { $new->{size_sensitive} = 1; $h } |
138 | sub TH() { $new->{size_sensitive} = 1; $h } |
74 | |
139 | |
75 | sub now() { urxvt::NOW } |
140 | sub now() { urxvt::NOW } |
76 | |
141 | |
77 | sub again($) { |
142 | sub again($) { |
78 | $new->{again} = $_[0]; |
143 | $new->{again} = $_[0]; |
… | |
… | |
185 | |
250 | |
186 | =cut |
251 | =cut |
187 | |
252 | |
188 | sub clip($;$$;$$) { |
253 | sub clip($;$$;$$) { |
189 | my $img = pop; |
254 | my $img = pop; |
190 | my $h = pop || H; |
255 | my $h = pop || TH; |
191 | my $w = pop || W; |
256 | my $w = pop || TW; |
192 | $img->sub_rect ($_[0], $_[1], $w, $h) |
257 | $img->sub_rect ($_[0], $_[1], $w, $h) |
193 | } |
258 | } |
194 | |
259 | |
195 | =item scale $img |
260 | =item scale $img |
196 | |
261 | |
… | |
… | |
217 | sub scale($$$) { |
282 | sub scale($$$) { |
218 | my $img = pop; |
283 | my $img = pop; |
219 | |
284 | |
220 | @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) |
285 | @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) |
221 | : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) |
286 | : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) |
222 | : $img->scale (W, H) |
287 | : $img->scale (TW, TH) |
223 | } |
288 | } |
224 | |
289 | |
225 | sub resize($$$) { |
290 | sub resize($$$) { |
226 | my $img = pop; |
291 | my $img = pop; |
227 | $img->scale ($_[0], $_[1]) |
292 | $img->scale ($_[0], $_[1]) |
228 | } |
293 | } |
229 | |
294 | |
230 | # TODO: ugly |
|
|
231 | sub move($$;$) { |
295 | sub move($$;$) { |
232 | my $img = pop->clone; |
296 | my $img = pop->clone; |
233 | $img->move ($_[0], $_[1]); |
297 | $img->move ($_[0], $_[1]); |
234 | $img |
298 | $img |
235 | # my $img = pop; |
|
|
236 | # $img->sub_rect ( |
|
|
237 | # $_[0], $_[1], |
|
|
238 | # $img->w, $img->h, |
|
|
239 | # $_[2], |
|
|
240 | # ) |
|
|
241 | } |
299 | } |
242 | |
300 | |
243 | sub rotate($$$$$$) { |
301 | sub rotate($$$$$$) { |
244 | my $img = pop; |
302 | my $img = pop; |
245 | $img->rotate ( |
303 | $img->rotate ( |
… | |
… | |
251 | ) |
309 | ) |
252 | } |
310 | } |
253 | |
311 | |
254 | sub blur($$;$) { |
312 | sub blur($$;$) { |
255 | my $img = pop; |
313 | my $img = pop; |
256 | |
|
|
257 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]); |
314 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
258 | } |
315 | } |
259 | |
316 | |
260 | sub contrast($$;$$;$) { |
317 | sub contrast($$;$$;$) { |
261 | my $img = pop; |
318 | my $img = pop; |
262 | my ($r, $g, $b, $a) = @_; |
319 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
277 | $a = 1 if @_ < 5; |
334 | $a = 1 if @_ < 5; |
278 | |
335 | |
279 | $img = $img->clone; |
336 | $img = $img->clone; |
280 | $img->brightness ($r, $g, $b, $a); |
337 | $img->brightness ($r, $g, $b, $a); |
281 | $img |
338 | $img |
282 | } |
|
|
283 | |
|
|
284 | =back |
|
|
285 | |
|
|
286 | =head2 SETTINGS |
|
|
287 | |
|
|
288 | =over 4 |
|
|
289 | |
|
|
290 | =item border $respect_border=1 |
|
|
291 | |
|
|
292 | Sets whether the image should respect the terminal border (argument true |
|
|
293 | or missing), or whether it should fill the whole window (the default). |
|
|
294 | |
|
|
295 | By default, the image will cover the whole toplevel window. If C<border> |
|
|
296 | is enabled, then it will only fill the character area and leave a normal |
|
|
297 | border in the background colour around it and behind the scrollbar. |
|
|
298 | |
|
|
299 | =cut |
|
|
300 | |
|
|
301 | sub border { |
|
|
302 | $border = @_ ? $_[0] : 1; |
|
|
303 | } |
339 | } |
304 | |
340 | |
305 | =back |
341 | =back |
306 | |
342 | |
307 | =cut |
343 | =cut |
… | |
… | |
338 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
374 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
339 | |
375 | |
340 | # set environment to evaluate user expression |
376 | # set environment to evaluate user expression |
341 | |
377 | |
342 | local $bgdsl_self = $self; |
378 | local $bgdsl_self = $self; |
343 | local $border; |
|
|
344 | |
379 | |
345 | local $old = $self->{state}; |
380 | local $old = $self->{state}; |
346 | local $new = my $state = $self->{state} = {}; |
381 | local $new = my $state = $self->{state} = {}; |
347 | |
382 | |
|
|
383 | my $border = 0; #d# |
|
|
384 | |
348 | ($l, $t, $w, $h) = |
385 | ($x, $y, $w, $h) = |
349 | $self->get_geometry; |
386 | $self->background_geometry ($border); |
350 | |
|
|
351 | warn "$l,$t,$w,$h\n";#d# |
|
|
352 | |
387 | |
353 | # evaluate user expression |
388 | # evaluate user expression |
354 | |
389 | |
355 | my $img = eval { $self->{expr}->() }; |
390 | my $img = eval { $self->{expr}->() }; |
356 | warn $@ if $@;#d# |
391 | warn $@ if $@;#d# |