ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
(Generate patch)

Comparing rxvt-unicode/src/perl/background (file contents):
Revision 1.6 by root, Tue Jun 5 13:56:42 2012 UTC vs.
Revision 1.42 by root, Sun Jun 10 10:42:19 2012 UTC

1#! perl 1#! perl
2 2
3our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; 3#:META:X_RESOURCE:%.expr:string:background expression
4$EXPR = 'rotate (move (load "/root/pix/das_fette_schwein.jpg", X, Y), W, H, 50, 50, counter 1/60, repeat_mirror)'; 4#:META:X_RESOURCE:%.border.:boolean:respect the terminal border
5#$EXPR = 'blur root, 10, 10'
6#$EXPR = 'blur move (root, -x, -y), 5, 5'
7#resize load "/root/pix/das_fette_schwein.jpg", w, h
8 5
9use Safe; 6#TODO: once, rootalign
10 7
8=head1 NAME
9
10 background - manage terminal background
11
12=head1 SYNOPSIS
13
14 urxvt --background-expr 'background expression'
15 --background-border
16
17=head1 DESCRIPTION
18
19This extension manages the terminal background by creating a picture that
20is behind the text, replacing the normal background colour.
21
22It does so by evaluating a Perl expression that I<calculates> the image on
23the fly, for example, by grabbing the root background or loading a file.
24
25While the full power of Perl is available, the operators have been design
26to be as simple as possible.
27
28For example, to load an image and scale it to the window size, you would
29use:
30
31 urxvt --background-expr 'scale load "/path/to/mybg.png"'
32
33Or specified as a X resource:
34
35 URxvt.background-expr: scale load "/path/to/mybg.png"
36
37=head1 THEORY OF OPERATION
38
39At startup, just before the window is mapped for the first time, the
40expression is evaluated and must yield an image. The image is then
41extended as necessary to cover the whole terminal window, and is set as a
42background pixmap.
43
44If the image contains an alpha channel, then it will be used as-is in
45visuals that support alpha channels (for example, for a compositing
46manager). In other visuals, the terminal background colour will be used to
47replace any transparency.
48
49When the expression relies, directly or indirectly, on the window size,
50position, the root pixmap, or a timer, then it will be remembered. If not,
51then it will be removed.
52
53If any of the parameters that the expression relies on changes (when the
54window is moved or resized, its position or size changes; when the root
55pixmap is replaced by another one the root background changes; or when the
56timer elapses), then the expression will be evaluated again.
57
58For example, an expression such as C<scale load "$HOME/mybg.png"> scales the
59image to the window size, so it relies on the window size and will
60be reevaluated each time it is changed, but not when it moves for
61example. That ensures that the picture always fills the terminal, even
62after it's size changes.
63
64=head2 EXPRESSIONS
65
66Expressions are normal Perl expressions, in fact, they are Perl blocks -
67which means you could use multiple lines and statements:
68
69 again 3600;
70 if (localtime now)[6]) {
71 return scale load "$HOME/weekday.png";
72 } else {
73 return scale load "$HOME/sunday.png";
74 }
75
76This expression gets evaluated once per hour. It will set F<sunday.png> as
77background on Sundays, and F<weekday.png> on all other days.
78
79Fortunately, we expect that most expressions will be much simpler, with
80little Perl knowledge needed.
81
82Basically, you always start with a function that "generates" an image
83object, such as C<load>, which loads an image from disk, or C<root>, which
84returns the root window background image:
85
86 load "$HOME/mypic.png"
87
88The path is usually specified as a quoted string (the exact rules can be
89found in the L<perlop> manpage). The F<$HOME> at the beginning of the
90string is expanded to the home directory.
91
92Then you prepend one or more modifiers or filtering expressions, such as
93C<scale>:
94
95 scale load "$HOME/mypic.png"
96
97Just like a mathematical expression with functions, you should read these
98expressions from right to left, as the C<load> is evaluated first, and
99its result becomes the argument to the C<scale> function.
100
101Many operators also allow some parameters preceding the input image
102that modify its behaviour. For example, C<scale> without any additional
103arguments scales the image to size of the terminal window. If you specify
104an additional argument, it uses it as a percentage:
105
106 scale 200, load "$HOME/mypic.png"
107
108This enlarges the image by a factor of 2 (200%). As you can see, C<scale>
109has now two arguments, the C<200> and the C<load> expression, while
110C<load> only has one argument. Arguments are separated from each other by
111commas.
112
113Scale also accepts two arguments, which are then separate factors for both
114horizontal and vertical dimensions. For example, this halves the image
115width and doubles the image height:
116
117 scale 50, 200, load "$HOME/mypic.png"
118
119Other effects than scalign are also readily available, for exmaple, you can
120tile the image to fill the whole window, instead of resizing it:
121
122 tile load "$HOME/mypic.png"
123
124In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator
125is kind of superfluous.
126
127Another common effect is to mirror the image, so that the same edges touch:
128
129 mirror load "$HOME/mypic.png"
130
131This is also a typical background expression:
132
133 rootalign root
134
135It first takes a snapshot of the screen background image, and then
136moves it to the upper left corner of the screen - the result is
137pseudo-transparency, as the image seems to be static while the window is
138moved around.
139
140=head2 CYCLES AND CACHING
141
142As has been mentioned before, the expression might be evaluated multiple
143times. Each time the expression is reevaluated, a new cycle is said to
144have begun. Many operators cache their results till the next cycle.
145
146For example, the C<load> operator keeps a copy of the image. If it is
147asked to load the same image on the next cycle it will not load it again,
148but return the cached copy.
149
150This only works for one cycle though, so as long as you load the same
151image every time, it will always be cached, but when you load a different
152image, it will forget about the first one.
153
154This allows you to either speed things up by keeping multiple images in
155memory, or comserve memory by loading images more often.
156
157For example, you can keep two images in memory and use a random one like
158this:
159
160 my $img1 = load "img1.png";
161 my $img2 = load "img2.png";
162 (0.5 > rand) ? $img1 : $img2
163
164Since both images are "loaded" every time the expression is evaluated,
165they are always kept in memory. Contrast this version:
166
167 my $path1 = "img1.png";
168 my $path2 = "img2.png";
169 load ((0.5 > rand) ? $path1 : $path2)
170
171Here, a path is selected randomly, and load is only called for one image,
172so keeps only one image in memory. If, on the next evaluation, luck
173decides to use the other path, then it will have to load that image again.
174
175=head1 REFERENCE
176
177=head2 COMMAND LINE SWITCHES
178
179=over 4
180
181=item --background-expr perl-expression
182
183Specifies the Perl expression to evaluate.
184
185=item --background-border
186
187By default, the expression creates an image that fills the full window,
188overwriting borders and any other areas, such as the scrollbar.
189
190Specifying this flag changes the behaviour, so that the image only
191replaces the background of the character area.
192
193=back
194
195=cut
196
197our $HOME;
11our ($bgdsl_self, $old, $new); 198our ($self, $old, $new);
12our ($l, $t, $w, $h); 199our ($x, $y, $w, $h);
200
201# enforce at least this interval between updates
202our $MIN_INTERVAL = 1/100;
13 203
14{ 204{
15 package urxvt::bgdsl; # background language 205 package urxvt::bgdsl; # background language
16 206
17 *repeat_black = \&urxvt::RepeatNone; #TODO wtf 207=head2 PROVIDERS/GENERATORS
18 *repeat_wrap = \&urxvt::RepeatNormal; 208
19 *repeat_pad = \&urxvt::RepeatPad; 209These functions provide an image, by loading it from disk, grabbing it
20 *repeat_mirror = \&urxvt::RepeatReflect; 210from the root screen or by simply generating it. They are used as starting
211points to get an image you can play with.
212
213=over 4
214
215=item load $path
216
217Loads the image at the given C<$path>. The image is set to plane tiling
218mode.
219
220Loaded images will be cached for one cycle.
221
222=cut
21 223
22 sub load($) { 224 sub load($) {
23 my ($path) = @_; 225 my ($path) = @_;
24 226
25 $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path); 227 $new->{load}{$path} = $old->{load}{$path} || $self->new_img_from_file ($path);
26 } 228 }
229
230=item root
231
232Returns the root window pixmap, that is, hopefully, the background image
233of your screen. The image is set to extend mode.
234
235This function makes your expression root sensitive, that means it will be
236reevaluated when the bg image changes.
237
238=cut
27 239
28 sub root() { 240 sub root() {
241 $new->{rootpmap_sensitive} = 1;
29 die "root op not supported, exg, we need you"; 242 die "root op not supported, exg, we need you";
30 } 243 }
31 244
245=item solid $colour
246
247=item solid $width, $height, $colour
248
249Creates a new image and completely fills it with the given colour. The
250image is set to tiling mode.
251
252If C<$width> and C<$height> are omitted, it creates a 1x1 image, which is
253useful for solid backgrounds or for use in filtering effects.
254
255=cut
256
257 sub solid($;$$) {
258 my $colour = pop;
259
260 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1);
261 $img->fill ($colour);
262 $img
263 }
264
265=back
266
267=head2 VARIABLES
268
269The following functions provide variable data such as the terminal window
270dimensions. They are not (Perl-) variables, they jsut return stuff that
271varies. Most of them make your expression sensitive to some events, for
272example using C<TW> (terminal width) means your expression is evaluated
273again when the terminal is resized.
274
275=over 4
276
277=item TX
278
279=item TY
280
281Return the X and Y coordinates of the terminal window (the terminal
282window is the full window by default, and the character area only when in
283border-respect mode).
284
285Using these functions make your expression sensitive to window moves.
286
287These functions are mainly useful to align images to the root window.
288
289Example: load an image and align it so it looks as if anchored to the
290background.
291
292 move -TX, -TY, load "mybg.png"
293
294=item TW
295
296Return the width (C<TW>) and height (C<TH>) of the terminal window (the
297terminal window is the full window by default, and the character area only
298when in border-respect mode).
299
300Using these functions make your expression sensitive to window resizes.
301
302These functions are mainly useful to scale images, or to clip images to
303the window size to conserve memory.
304
305Example: take the screen background, clip it to the window size, blur it a
306bit, align it to the window position and use it as background.
307
308 clip move -TX, -TY, blur 5, root
309
310=cut
311
312 sub TX() { $new->{position_sensitive} = 1; $x }
313 sub TY() { $new->{position_sensitive} = 1; $y }
314 sub TW() { $new->{size_sensitive} = 1; $w }
315 sub TH() { $new->{size_sensitive} = 1; $h }
316
317=item now
318
319Returns the current time as (fractional) seconds since the epoch.
320
321Using this expression does I<not> make your expression sensitive to time,
322but the next two functions do.
323
324=item again $seconds
325
326When this function is used the expression will be reevaluated again in
327C<$seconds> seconds.
328
329Example: load some image and rotate it according to the time of day (as if it were
330the hour pointer of a clock). Update this image every minute.
331
332 again 60; rotate TW, TH, 50, 50, (now % 86400) * -720 / 86400, scale load "myclock.png"
333
334=item counter $seconds
335
336Like C<again>, but also returns an increasing counter value, starting at
3370, which might be useful for some simple animation effects.
338
339=cut
340
341 sub now() { urxvt::NOW }
342
343 sub again($) {
344 $new->{again} = $_[0];
345 }
346
347 sub counter($) {
348 $new->{again} = $_[0];
349 $self->{counter} + 0
350 }
351
352=back
353
354=head2 TILING MODES
355
356The following operators modify the tiling mode of an image, that is, the
357way that pixels outside the image area are painted when the image is used.
358
359=over 4
360
361=item tile $img
362
363Tiles the whole plane with the image and returns this new image - or in
364other words, it returns a copy of the image in plane tiling mode.
365
366Example: load an image and tile it over the background, without
367resizing. The C<tile> call is superfluous because C<load> already defaults
368to tiling mode.
369
370 tile load "mybg.png"
371
372=item mirror $img
373
374Similar to tile, but reflects the image each time it uses a new copy, so
375that top edges always touch top edges, right edges always touch right
376edges and so on (with normal tiling, left edges always touch right edges
377and top always touch bottom edges).
378
379Example: load an image and mirror it over the background, avoiding sharp
380edges at the image borders at the expense of mirroring the image itself
381
382 mirror load "mybg.png"
383
384=item pad $img
385
386Takes an image and modifies it so that all pixels outside the image area
387become transparent. This mode is most useful when you want to place an
388image over another image or the background colour while leaving all
389background pixels outside the image unchanged.
390
391Example: load an image and display it in the upper left corner. The rest
392of the space is left "empty" (transparent or wahtever your compisotr does
393in alpha mode, else background colour).
394
395 pad load "mybg.png"
396
397=item extend $img
398
399Extends the image over the whole plane, using the closest pixel in the
400area outside the image. This mode is mostly useful when you more complex
401filtering operations and want the pixels outside the image to have the
402same values as the pixels near the edge.
403
404Example: just for curiosity, how does this pixel extension stuff work?
405
406 extend move 50, 50, load "mybg.png"
407
408=cut
409
410 sub pad($) {
411 my $img = $_[0]->clone;
412 $img->repeat_mode (urxvt::RepeatNone);
413 $img
414 }
415
416 sub tile($) {
417 my $img = $_[0]->clone;
418 $img->repeat_mode (urxvt::RepeatNormal);
419 $img
420 }
421
422 sub mirror($) {
423 my $img = $_[0]->clone;
424 $img->repeat_mode (urxvt::RepeatReflect);
425 $img
426 }
427
428 sub extend($) {
429 my $img = $_[0]->clone;
430 $img->repeat_mode (urxvt::RepeatPad);
431 $img
432 }
433
434=back
435
436=head2 PIXEL OPERATORS
437
438The following operators modify the image pixels in various ways.
439
440=over 4
441
442=item clone $img
443
444Returns an exact copy of the image.
445
446=cut
447
32# sub clone($) { 448 sub clone($) {
33# $_[0]->clone 449 $_[0]->clone
34# } 450 }
35 451
36 sub subrect($$$$$;$) { 452=item clip $img
37 $_[0]->sub_rect ($_[1], $_[2], $_[3], $_[4], $_[5]) 453
454=item clip $width, $height, $img
455
456=item clip $x, $y, $width, $height, $img
457
458Clips an image to the given rectangle. If the rectangle is outside the
459image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is
460larger than the image, then the tiling mode defines how the extra pixels
461will be filled.
462
463If C<$x> an C<$y> are missing, then C<0> is assumed for both.
464
465If C<$width> and C<$height> are missing, then the window size will be
466assumed.
467
468Example: load an image, blur it, and clip it to the window size to save
469memory.
470
471 clip blur 10, load "mybg.png"
472
473=cut
474
475 sub clip($;$$;$$) {
476 my $img = pop;
477 my $h = pop || TH;
478 my $w = pop || TW;
479 $img->sub_rect ($_[0], $_[1], $w, $h)
480 }
481
482=item scale $img
483
484=item scale $size_percent, $img
485
486=item scale $width_percent, $height_percent, $img
487
488Scales the image by the given percentages in horizontal
489(C<$width_percent>) and vertical (C<$height_percent>) direction.
490
491If only one percentage is give, it is used for both directions.
492
493If no percentages are given, scales the image to the window size without
494keeping aspect.
495
496=item resize $width, $height, $img
497
498Resizes the image to exactly C<$width> times C<$height> pixels.
499
500=cut
501
502#TODO: maximise, maximise_fill?
503
504 sub scale($;$;$) {
505 my $img = pop;
506
507 @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01)
508 : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01)
509 : $img->scale (TW, TH)
38 } 510 }
39 511
40 sub resize($$$) { 512 sub resize($$$) {
41 $_[0]->scale ($_[1], $_[2]) 513 my $img = pop;
514 $img->scale ($_[0], $_[1])
42 } 515 }
43 516
517=item move $dx, $dy, $img
518
519Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in
520the vertical.
521
522Example: move the image right by 20 pixels and down by 30.
523
524 move 20, 30, ...
525
526=item rootalign $img
527
528Moves the image so that it appears glued to the screen as opposed to the
529window. This gives the illusion of a larger area behind the window. It is
530exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the
531top left of the screen.
532
533Example: load a background image, put it in mirror mode and root align it.
534
535 rootalign mirror load "mybg.png"
536
537Example: take the screen background and align it, giving the illusion of
538transparency as long as the window isn't in front of other windows.
539
540 rootalign root
541
542=cut
543
44 sub move($$$;$) { 544 sub move($$;$) {
45 # TODO: must be simpler
46 $_[0]->transform ($_[0]->w, $_[0]->h,
47 1, 0, $_[1],
48 0, 1, $_[2],
49 0, 0, 1,
50 $_[3],
51 )
52 }
53
54 sub rotate($$$$$$;$) {
55 $_[0]->rotate (
56 $_[1],
57 $_[2],
58 $_[3] * $_[0]->w * .01,
59 $_[4] * $_[0]->h * .01,
60 $_[5] * (3.14159265 / 180),
61 $_[6],
62 )
63 }
64
65 sub blur($$$) {
66 my ($img, $rh, $rv) = @_;
67
68 $img = $img->clone; 545 my $img = pop->clone;
69 $img->blur ($rh, $rv); 546 $img->move ($_[0], $_[1]);
70 $img 547 $img
71 } 548 }
72 549
550 sub rootalign($) {
551 move -TX, -TY, $_[0]
552 }
553
554=item contrast $factor, $img
555
556=item contrast $r, $g, $b, $img
557
558=item contrast $r, $g, $b, $a, $img
559
560Adjusts the I<contrast> of an image.
561
562#TODO#
563
564=item brightness $factor, $img
565
566=item brightness $r, $g, $b, $img
567
568=item brightness $r, $g, $b, $a, $img
569
570Adjusts the brightness of an image.
571
572=cut
573
73 sub contrast($$;$$;$) { 574 sub contrast($$;$$;$) {
575 my $img = pop;
74 my ($img, $r, $g, $b, $a) = @_; 576 my ($r, $g, $b, $a) = @_;
75 577
76 ($g, $b) = ($r, $r) if @_ < 4; 578 ($g, $b) = ($r, $r) if @_ < 4;
77 $a = 1 if @_ < 5; 579 $a = 1 if @_ < 5;
78 580
79 $img = $img->clone; 581 $img = $img->clone;
80 $img->contrast ($r, $g, $b, $a); 582 $img->contrast ($r, $g, $b, $a);
81 $img 583 $img
82 } 584 }
83 585
84 sub brightness($$;$$;$) { 586 sub brightness($$;$$;$) {
587 my $img = pop;
85 my ($img, $r, $g, $b, $a) = @_; 588 my ($r, $g, $b, $a) = @_;
86 589
87 ($g, $b) = ($r, $r) if @_ < 4; 590 ($g, $b) = ($r, $r) if @_ < 4;
88 $a = 1 if @_ < 5; 591 $a = 1 if @_ < 5;
89 592
90 $img = $img->clone; 593 $img = $img->clone;
91 $img->brightness ($r, $g, $b, $a); 594 $img->brightness ($r, $g, $b, $a);
92 $img 595 $img
93 } 596 }
94 597
95 sub X() { $new->{position_sensitive} = 1; $l } 598=item blur $radius, $img
96 sub Y() { $new->{position_sensitive} = 1; $t }
97 sub W() { $new->{size_sensitive} = 1; $w }
98 sub H() { $new->{size_sensitive} = 1; $h }
99 599
100 sub now() { urxvt::NOW } 600=item blur $radius_horz, $radius_vert, $img
101 601
102 sub again($) { 602Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii
103 $new->{again} = $_[0]; 603can also be specified separately.
104 }
105 604
106 sub counter($) { 605Blurring is often I<very> slow, at least compared or other
107 $new->{again} = $_[0]; 606operators. Larger blur radii are slower than smaller ones, too, so if you
108 $bgdsl_self->{counter}++ + 0 607don't want to freeze your screen for long times, start experimenting with
608low values for radius (<5).
609
610=cut
611
612 sub blur($$;$) {
613 my $img = pop;
614 $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0])
109 } 615 }
616
617=item rotate $new_width, $new_height, $center_x, $center_y, $degrees
618
619Rotates the image by C<$degrees> degrees, counter-clockwise, around the
620pointer at C<$center_x> and C<$center_y> (specified as percentage of image
621width/height), generating a new image with width C<$new_width> and height
622C<$new_height>.
623
624#TODO# new width, height, maybe more operators?
625
626Example: rotate the image by 90 degrees
627
628=cut
629
630 sub rotate($$$$$$) {
631 my $img = pop;
632 $img->rotate (
633 $_[0],
634 $_[1],
635 $_[2] * $img->w * .01,
636 $_[3] * $img->h * .01,
637 $_[4] * (3.14159265 / 180),
638 )
639 }
640
641=back
642
643=cut
644
110} 645}
111 646
112sub parse_expr { 647sub parse_expr {
113 my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; 648 my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}";
114 die if $@; 649 die if $@;
123 $self->recalculate; 658 $self->recalculate;
124} 659}
125 660
126# evaluate the current bg expression 661# evaluate the current bg expression
127sub recalculate { 662sub recalculate {
128 my ($self) = @_; 663 my ($arg_self) = @_;
129 664
130 #TODO: rate limit calls 665 # rate limit evaluation
131 666
132 local $bgdsl_self = $self; 667 if ($arg_self->{next_refresh} > urxvt::NOW) {
668 $arg_self->{next_refresh_timer} = urxvt::timer->new->after ($arg_self->{next_refresh} - urxvt::NOW)->cb (sub {
669 $arg_self->recalculate;
670 });
671 return;
672 }
133 673
674 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL;
675
676 # set environment to evaluate user expression
677
678 local $self = $arg_self;
679
680 local $HOME = $ENV{HOME};
134 local $old = $self->{state}; 681 local $old = $self->{state};
135 local $new = my $state = $self->{state} = {}; 682 local $new = my $state = $self->{state} = {};
136 683
137 ($l, $t, $w, $h) = 684 ($x, $y, $w, $h) =
138 $self->get_geometry; 685 $self->background_geometry ($self->{border});
686
687 # evaluate user expression
139 688
140 my $img = eval { $self->{expr}->() }; 689 my $img = eval { $self->{expr}->() };
141 warn $@ if $@;#d# 690 warn $@ if $@;#d#
691 die if !UNIVERSAL::isa $img, "urxvt::img";
692
693 $state->{size_sensitive} = 1
694 if $img->repeat_mode != urxvt::RepeatNormal;
695
696 # if the expression is sensitive to external events, prepare reevaluation then
142 697
143 my $repeat; 698 my $repeat;
144 699
145 if (my $again = $state->{again}) { 700 if (my $again = $state->{again}) {
146 $repeat = 1; 701 $repeat = 1;
702 my $self = $self;
147 $state->{timer} = $again == $old->{again} 703 $state->{timer} = $again == $old->{again}
148 ? $old->{timer} 704 ? $old->{timer}
149 : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { $self->recalculate }); 705 : urxvt::timer->new->after ($again)->interval ($again)->cb (sub {
706 ++$self->{counter};
707 $self->recalculate
708 });
150 } 709 }
151 710
152 if (delete $state->{position_sensitive}) { 711 if (delete $state->{position_sensitive}) {
153 $repeat = 1; 712 $repeat = 1;
154 $self->enable (position_change => sub { $_[0]->recalculate }); 713 $self->enable (position_change => sub { $_[0]->recalculate });
161 $self->enable (size_change => sub { $_[0]->recalculate }); 720 $self->enable (size_change => sub { $_[0]->recalculate });
162 } else { 721 } else {
163 $self->disable ("size_change"); 722 $self->disable ("size_change");
164 } 723 }
165 724
725 if (delete $state->{rootpmap_sensitive}) {
726 $repeat = 1;
727 $self->enable (rootpmap_change => sub { $_[0]->recalculate });
728 } else {
729 $self->disable ("rootpmap_change");
730 }
731
732 # clear stuff we no longer need
733
166 %$old = (); 734 %$old = ();
167 735
168 unless ($repeat) { 736 unless ($repeat) {
169 delete $self->{state}; 737 delete $self->{state};
170 delete $self->{expr}; 738 delete $self->{expr};
171 } 739 }
172 740
173 $img = $img->sub_rect (0, 0, $w, $h) 741 # set background pixmap
174 if $img->w != $w || $img->h != $h;
175 742
176 $self->set_background ($img); 743 $self->set_background ($img, $self->{border});
177 $self->scr_recolour (0); 744 $self->scr_recolour (0);
178 $self->want_refresh; 745 $self->want_refresh;
179} 746}
180 747
181sub on_start { 748sub on_start {
182 my ($self) = @_; 749 my ($self) = @_;
183 750
751 my $expr = $self->x_resource ("background.expr")
752 or return;
753
184 $self->set_expr (parse_expr $EXPR); 754 $self->set_expr (parse_expr $expr);
755 $self->{border} = $self->x_resource_boolean ("background.border");
185 756
186 () 757 ()
187} 758}
188 759

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines