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 | |
11 | =head1 SYNOPSIS |
23 | =head1 SYNOPSIS |
12 | |
24 | |
13 | urxvt --background-expr 'background expression' |
25 | urxvt --background-expr 'background expression' |
14 | --background-border |
26 | --background-border |
15 | --background-interval seconds |
27 | --background-interval seconds |
16 | |
28 | |
|
|
29 | =head1 QUICK AND DIRTY CHEAT SHEET |
|
|
30 | |
|
|
31 | Load a random jpeg image and tile the background with it without scaling |
|
|
32 | or anything else: |
|
|
33 | |
|
|
34 | load "/path/to/img.jpg" |
|
|
35 | |
|
|
36 | The same, but use mirroring/reflection instead of tiling: |
|
|
37 | |
|
|
38 | mirror load "/path/to/img.jpg" |
|
|
39 | |
|
|
40 | Load an image and scale it to exactly fill the terminal window: |
|
|
41 | |
|
|
42 | scale keep { load "/path/to/img.jpg" } |
|
|
43 | |
|
|
44 | Implement pseudo-transparency by using a suitably-aligned root pixmap |
|
|
45 | as window background: |
|
|
46 | |
|
|
47 | rootalign root |
|
|
48 | |
|
|
49 | Likewise, but keep a blurred copy: |
|
|
50 | |
|
|
51 | rootalign keep { blur 10, root } |
|
|
52 | |
17 | =head1 DESCRIPTION |
53 | =head1 DESCRIPTION |
18 | |
54 | |
19 | This extension manages the terminal background by creating a picture that |
55 | This extension manages the terminal background by creating a picture that |
20 | is behind the text, replacing the normal background colour. |
56 | is behind the text, replacing the normal background colour. |
21 | |
57 | |
… | |
… | |
26 | to be as simple as possible. |
62 | to be as simple as possible. |
27 | |
63 | |
28 | 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 |
29 | use: |
65 | use: |
30 | |
66 | |
31 | urxvt --background-expr 'scale load "/path/to/mybg.png"' |
67 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
32 | |
68 | |
33 | Or specified as a X resource: |
69 | Or specified as a X resource: |
34 | |
70 | |
35 | URxvt.background-expr: scale load "/path/to/mybg.png" |
71 | URxvt.background.expr: scale keep { load "/path/to/mybg.png" } |
36 | |
72 | |
37 | =head1 THEORY OF OPERATION |
73 | =head1 THEORY OF OPERATION |
38 | |
74 | |
39 | 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 |
40 | 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 |
… | |
… | |
53 | If any of the parameters that the expression relies on changes (when the |
89 | If any of the parameters that the expression relies on changes (when the |
54 | window is moved or resized, its position or size changes; when the root |
90 | window is moved or resized, its position or size changes; when the root |
55 | pixmap is replaced by another one the root background changes; or when the |
91 | pixmap is replaced by another one the root background changes; or when the |
56 | timer elapses), then the expression will be evaluated again. |
92 | timer elapses), then the expression will be evaluated again. |
57 | |
93 | |
58 | For example, an expression such as C<scale load "$HOME/mybg.png"> scales the |
94 | For example, an expression such as C<scale keep { load "$HOME/mybg.png" |
59 | image to the window size, so it relies on the window size and will |
95 | }> scales the image to the window size, so it relies on the window size |
60 | be reevaluated each time it is changed, but not when it moves for |
96 | and will be reevaluated each time it is changed, but not when it moves for |
61 | example. That ensures that the picture always fills the terminal, even |
97 | example. That ensures that the picture always fills the terminal, even |
62 | after its size changes. |
98 | after its size changes. |
63 | |
99 | |
64 | =head2 EXPRESSIONS |
100 | =head2 EXPRESSIONS |
65 | |
101 | |
66 | Expressions are normal Perl expressions, in fact, they are Perl blocks - |
102 | Expressions are normal Perl expressions, in fact, they are Perl blocks - |
67 | which means you could use multiple lines and statements: |
103 | which means you could use multiple lines and statements: |
68 | |
104 | |
|
|
105 | scale keep { |
69 | again 3600; |
106 | again 3600; |
70 | if (localtime now)[6]) { |
107 | if (localtime now)[6]) { |
71 | return scale load "$HOME/weekday.png"; |
108 | return load "$HOME/weekday.png"; |
72 | } else { |
109 | } else { |
73 | return scale load "$HOME/sunday.png"; |
110 | return load "$HOME/sunday.png"; |
|
|
111 | } |
74 | } |
112 | } |
75 | |
113 | |
76 | This expression is evaluated once per hour. It will set F<sunday.png> as |
114 | This inner expression is evaluated once per hour (and whenever the |
|
|
115 | terminal window is resized). It sets F<sunday.png> as background on |
77 | background on Sundays, and F<weekday.png> on all other days. |
116 | Sundays, and F<weekday.png> on all other days. |
78 | |
117 | |
79 | Fortunately, we expect that most expressions will be much simpler, with |
118 | Fortunately, we expect that most expressions will be much simpler, with |
80 | little Perl knowledge needed. |
119 | little Perl knowledge needed. |
81 | |
120 | |
82 | Basically, you always start with a function that "generates" an image |
121 | Basically, you always start with a function that "generates" an image |
… | |
… | |
105 | get a percentage): |
144 | get a percentage): |
106 | |
145 | |
107 | scale 2, load "$HOME/mypic.png" |
146 | scale 2, load "$HOME/mypic.png" |
108 | |
147 | |
109 | 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> |
110 | 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 |
111 | 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 |
112 | commas. |
151 | commas. |
113 | |
152 | |
114 | 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 |
115 | horizontal and vertical dimensions. For example, this halves the image |
154 | horizontal and vertical dimensions. For example, this halves the image |
116 | width and doubles the image height: |
155 | width and doubles the image height: |
117 | |
156 | |
118 | scale 0.5, 2, load "$HOME/mypic.png" |
157 | scale 0.5, 2, load "$HOME/mypic.png" |
119 | |
158 | |
120 | Other effects than scaling are also readily available, for example, you can |
159 | IF you try out these expressions, you might suffer from some sluggishness, |
121 | tile the image to fill the whole window, instead of resizing it: |
160 | because each time the terminal is resized, it loads the PNG image again |
|
|
161 | and scales it. Scaling is usually fast (and unavoidable), but loading the |
|
|
162 | image can be quite time consuming. This is where C<keep> comes in handy: |
122 | |
163 | |
|
|
164 | scale 0.5, 2, keep { load "$HOME/mypic.png" } |
|
|
165 | |
|
|
166 | The C<keep> operator executes all the statements inside the braces only |
|
|
167 | once, or when it thinks the outcome might change. In other cases it |
|
|
168 | returns the last value computed by the brace block. |
|
|
169 | |
|
|
170 | This means that the C<load> is only executed once, which makes it much |
|
|
171 | faster, but also means that more memory is being used, because the loaded |
|
|
172 | image must be kept in memory at all times. In this expression, the |
|
|
173 | trade-off is likely worth it. |
|
|
174 | |
|
|
175 | But back to effects: Other effects than scaling are also readily |
|
|
176 | available, for example, you can tile the image to fill the whole window, |
|
|
177 | instead of resizing it: |
|
|
178 | |
123 | tile load "$HOME/mypic.png" |
179 | tile keep { load "$HOME/mypic.png" } |
124 | |
180 | |
125 | In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator |
181 | In fact, images returned by C<load> are in C<tile> mode by default, so the |
126 | is kind of superfluous. |
182 | C<tile> operator is kind of superfluous. |
127 | |
183 | |
128 | Another common effect is to mirror the image, so that the same edges touch: |
184 | Another common effect is to mirror the image, so that the same edges |
|
|
185 | touch: |
129 | |
186 | |
130 | mirror load "$HOME/mypic.png" |
187 | mirror keep { load "$HOME/mypic.png" } |
131 | |
188 | |
132 | This is also a typical background expression: |
189 | Another common background expression is: |
133 | |
190 | |
134 | rootalign root |
191 | rootalign root |
135 | |
192 | |
136 | It first takes a snapshot of the screen background image, and then |
193 | This one first takes a snapshot of the screen background image, and then |
137 | moves it to the upper left corner of the screen - the result is |
194 | moves it to the upper left corner of the screen (as opposed to the upper |
138 | pseudo-transparency, as the image seems to be static while the window is |
195 | left corner of the terminal window)- the result is pseudo-transparency: |
139 | moved around. |
196 | the image seems to be static while the window is moved around. |
140 | |
197 | |
141 | =head2 CYCLES AND CACHING |
198 | =head2 COLOUR SPECIFICATIONS |
142 | |
199 | |
143 | As has been mentioned before, the expression might be evaluated multiple |
200 | Whenever an operator expects a "colour", then this can be specified in one |
144 | times. Each time the expression is reevaluated, a new cycle is said to |
201 | of two ways: Either as string with an X11 colour specification, such as: |
145 | have begun. Many operators cache their results till the next cycle. |
|
|
146 | |
202 | |
147 | For example, the C<load> operator keeps a copy of the image. If it is |
203 | "red" # named colour |
148 | asked to load the same image on the next cycle it will not load it again, |
204 | "#f00" # simple rgb |
149 | but return the cached copy. |
205 | "[50]red" # red with 50% alpha |
|
|
206 | "TekHVC:300/50/50" # anything goes |
150 | |
207 | |
151 | This only works for one cycle though, so as long as you load the same |
208 | OR as an array reference with one, three or four components: |
152 | image every time, it will always be cached, but when you load a different |
|
|
153 | image, it will forget about the first one. |
|
|
154 | |
209 | |
155 | This allows you to either speed things up by keeping multiple images in |
210 | [0.5] # 50% gray, 100% alpha |
156 | memory, or conserve memory by loading images more often. |
211 | [0.5, 0, 0] # dark red, no green or blur, 100% alpha |
|
|
212 | [0.5, 0, 0, 0.7] # same with explicit 70% alpha |
157 | |
213 | |
158 | For example, you can keep two images in memory and use a random one like |
214 | =head2 CACHING AND SENSITIVITY |
159 | this: |
|
|
160 | |
215 | |
161 | my $img1 = load "img1.png"; |
216 | Since some operations (such as C<load> and C<blur>) can take a long time, |
162 | my $img2 = load "img2.png"; |
217 | caching results can be very important for a smooth operation. Caching can |
163 | (0.5 > rand) ? $img1 : $img2 |
218 | also be useful to reduce memory usage, though, for example, when an image |
|
|
219 | is cached by C<load>, it could be shared by multiple terminal windows |
|
|
220 | running inside urxvtd. |
164 | |
221 | |
165 | Since both images are "loaded" every time the expression is evaluated, |
222 | =head3 C<keep { ... }> caching |
166 | they are always kept in memory. Contrast this version: |
|
|
167 | |
223 | |
168 | my $path1 = "img1.png"; |
224 | The most important way to cache expensive operations is to use C<keep { |
169 | my $path2 = "img2.png"; |
225 | ... }>. The C<keep> operator takes a block of multiple statements enclosed |
170 | load ((0.5 > rand) ? $path1 : $path2) |
226 | by C<{}> and keeps the return value in memory. |
171 | |
227 | |
172 | Here, a path is selected randomly, and load is only called for one image, |
228 | An expression can be "sensitive" to various external events, such as |
173 | so keeps only one image in memory. If, on the next evaluation, luck |
229 | scaling or moving the window, root background changes and timers. Simply |
174 | decides to use the other path, then it will have to load that image again. |
230 | using an expression (such as C<scale> without parameters) that depends on |
|
|
231 | certain changing values (called "variables"), or using those variables |
|
|
232 | directly, will make an expression sensitive to these events - for example, |
|
|
233 | using C<scale> or C<TW> will make the expression sensitive to the terminal |
|
|
234 | size, and thus to resizing events. |
|
|
235 | |
|
|
236 | When such an event happens, C<keep> will automatically trigger a |
|
|
237 | reevaluation of the whole expression with the new value of the expression. |
|
|
238 | |
|
|
239 | C<keep> is most useful for expensive operations, such as C<blur>: |
|
|
240 | |
|
|
241 | rootalign keep { blur 20, root } |
|
|
242 | |
|
|
243 | This makes a blurred copy of the root background once, and on subsequent |
|
|
244 | calls, just root-aligns it. Since C<blur> is usually quite slow and |
|
|
245 | C<rootalign> is quite fast, this trades extra memory (for the cached |
|
|
246 | blurred pixmap) with speed (blur only needs to be redone when root |
|
|
247 | changes). |
|
|
248 | |
|
|
249 | =head3 C<load> caching |
|
|
250 | |
|
|
251 | The C<load> operator itself does not keep images in memory, but as long as |
|
|
252 | the image is still in memory, C<load> will use the in-memory image instead |
|
|
253 | of loading it freshly from disk. |
|
|
254 | |
|
|
255 | That means that this expression: |
|
|
256 | |
|
|
257 | keep { load "$HOME/path..." } |
|
|
258 | |
|
|
259 | Not only caches the image in memory, other terminal instances that try to |
|
|
260 | C<load> it can reuse that in-memory copy. |
175 | |
261 | |
176 | =head1 REFERENCE |
262 | =head1 REFERENCE |
177 | |
263 | |
178 | =head2 COMMAND LINE SWITCHES |
264 | =head2 COMMAND LINE SWITCHES |
179 | |
265 | |
180 | =over 4 |
266 | =over |
181 | |
267 | |
182 | =item --background-expr perl-expression |
268 | =item --background-expr perl-expression |
183 | |
269 | |
184 | Specifies the Perl expression to evaluate. |
270 | Specifies the Perl expression to evaluate. |
185 | |
271 | |
… | |
… | |
203 | =back |
289 | =back |
204 | |
290 | |
205 | =cut |
291 | =cut |
206 | |
292 | |
207 | our %_IMG_CACHE; |
293 | our %_IMG_CACHE; |
208 | our %_ONCE_CACHE; |
|
|
209 | our $HOME; |
294 | our $HOME; |
210 | our ($self, $old, $new); |
295 | our ($self, $frame); |
211 | our ($x, $y, $w, $h); |
296 | our ($x, $y, $w, $h, $focus); |
212 | |
297 | |
213 | # enforce at least this interval between updates |
298 | # enforce at least this interval between updates |
214 | our $MIN_INTERVAL = 6/59.951; |
299 | our $MIN_INTERVAL = 6/59.951; |
215 | |
300 | |
216 | { |
301 | { |
217 | package urxvt::bgdsl; # background language |
302 | package urxvt::bgdsl; # background language |
|
|
303 | |
|
|
304 | sub FR_PARENT() { 0 } # parent frame, if any - must be #0 |
|
|
305 | sub FR_CACHE () { 1 } # cached values |
|
|
306 | sub FR_AGAIN () { 2 } # what this expr is sensitive to |
|
|
307 | sub FR_STATE () { 3 } # watchers etc. |
218 | |
308 | |
219 | use List::Util qw(min max sum shuffle); |
309 | use List::Util qw(min max sum shuffle); |
220 | |
310 | |
221 | =head2 PROVIDERS/GENERATORS |
311 | =head2 PROVIDERS/GENERATORS |
222 | |
312 | |
223 | 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 |
224 | 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 |
225 | points to get an image you can play with. |
315 | points to get an image you can play with. |
226 | |
316 | |
227 | =over 4 |
317 | =over |
228 | |
318 | |
229 | =item load $path |
319 | =item load $path |
230 | |
320 | |
231 | 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 |
232 | mode. |
322 | mode. |
233 | |
323 | |
234 | Loaded images will be cached for one cycle, and shared between temrinals |
324 | If the image is already in memory (e.g. because another terminal instance |
235 | running in the same process (e.g. in C<urxvtd>). |
325 | uses it), then the in-memory copy is returned instead. |
236 | |
326 | |
237 | =item load_uc $path |
327 | =item load_uc $path |
238 | |
328 | |
239 | Load uncached - same as load, but does not cache the image. This function |
329 | Load uncached - same as load, but does not cache the image, which means it |
240 | is most useufl if you want to optimise a background expression in some |
330 | is I<always> loaded from the filesystem again, even if another copy of it |
241 | way. |
331 | is in memory at the time. |
242 | |
332 | |
243 | =cut |
333 | =cut |
244 | |
334 | |
245 | sub load_uc($) { |
335 | sub load_uc($) { |
|
|
336 | $self->new_img_from_file ($_[0]) |
|
|
337 | } |
|
|
338 | |
|
|
339 | sub load($) { |
246 | my ($path) = @_; |
340 | my ($path) = @_; |
247 | |
341 | |
248 | $_IMG_CACHE{$path} || do { |
342 | $_IMG_CACHE{$path} || do { |
249 | my $img = $self->new_img_from_file ($path); |
343 | my $img = load_uc $path; |
250 | Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); |
344 | Scalar::Util::weaken ($_IMG_CACHE{$path} = $img); |
251 | $img |
345 | $img |
252 | } |
346 | } |
253 | } |
347 | } |
254 | |
348 | |
255 | sub load($) { |
|
|
256 | my ($path) = @_; |
|
|
257 | |
|
|
258 | $new->{load}{$path} = $old->{load}{$path} || load_uc $path; |
|
|
259 | } |
|
|
260 | |
|
|
261 | =item root |
349 | =item root |
262 | |
350 | |
263 | Returns the root window pixmap, that is, hopefully, the background image |
351 | Returns the root window pixmap, that is, hopefully, the background image |
264 | of your screen. The image is set to extend mode. |
352 | of your screen. |
265 | |
353 | |
266 | This function makes your expression root sensitive, that means it will be |
354 | This function makes your expression root sensitive, that means it will be |
267 | reevaluated when the bg image changes. |
355 | reevaluated when the bg image changes. |
268 | |
356 | |
269 | =cut |
357 | =cut |
270 | |
358 | |
271 | sub root() { |
359 | sub root() { |
272 | $new->{rootpmap_sensitive} = 1; |
360 | $frame->[FR_AGAIN]{rootpmap} = 1; |
273 | $self->new_img_from_root |
361 | $self->new_img_from_root |
274 | } |
362 | } |
275 | |
363 | |
276 | =item solid $colour |
364 | =item solid $colour |
277 | |
365 | |
… | |
… | |
286 | =cut |
374 | =cut |
287 | |
375 | |
288 | sub solid($;$$) { |
376 | sub solid($;$$) { |
289 | my $colour = pop; |
377 | my $colour = pop; |
290 | |
378 | |
291 | my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); |
379 | my $img = $self->new_img (urxvt::PictStandardARGB32, 0, 0, $_[0] || 1, $_[1] || 1); |
292 | $img->fill ($colour); |
380 | $img->fill ($colour); |
293 | $img |
381 | $img |
294 | } |
382 | } |
295 | |
383 | |
296 | =item clone $img |
384 | =item clone $img |
… | |
… | |
302 | |
390 | |
303 | sub clone($) { |
391 | sub clone($) { |
304 | $_[0]->clone |
392 | $_[0]->clone |
305 | } |
393 | } |
306 | |
394 | |
|
|
395 | =item merge $img ... |
|
|
396 | |
|
|
397 | Takes any number of images and merges them together, creating a single |
|
|
398 | image containing them all. The tiling mode of the first image is used as |
|
|
399 | the tiling mode of the resulting image. |
|
|
400 | |
|
|
401 | This function is called automatically when an expression returns multiple |
|
|
402 | images. |
|
|
403 | |
|
|
404 | =cut |
|
|
405 | |
|
|
406 | sub merge(@) { |
|
|
407 | return $_[0] unless $#_; |
|
|
408 | |
|
|
409 | # rather annoyingly clumsy, but optimisation is for another time |
|
|
410 | |
|
|
411 | my $x0 = +1e9; |
|
|
412 | my $y0 = +1e9; |
|
|
413 | my $x1 = -1e9; |
|
|
414 | my $y1 = -1e9; |
|
|
415 | |
|
|
416 | for (@_) { |
|
|
417 | my ($x, $y, $w, $h) = $_->geometry; |
|
|
418 | |
|
|
419 | $x0 = $x if $x0 > $x; |
|
|
420 | $y0 = $y if $y0 > $y; |
|
|
421 | |
|
|
422 | $x += $w; |
|
|
423 | $y += $h; |
|
|
424 | |
|
|
425 | $x1 = $x if $x1 < $x; |
|
|
426 | $y1 = $y if $y1 < $y; |
|
|
427 | } |
|
|
428 | |
|
|
429 | my $base = $self->new_img (urxvt::PictStandardARGB32, $x0, $y0, $x1 - $x0, $y1 - $y0); |
|
|
430 | $base->repeat_mode ($_[0]->repeat_mode); |
|
|
431 | $base->fill ([0, 0, 0, 0]); |
|
|
432 | |
|
|
433 | $base->draw ($_) |
|
|
434 | for @_; |
|
|
435 | |
|
|
436 | $base |
|
|
437 | } |
|
|
438 | |
|
|
439 | =back |
|
|
440 | |
307 | =head2 TILING MODES |
441 | =head2 TILING MODES |
308 | |
442 | |
309 | 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 |
310 | 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. |
311 | |
445 | |
312 | =over 4 |
446 | =over |
313 | |
447 | |
314 | =item tile $img |
448 | =item tile $img |
315 | |
449 | |
316 | 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 |
317 | 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. |
… | |
… | |
392 | dimensions. They are not (Perl-) variables, they just return stuff that |
526 | dimensions. They are not (Perl-) variables, they just return stuff that |
393 | 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 |
394 | example using C<TW> (terminal width) means your expression is evaluated |
528 | example using C<TW> (terminal width) means your expression is evaluated |
395 | again when the terminal is resized. |
529 | again when the terminal is resized. |
396 | |
530 | |
397 | =over 4 |
531 | =over |
398 | |
532 | |
399 | =item TX |
533 | =item TX |
400 | |
534 | |
401 | =item TY |
535 | =item TY |
402 | |
536 | |
403 | Return the X and Y coordinates of the terminal window (the terminal |
537 | Return the X and Y coordinates of the terminal window (the terminal |
404 | window is the full window by default, and the character area only when in |
538 | window is the full window by default, and the character area only when in |
405 | border-respect mode). |
539 | border-respect mode). |
406 | |
540 | |
407 | Using these functions make your expression sensitive to window moves. |
541 | Using these functions makes your expression sensitive to window moves. |
408 | |
542 | |
409 | These functions are mainly useful to align images to the root window. |
543 | These functions are mainly useful to align images to the root window. |
410 | |
544 | |
411 | Example: load an image and align it so it looks as if anchored to the |
545 | Example: load an image and align it so it looks as if anchored to the |
412 | background. |
546 | background (that's exactly what C<rootalign> does btw.): |
413 | |
547 | |
414 | move -TX, -TY, load "mybg.png" |
548 | move -TX, -TY, keep { load "mybg.png" } |
415 | |
549 | |
416 | =item TW |
550 | =item TW |
|
|
551 | |
|
|
552 | =item TH |
417 | |
553 | |
418 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
554 | Return the width (C<TW>) and height (C<TH>) of the terminal window (the |
419 | terminal window is the full window by default, and the character area only |
555 | terminal window is the full window by default, and the character area only |
420 | when in border-respect mode). |
556 | when in border-respect mode). |
421 | |
557 | |
422 | Using these functions make your expression sensitive to window resizes. |
558 | Using these functions makes your expression sensitive to window resizes. |
423 | |
559 | |
424 | These functions are mainly useful to scale images, or to clip images to |
560 | These functions are mainly useful to scale images, or to clip images to |
425 | the window size to conserve memory. |
561 | the window size to conserve memory. |
426 | |
562 | |
427 | Example: take the screen background, clip it to the window size, blur it a |
563 | Example: take the screen background, clip it to the window size, blur it a |
428 | bit, align it to the window position and use it as background. |
564 | bit, align it to the window position and use it as background. |
429 | |
565 | |
430 | clip move -TX, -TY, blur 5, root |
566 | clip move -TX, -TY, keep { blur 5, root } |
431 | |
567 | |
432 | =cut |
568 | =item FOCUS |
433 | |
569 | |
434 | sub TX() { $new->{position_sensitive} = 1; $x } |
570 | Returns a boolean indicating whether the terminal window has keyboard |
435 | sub TY() { $new->{position_sensitive} = 1; $y } |
571 | focus, in which case it returns true. |
436 | sub TW() { $new->{size_sensitive} = 1; $w } |
572 | |
437 | sub TH() { $new->{size_sensitive} = 1; $h } |
573 | Using this function makes your expression sensitive to focus changes. |
|
|
574 | |
|
|
575 | A common use case is to fade the background image when the terminal loses |
|
|
576 | focus, often together with the C<-fade> command line option. In fact, |
|
|
577 | there is a special function for just that use case: C<focus_fade>. |
|
|
578 | |
|
|
579 | Example: use two entirely different background images, depending on |
|
|
580 | whether the window has focus. |
|
|
581 | |
|
|
582 | FOCUS ? keep { load "has_focus.jpg" } : keep { load "no_focus.jpg" } |
|
|
583 | |
|
|
584 | =cut |
|
|
585 | |
|
|
586 | sub TX () { $frame->[FR_AGAIN]{position} = 1; $x } |
|
|
587 | sub TY () { $frame->[FR_AGAIN]{position} = 1; $y } |
|
|
588 | sub TW () { $frame->[FR_AGAIN]{size} = 1; $w } |
|
|
589 | sub TH () { $frame->[FR_AGAIN]{size} = 1; $h } |
|
|
590 | sub FOCUS() { $frame->[FR_AGAIN]{focus} = 1; $focus } |
438 | |
591 | |
439 | =item now |
592 | =item now |
440 | |
593 | |
441 | Returns the current time as (fractional) seconds since the epoch. |
594 | Returns the current time as (fractional) seconds since the epoch. |
442 | |
595 | |
… | |
… | |
449 | C<$seconds> seconds. |
602 | C<$seconds> seconds. |
450 | |
603 | |
451 | Example: load some image and rotate it according to the time of day (as if it were |
604 | Example: load some image and rotate it according to the time of day (as if it were |
452 | the hour pointer of a clock). Update this image every minute. |
605 | the hour pointer of a clock). Update this image every minute. |
453 | |
606 | |
|
|
607 | again 60; |
454 | again 60; rotate 50, 50, (now % 86400) * -720 / 86400, scale load "myclock.png" |
608 | rotate 50, 50, (now % 86400) * -72 / 8640, scale keep { load "myclock.png" } |
455 | |
609 | |
456 | =item counter $seconds |
610 | =item counter $seconds |
457 | |
611 | |
458 | Like C<again>, but also returns an increasing counter value, starting at |
612 | Like C<again>, but also returns an increasing counter value, starting at |
459 | 0, which might be useful for some simple animation effects. |
613 | 0, which might be useful for some simple animation effects. |
… | |
… | |
461 | =cut |
615 | =cut |
462 | |
616 | |
463 | sub now() { urxvt::NOW } |
617 | sub now() { urxvt::NOW } |
464 | |
618 | |
465 | sub again($) { |
619 | sub again($) { |
466 | $new->{again} = $_[0]; |
620 | $frame->[FR_AGAIN]{time} = $_[0]; |
467 | } |
621 | } |
468 | |
622 | |
469 | sub counter($) { |
623 | sub counter($) { |
470 | $new->{again} = $_[0]; |
624 | $frame->[FR_AGAIN]{time} = $_[0]; |
471 | $self->{counter} + 0 |
625 | $frame->[FR_STATE]{counter} + 0 |
472 | } |
626 | } |
473 | |
627 | |
474 | =back |
628 | =back |
475 | |
629 | |
476 | =head2 SHAPE CHANGING OPERATORS |
630 | =head2 SHAPE CHANGING OPERATORS |
477 | |
631 | |
478 | 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. |
479 | |
633 | |
480 | =over 4 |
634 | =over |
481 | |
635 | |
482 | =item clip $img |
636 | =item clip $img |
483 | |
637 | |
484 | =item clip $width, $height, $img |
638 | =item clip $width, $height, $img |
485 | |
639 | |
… | |
… | |
488 | Clips an image to the given rectangle. If the rectangle is outside the |
642 | Clips an image to the given rectangle. If the rectangle is outside the |
489 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
643 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
490 | larger than the image, then the tiling mode defines how the extra pixels |
644 | larger than the image, then the tiling mode defines how the extra pixels |
491 | will be filled. |
645 | will be filled. |
492 | |
646 | |
493 | If C<$x> an C<$y> are missing, then C<0> is assumed for both. |
647 | If C<$x> and C<$y> are missing, then C<0> is assumed for both. |
494 | |
648 | |
495 | If C<$width> and C<$height> are missing, then the window size will be |
649 | If C<$width> and C<$height> are missing, then the window size will be |
496 | assumed. |
650 | assumed. |
497 | |
651 | |
498 | Example: load an image, blur it, and clip it to the window size to save |
652 | Example: load an image, blur it, and clip it to the window size to save |
499 | memory. |
653 | memory. |
500 | |
654 | |
501 | clip blur 10, load "mybg.png" |
655 | clip keep { blur 10, load "mybg.png" } |
502 | |
656 | |
503 | =cut |
657 | =cut |
504 | |
658 | |
505 | sub clip($;$$;$$) { |
659 | sub clip($;$$;$$) { |
506 | my $img = pop; |
660 | my $img = pop; |
… | |
… | |
516 | =item scale $width_factor, $height_factor, $img |
670 | =item scale $width_factor, $height_factor, $img |
517 | |
671 | |
518 | Scales the image by the given factors in horizontal |
672 | Scales the image by the given factors in horizontal |
519 | (C<$width>) and vertical (C<$height>) direction. |
673 | (C<$width>) and vertical (C<$height>) direction. |
520 | |
674 | |
521 | If only one factor is give, it is used for both directions. |
675 | If only one factor is given, it is used for both directions. |
522 | |
676 | |
523 | If no factors are given, scales the image to the window size without |
677 | If no factors are given, scales the image to the window size without |
524 | keeping aspect. |
678 | keeping aspect. |
525 | |
679 | |
526 | =item resize $width, $height, $img |
680 | =item resize $width, $height, $img |
… | |
… | |
600 | the terminal window (or the box specified by C<$width> and C<$height> if |
754 | the terminal window (or the box specified by C<$width> and C<$height> if |
601 | given). |
755 | given). |
602 | |
756 | |
603 | Example: load an image and center it. |
757 | Example: load an image and center it. |
604 | |
758 | |
605 | center pad load "mybg.png" |
759 | center keep { pad load "mybg.png" } |
606 | |
760 | |
607 | =item rootalign $img |
761 | =item rootalign $img |
608 | |
762 | |
609 | Moves the image so that it appears glued to the screen as opposed to the |
763 | Moves the image so that it appears glued to the screen as opposed to the |
610 | window. This gives the illusion of a larger area behind the window. It is |
764 | window. This gives the illusion of a larger area behind the window. It is |
611 | exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the |
765 | exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the |
612 | top left of the screen. |
766 | top left of the screen. |
613 | |
767 | |
614 | Example: load a background image, put it in mirror mode and root align it. |
768 | Example: load a background image, put it in mirror mode and root align it. |
615 | |
769 | |
616 | rootalign mirror load "mybg.png" |
770 | rootalign keep { mirror load "mybg.png" } |
617 | |
771 | |
618 | Example: take the screen background and align it, giving the illusion of |
772 | Example: take the screen background and align it, giving the illusion of |
619 | transparency as long as the window isn't in front of other windows. |
773 | transparency as long as the window isn't in front of other windows. |
620 | |
774 | |
621 | rootalign root |
775 | rootalign root |
… | |
… | |
646 | |
800 | |
647 | sub rootalign($) { |
801 | sub rootalign($) { |
648 | move -TX, -TY, $_[0] |
802 | move -TX, -TY, $_[0] |
649 | } |
803 | } |
650 | |
804 | |
651 | =item rotate $center_x, $center_y, $degrees |
805 | =item rotate $center_x, $center_y, $degrees, $img |
652 | |
806 | |
653 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
807 | Rotates the image clockwise by C<$degrees> degrees, around the point at |
654 | pointer at C<$center_x> and C<$center_y> (specified as factor of image |
808 | C<$center_x> and C<$center_y> (specified as factor of image width/height). |
655 | width/height). |
|
|
656 | |
809 | |
657 | #TODO# new width, height, maybe more operators? |
|
|
658 | |
|
|
659 | Example: rotate the image by 90 degrees |
810 | Example: rotate the image by 90 degrees around its center. |
|
|
811 | |
|
|
812 | rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } |
660 | |
813 | |
661 | =cut |
814 | =cut |
662 | |
815 | |
663 | sub rotate($$$$) { |
816 | sub rotate($$$$) { |
664 | my $img = pop; |
817 | my $img = pop; |
665 | $img->rotate ( |
818 | $img->rotate ( |
666 | $_[0] * $img->w, |
819 | $_[0] * ($img->w + $img->x), |
667 | $_[1] * $img->h, |
820 | $_[1] * ($img->h + $img->y), |
668 | $_[2] * (3.14159265 / 180), |
821 | $_[2] * (3.14159265 / 180), |
669 | ) |
822 | ) |
670 | } |
823 | } |
671 | |
824 | |
672 | =back |
825 | =back |
673 | |
826 | |
674 | =head2 COLOUR MODIFICATIONS |
827 | =head2 COLOUR MODIFICATIONS |
675 | |
828 | |
676 | The following operators change the pixels of the image. |
829 | The following operators change the pixels of the image. |
677 | |
830 | |
678 | =over 4 |
831 | =over |
|
|
832 | |
|
|
833 | =item tint $color, $img |
|
|
834 | |
|
|
835 | Tints the image in the given colour. |
|
|
836 | |
|
|
837 | Example: tint the image red. |
|
|
838 | |
|
|
839 | tint "red", load "rgb.png" |
|
|
840 | |
|
|
841 | Example: the same, but specify the colour by component. |
|
|
842 | |
|
|
843 | tint [1, 0, 0], load "rgb.png" |
|
|
844 | |
|
|
845 | =cut |
|
|
846 | |
|
|
847 | sub tint($$) { |
|
|
848 | $_[1]->tint ($_[0]) |
|
|
849 | } |
|
|
850 | |
|
|
851 | =item shade $factor, $img |
|
|
852 | |
|
|
853 | Shade the image by the given factor. |
|
|
854 | |
|
|
855 | =cut |
|
|
856 | |
|
|
857 | sub shade($$) { |
|
|
858 | $_[1]->shade ($_[0]) |
|
|
859 | } |
679 | |
860 | |
680 | =item contrast $factor, $img |
861 | =item contrast $factor, $img |
681 | |
862 | |
682 | =item contrast $r, $g, $b, $img |
863 | =item contrast $r, $g, $b, $img |
683 | |
864 | |
… | |
… | |
713 | latter in a white picture. |
894 | latter in a white picture. |
714 | |
895 | |
715 | Due to idiosyncrasies in the underlying XRender extension, biases less |
896 | Due to idiosyncrasies in the underlying XRender extension, biases less |
716 | than zero can be I<very> slow. |
897 | than zero can be I<very> slow. |
717 | |
898 | |
|
|
899 | You can also try the experimental(!) C<muladd> operator. |
|
|
900 | |
718 | =cut |
901 | =cut |
719 | |
902 | |
720 | sub contrast($$;$$;$) { |
903 | sub contrast($$;$$;$) { |
721 | my $img = pop; |
904 | my $img = pop; |
722 | my ($r, $g, $b, $a) = @_; |
905 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
737 | $a = 1 if @_ < 4; |
920 | $a = 1 if @_ < 4; |
738 | |
921 | |
739 | $img = $img->clone; |
922 | $img = $img->clone; |
740 | $img->brightness ($r, $g, $b, $a); |
923 | $img->brightness ($r, $g, $b, $a); |
741 | $img |
924 | $img |
|
|
925 | } |
|
|
926 | |
|
|
927 | =item muladd $mul, $add, $img # EXPERIMENTAL |
|
|
928 | |
|
|
929 | First multiplies the pixels by C<$mul>, then adds C<$add>. This can be used |
|
|
930 | to implement brightness and contrast at the same time, with a wider value |
|
|
931 | range than contrast and brightness operators. |
|
|
932 | |
|
|
933 | Due to numerous bugs in XRender implementations, it can also introduce a |
|
|
934 | number of visual artifacts. |
|
|
935 | |
|
|
936 | Example: increase contrast by a factor of C<$c> without changing image |
|
|
937 | brightness too much. |
|
|
938 | |
|
|
939 | muladd $c, (1 - $c) * 0.5, $img |
|
|
940 | |
|
|
941 | =cut |
|
|
942 | |
|
|
943 | sub muladd($$$) { |
|
|
944 | $_[2]->muladd ($_[0], $_[1]) |
742 | } |
945 | } |
743 | |
946 | |
744 | =item blur $radius, $img |
947 | =item blur $radius, $img |
745 | |
948 | |
746 | =item blur $radius_horz, $radius_vert, $img |
949 | =item blur $radius_horz, $radius_vert, $img |
… | |
… | |
758 | sub blur($$;$) { |
961 | sub blur($$;$) { |
759 | my $img = pop; |
962 | my $img = pop; |
760 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
963 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
761 | } |
964 | } |
762 | |
965 | |
|
|
966 | =item focus_fade $img |
|
|
967 | |
|
|
968 | =item focus_fade $factor, $img |
|
|
969 | |
|
|
970 | =item focus_fade $factor, $color, $img |
|
|
971 | |
|
|
972 | Fades the image by the given factor (and colour) when focus is lost (the |
|
|
973 | same as the C<-fade>/C<-fadecolor> command line options, which also supply |
|
|
974 | the default values for C<factor> and C<$color>. Unlike with C<-fade>, the |
|
|
975 | C<$factor> is a real value, not a percentage value (that is, 0..1, not |
|
|
976 | 0..100). |
|
|
977 | |
|
|
978 | Example: do the right thing when focus fading is requested. |
|
|
979 | |
|
|
980 | focus_fade load "mybg.jpg"; |
|
|
981 | |
|
|
982 | =cut |
|
|
983 | |
|
|
984 | sub focus_fade($;$$) { |
|
|
985 | my $img = pop; |
|
|
986 | |
|
|
987 | return $img |
|
|
988 | if FOCUS; |
|
|
989 | |
|
|
990 | my $fade = @_ >= 1 ? $_[0] : defined $self->resource ("fade") ? $self->resource ("fade") * 0.01 : 0; |
|
|
991 | my $color = @_ >= 2 ? $_[1] : $self->resource ("color+" . urxvt::Color_fade); |
|
|
992 | |
|
|
993 | $img = $img->tint ($color) if $color ne "rgb:00/00/00"; |
|
|
994 | $img = $img->muladd (1 - $fade, 0) if $fade; |
|
|
995 | |
|
|
996 | $img |
|
|
997 | } |
|
|
998 | |
763 | =back |
999 | =back |
764 | |
1000 | |
765 | =head2 OTHER STUFF |
1001 | =head2 OTHER STUFF |
766 | |
1002 | |
767 | Anything that didn't fit any of the other categories, even after appliyng |
1003 | Anything that didn't fit any of the other categories, even after applying |
768 | force and closing our eyes. |
1004 | force and closing our eyes. |
769 | |
1005 | |
770 | =over 4 |
1006 | =over |
771 | |
1007 | |
772 | =item once { ... } |
1008 | =item keep { ... } |
773 | |
1009 | |
774 | This function 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 |
775 | statements enclosed by braces. |
1011 | statements enclosed by braces. |
776 | |
1012 | |
777 | The trick is that this code block is only evaluated once - future calls |
1013 | The trick is that this code block is only evaluated when the outcome |
778 | will simply return the original image (yes, it should only be used with |
1014 | changes - on other calls the C<keep> simply returns the image it computed |
779 | images). |
1015 | previously (yes, it should only be used with images). Or in other words, |
|
|
1016 | C<keep> I<caches> the result of the code block so it doesn't need to be |
|
|
1017 | computed again. |
780 | |
1018 | |
781 | This can be extremely useful to avoid redoign the same slow operations |
1019 | This can be extremely useful to avoid redoing slow operations - for |
782 | again and again- for example, if your background expression takes the root |
1020 | example, if your background expression takes the root background, blurs it |
783 | background, blurs it and then root-aligns it it would have to blur the |
1021 | and then root-aligns it it would have to blur the root background on every |
784 | root background on every window move or resize. |
1022 | window move or resize. |
785 | |
1023 | |
|
|
1024 | Another example is C<load>, which can be quite slow. |
|
|
1025 | |
|
|
1026 | In fact, urxvt itself encloses the whole expression in some kind of |
|
|
1027 | C<keep> block so it only is reevaluated as required. |
|
|
1028 | |
786 | Putting the blur into a C<once> block will make sure the blur is only done |
1029 | Putting the blur into a C<keep> block will make sure the blur is only done |
787 | once: |
1030 | once, while the C<rootalign> is still done each time the window moves. |
788 | |
1031 | |
789 | rootlign once { blur 10, root } |
1032 | rootalign keep { blur 10, root } |
790 | |
1033 | |
791 | This leaves the question of how to force reevaluation of the block, in |
1034 | This leaves the question of how to force reevaluation of the block, |
792 | case the root background changes: Right now, all once blocks forget that |
1035 | in case the root background changes: If expression inside the block |
793 | they ahve been executed before each time the root background changes (if |
1036 | is sensitive to some event (root background changes, window geometry |
794 | the expression is sensitive to that) or when C<once_again> is called. |
1037 | changes), then it will be reevaluated automatically as needed. |
795 | |
|
|
796 | =item once_again |
|
|
797 | |
|
|
798 | Resets all C<once> block as if they had never been called, i.e. on the |
|
|
799 | next call they will be reevaluated again. |
|
|
800 | |
|
|
801 | =cut |
|
|
802 | |
|
|
803 | sub once(&) { |
|
|
804 | $_ONCE_CACHE{$_[0]+0} ||= $_[0]() |
|
|
805 | } |
|
|
806 | |
|
|
807 | sub once_again() { |
|
|
808 | %_ONCE_CACHE = (); |
|
|
809 | } |
|
|
810 | |
1038 | |
811 | =back |
1039 | =back |
812 | |
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 |
|
|
1186 | |
|
|
1187 | =cut |
|
|
1188 | |
|
|
1189 | sub keep(&) { |
|
|
1190 | my $id = $_[0]+0; |
|
|
1191 | |
|
|
1192 | local $frame = $self->{frame_cache}{$id} ||= [$frame]; |
|
|
1193 | |
|
|
1194 | unless ($frame->[FR_CACHE]) { |
|
|
1195 | $frame->[FR_CACHE] = [ $_[0]() ]; |
|
|
1196 | |
|
|
1197 | my $self = $self; |
|
|
1198 | my $frame = $frame; |
|
|
1199 | Scalar::Util::weaken $frame; |
|
|
1200 | $self->compile_frame ($frame, sub { |
|
|
1201 | # clear this frame cache, also for all parents |
|
|
1202 | for (my $frame = $frame; $frame; $frame = $frame->[0]) { |
|
|
1203 | undef $frame->[FR_CACHE]; |
|
|
1204 | } |
|
|
1205 | |
|
|
1206 | $self->recalculate; |
|
|
1207 | }); |
|
|
1208 | }; |
|
|
1209 | |
|
|
1210 | # in scalar context we always return the first original result, which |
|
|
1211 | # is not quite how perl works. |
|
|
1212 | wantarray |
|
|
1213 | ? @{ $frame->[FR_CACHE] } |
|
|
1214 | : $frame->[FR_CACHE][0] |
|
|
1215 | } |
|
|
1216 | |
|
|
1217 | # sub keep_clear() { |
|
|
1218 | # delete $self->{frame_cache}; |
|
|
1219 | # } |
|
|
1220 | |
|
|
1221 | =back |
|
|
1222 | |
813 | =cut |
1223 | =cut |
814 | |
1224 | |
815 | } |
1225 | } |
816 | |
1226 | |
817 | sub parse_expr { |
1227 | sub parse_expr { |
818 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
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 { |
|
|
1236 | $expr = eval |
|
|
1237 | "sub {\n" |
|
|
1238 | . "package urxvt::bgdsl;\n" |
|
|
1239 | . "#line 0 'background expression'\n" |
|
|
1240 | . "$expr\n" |
|
|
1241 | . "}"; |
819 | die if $@; |
1242 | die if $@; |
|
|
1243 | } |
|
|
1244 | |
820 | $expr |
1245 | $expr |
821 | } |
1246 | } |
822 | |
1247 | |
823 | # compiles a parsed expression |
1248 | # compiles a parsed expression |
824 | sub set_expr { |
1249 | sub set_expr { |
825 | my ($self, $expr) = @_; |
1250 | my ($self, $expr) = @_; |
826 | |
1251 | |
|
|
1252 | $self->{root} = []; # the outermost frame |
827 | $self->{expr} = $expr; |
1253 | $self->{expr} = $expr; |
828 | $self->recalculate; |
1254 | $self->recalculate; |
|
|
1255 | } |
|
|
1256 | |
|
|
1257 | # takes a hash of sensitivity indicators and installs watchers |
|
|
1258 | sub compile_frame { |
|
|
1259 | my ($self, $frame, $cb) = @_; |
|
|
1260 | |
|
|
1261 | my $state = $frame->[urxvt::bgdsl::FR_STATE] ||= {}; |
|
|
1262 | my $again = $frame->[urxvt::bgdsl::FR_AGAIN]; |
|
|
1263 | |
|
|
1264 | # don't keep stuff alive |
|
|
1265 | Scalar::Util::weaken $state; |
|
|
1266 | |
|
|
1267 | if ($again->{nested}) { |
|
|
1268 | $state->{nested} = 1; |
|
|
1269 | } else { |
|
|
1270 | delete $state->{nested}; |
|
|
1271 | } |
|
|
1272 | |
|
|
1273 | if (my $interval = $again->{time}) { |
|
|
1274 | $state->{time} = [$interval, urxvt::timer->new->after ($interval)->interval ($interval)] |
|
|
1275 | if $state->{time}[0] != $interval; |
|
|
1276 | |
|
|
1277 | # callback *might* have changed, although we could just rule that out |
|
|
1278 | $state->{time}[1]->cb (sub { |
|
|
1279 | ++$state->{counter}; |
|
|
1280 | $cb->(); |
|
|
1281 | }); |
|
|
1282 | } else { |
|
|
1283 | delete $state->{time}; |
|
|
1284 | } |
|
|
1285 | |
|
|
1286 | if ($again->{position}) { |
|
|
1287 | $state->{position} = $self->on (position_change => $cb); |
|
|
1288 | } else { |
|
|
1289 | delete $state->{position}; |
|
|
1290 | } |
|
|
1291 | |
|
|
1292 | if ($again->{size}) { |
|
|
1293 | $state->{size} = $self->on (size_change => $cb); |
|
|
1294 | } else { |
|
|
1295 | delete $state->{size}; |
|
|
1296 | } |
|
|
1297 | |
|
|
1298 | if ($again->{rootpmap}) { |
|
|
1299 | $state->{rootpmap} = $self->on (rootpmap_change => $cb); |
|
|
1300 | } else { |
|
|
1301 | delete $state->{rootpmap}; |
|
|
1302 | } |
|
|
1303 | |
|
|
1304 | if ($again->{focus}) { |
|
|
1305 | $state->{focus} = $self->on (focus_in => $cb, focus_out => $cb); |
|
|
1306 | } else { |
|
|
1307 | delete $state->{focus}; |
|
|
1308 | } |
829 | } |
1309 | } |
830 | |
1310 | |
831 | # evaluate the current bg expression |
1311 | # evaluate the current bg expression |
832 | sub recalculate { |
1312 | sub recalculate { |
833 | my ($arg_self) = @_; |
1313 | my ($arg_self) = @_; |
… | |
… | |
841 | return; |
1321 | return; |
842 | } |
1322 | } |
843 | |
1323 | |
844 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
1324 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
845 | |
1325 | |
|
|
1326 | unless ($arg_self->has_render) { |
|
|
1327 | warn "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
|
|
1328 | return; |
|
|
1329 | } |
|
|
1330 | |
846 | # set environment to evaluate user expression |
1331 | # set environment to evaluate user expression |
847 | |
1332 | |
848 | local $self = $arg_self; |
1333 | local $self = $arg_self; |
849 | |
|
|
850 | local $HOME = $ENV{HOME}; |
1334 | local $HOME = $ENV{HOME}; |
851 | local $old = $self->{state}; |
1335 | local $frame = $self->{root}; |
852 | local $new = my $state = $self->{state} = {}; |
|
|
853 | |
1336 | |
854 | ($x, $y, $w, $h) = |
|
|
855 | $self->background_geometry ($self->{border}); |
1337 | ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); |
|
|
1338 | $focus = $self->focus; |
856 | |
1339 | |
857 | # evaluate user expression |
1340 | # evaluate user expression |
858 | |
1341 | |
859 | my $img = eval { $self->{expr}->() }; |
1342 | my @img = eval { $self->{expr}->() }; |
860 | warn $@ if $@;#d# |
1343 | die $@ if $@; |
861 | die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img"; |
1344 | die "background-expr did not return anything.\n" unless @img; |
862 | |
1345 | |
863 | $state->{size_sensitive} = 1 |
1346 | if ($img[0]) { |
|
|
1347 | die "background-expr: expected image(s), got something else.\n" |
|
|
1348 | if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; |
|
|
1349 | |
|
|
1350 | my $img = urxvt::bgdsl::merge @img; |
|
|
1351 | |
|
|
1352 | $frame->[urxvt::bgdsl::FR_AGAIN]{size} = 1 |
864 | if $img->repeat_mode != urxvt::RepeatNormal; |
1353 | if $img->repeat_mode != urxvt::RepeatNormal; |
865 | |
1354 | |
866 | # if the expression is sensitive to external events, prepare reevaluation then |
1355 | # if the expression is sensitive to external events, prepare reevaluation then |
|
|
1356 | $self->compile_frame ($frame, sub { $arg_self->recalculate }); |
867 | |
1357 | |
868 | my $repeat; |
1358 | # clear stuff we no longer need |
869 | |
1359 | |
870 | if (my $again = $state->{again}) { |
1360 | # unless (%{ $frame->[FR_STATE] }) { |
871 | $repeat = 1; |
1361 | # delete $self->{state}; |
872 | my $self = $self; |
1362 | # delete $self->{expr}; |
873 | $state->{timer} = $again == $old->{again} |
|
|
874 | ? $old->{timer} |
|
|
875 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
|
|
876 | ++$self->{counter}; |
|
|
877 | $self->recalculate |
|
|
878 | }); |
|
|
879 | } |
1363 | # } |
880 | |
1364 | |
881 | if (delete $state->{position_sensitive}) { |
1365 | # set background pixmap |
882 | $repeat = 1; |
1366 | |
883 | $self->enable (position_change => sub { $_[0]->recalculate }); |
1367 | $self->set_background ($img, $self->{border}); |
884 | } else { |
1368 | } else { |
885 | $self->disable ("position_change"); |
1369 | $self->clr_background; |
886 | } |
1370 | } |
887 | |
1371 | |
888 | if (delete $state->{size_sensitive}) { |
|
|
889 | $repeat = 1; |
|
|
890 | $self->enable (size_change => sub { $_[0]->recalculate }); |
|
|
891 | } else { |
|
|
892 | $self->disable ("size_change"); |
|
|
893 | } |
|
|
894 | |
|
|
895 | if (delete $state->{rootpmap_sensitive}) { |
|
|
896 | $repeat = 1; |
|
|
897 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
|
|
898 | } else { |
|
|
899 | $self->disable ("rootpmap_change"); |
|
|
900 | } |
|
|
901 | |
|
|
902 | # clear stuff we no longer need |
|
|
903 | |
|
|
904 | %$old = (); |
|
|
905 | |
|
|
906 | unless ($repeat) { |
|
|
907 | delete $self->{state}; |
|
|
908 | delete $self->{expr}; |
|
|
909 | } |
|
|
910 | |
|
|
911 | # set background pixmap |
|
|
912 | |
|
|
913 | $self->set_background ($img, $self->{border}); |
|
|
914 | $self->scr_recolour (0); |
1372 | $self->scr_recolor (0); |
915 | $self->want_refresh; |
1373 | $self->want_refresh; |
916 | } |
1374 | } |
917 | |
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. does not |
|
|
1454 | # support binary NULs in string. |
|
|
1455 | sub q0 { |
|
|
1456 | (my $str = shift) =~ s/\x00//g; # make sure there really aren't any embedded NULs |
|
|
1457 | "q\x00$str\x00" |
|
|
1458 | } |
|
|
1459 | |
|
|
1460 | sub old_bg_expr { |
|
|
1461 | my ($self) = @_; |
|
|
1462 | |
|
|
1463 | my $expr; |
|
|
1464 | |
|
|
1465 | my $bg_opts = $self->{bg_opts}; |
|
|
1466 | |
|
|
1467 | if ($bg_opts->{root} =~ /^\s*(?:true|yes|on|1)\s*$/i) { |
|
|
1468 | $expr .= "tile ("; |
|
|
1469 | |
|
|
1470 | my $shade = $bg_opts->{shade}; |
|
|
1471 | |
|
|
1472 | if ($shade) { |
|
|
1473 | $shade = List::Util::min $shade, 200; |
|
|
1474 | $shade = List::Util::max $shade, -100; |
|
|
1475 | $shade = 200 - (100 + $shade) if $shade < 0; |
|
|
1476 | |
|
|
1477 | $shade = $shade * 0.01 - 1; |
|
|
1478 | $expr .= "shade $shade, "; |
|
|
1479 | } |
|
|
1480 | |
|
|
1481 | my $tint = $bg_opts->{tint}; |
|
|
1482 | |
|
|
1483 | if ($tint) { |
|
|
1484 | $tint = q0 $tint; |
|
|
1485 | $expr .= "tint $tint,"; |
|
|
1486 | } |
|
|
1487 | |
|
|
1488 | my $blur = $bg_opts->{blur}; |
|
|
1489 | |
|
|
1490 | if ($blur and $blur =~ /^ =? ([0-9]+)? (?:[xX] ([0-9]+))? $/x) { |
|
|
1491 | my $hr = defined $1 ? $1 : 1; |
|
|
1492 | my $vr = defined $2 ? $2 : $hr; |
|
|
1493 | |
|
|
1494 | if ($hr != 0 and $vr != 0) { |
|
|
1495 | $expr .= "blur $hr, $vr, "; |
|
|
1496 | } |
|
|
1497 | } |
|
|
1498 | |
|
|
1499 | $expr .= "rootalign root)"; |
|
|
1500 | } |
|
|
1501 | |
|
|
1502 | if ($bg_opts->{path}) { |
|
|
1503 | my $file_expr; |
|
|
1504 | my $h_scale = $bg_opts->{h_scale} * 0.01; |
|
|
1505 | my $v_scale = $bg_opts->{v_scale} * 0.01; |
|
|
1506 | my $h_align = $bg_opts->{h_align} * 0.01; |
|
|
1507 | my $v_align = $bg_opts->{v_align} * 0.01; |
|
|
1508 | |
|
|
1509 | if (!$bg_opts->{tile}) { |
|
|
1510 | $file_expr .= "pad ("; |
|
|
1511 | } else { |
|
|
1512 | $file_expr .= "tile ("; |
|
|
1513 | } |
|
|
1514 | |
|
|
1515 | if ($bg_opts->{root_align}) { |
|
|
1516 | $file_expr .= "rootalign "; |
|
|
1517 | } else { |
|
|
1518 | $file_expr .= "align $h_align, $v_align, "; |
|
|
1519 | } |
|
|
1520 | |
|
|
1521 | if ($h_scale != 0 and $v_scale != 0) { |
|
|
1522 | my $op = $bg_opts->{keep_aspect} ? "fit" : "resize"; |
|
|
1523 | $file_expr .= "$op TW * $h_scale, TH * $v_scale, "; |
|
|
1524 | } |
|
|
1525 | |
|
|
1526 | my $path = q0 $bg_opts->{path}; |
|
|
1527 | |
|
|
1528 | $file_expr .= "keep { load $path })"; |
|
|
1529 | |
|
|
1530 | if ($expr) { |
|
|
1531 | $expr .= ", tint (\"[50]white\", $file_expr)"; |
|
|
1532 | } else { |
|
|
1533 | $expr = $file_expr; |
|
|
1534 | } |
|
|
1535 | } |
|
|
1536 | |
|
|
1537 | $expr |
|
|
1538 | } |
|
|
1539 | |
|
|
1540 | sub on_osc_seq { |
|
|
1541 | my ($self, $op, $arg) = @_; |
|
|
1542 | |
|
|
1543 | $self->{bg_opts} or return; |
|
|
1544 | |
|
|
1545 | $op =~ /^(?:20|705)$/ or return; |
|
|
1546 | |
|
|
1547 | if ($op eq "20") { |
|
|
1548 | if ($arg eq "?") { |
|
|
1549 | my $h_scale = $self->{bg_opts}->{h_scale}; |
|
|
1550 | my $v_scale = $self->{bg_opts}->{v_scale}; |
|
|
1551 | my $h_align = $self->{bg_opts}->{h_align}; |
|
|
1552 | my $v_align = $self->{bg_opts}->{v_align}; |
|
|
1553 | $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007"); |
|
|
1554 | } else { |
|
|
1555 | $self->old_bg_opts ($arg); |
|
|
1556 | my $expr = $self->old_bg_expr; |
|
|
1557 | $self->set_expr (parse_expr $expr) if $expr; |
|
|
1558 | } |
|
|
1559 | } elsif ($op eq "705") { |
|
|
1560 | $self->{bg_opts}->{tint} = $arg; |
|
|
1561 | my $expr = $self->old_bg_expr; |
|
|
1562 | $self->set_expr (parse_expr $expr) if $expr; |
|
|
1563 | } |
|
|
1564 | |
|
|
1565 | 1 |
|
|
1566 | } |
|
|
1567 | |
|
|
1568 | sub find_resource { |
|
|
1569 | my ($self, $res, $opt) = @_; |
|
|
1570 | |
|
|
1571 | my $v = $self->x_resource ($opt); |
|
|
1572 | $v = $self->x_resource ($res) unless defined $v; |
|
|
1573 | |
|
|
1574 | $v |
|
|
1575 | } |
|
|
1576 | |
918 | sub on_start { |
1577 | sub on_start { |
919 | my ($self) = @_; |
1578 | my ($self) = @_; |
920 | |
1579 | |
921 | my $expr = $self->x_resource ("%.expr") |
1580 | my $expr = $self->x_resource ("%.expr"); |
922 | or return; |
|
|
923 | |
1581 | |
924 | $self->has_render |
1582 | if (!$expr) { |
925 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
1583 | $self->{bg_opts} = { h_scale => 100, v_scale => 100, |
|
|
1584 | h_align => 50, v_align => 50 }; |
|
|
1585 | |
|
|
1586 | $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh"); |
|
|
1587 | $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint"); |
|
|
1588 | $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr"); |
|
|
1589 | $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr"); |
|
|
1590 | |
|
|
1591 | $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap")); |
|
|
1592 | $expr = $self->old_bg_expr; |
|
|
1593 | } |
926 | |
1594 | |
927 | $self->set_expr (parse_expr $expr); |
1595 | $self->set_expr (parse_expr $expr); |
928 | $self->{border} = $self->x_resource_boolean ("%.border"); |
1596 | $self->{border} = $self->x_resource_boolean ("%.border"); |
929 | |
1597 | |
930 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
1598 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |