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.7 by root, Tue Jun 5 14:04:58 2012 UTC vs.
Revision 1.12 by root, Tue Jun 5 18:29:51 2012 UTC

1#! perl 1#! perl
2
3#:META:RESOURCE:$$:string
2 4
3our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; 5our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y';
4$EXPR = ' 6$EXPR = '
5 rotate W, H, 50, 50, counter 1/60, repeat_mirror, 7 rotate W, H, 50, 50, counter 1/59.95, repeat_mirror,
6 clip X, Y, W, H, repeat_mirror, 8 clip X, Y, W, H, repeat_mirror,
7 load "/root/pix/das_fette_schwein.jpg" 9 load "/root/pix/das_fette_schwein.jpg"
8'; 10';
9#$EXPR = 'blur root, 10, 10' 11#$EXPR = 'blur root, 10, 10'
10#$EXPR = 'blur move (root, -x, -y), 5, 5' 12#$EXPR = 'blur move (root, -x, -y), 5, 5'
13use Safe; 15use Safe;
14 16
15our ($bgdsl_self, $old, $new); 17our ($bgdsl_self, $old, $new);
16our ($l, $t, $w, $h); 18our ($l, $t, $w, $h);
17 19
20# enforce at leats this time between updates
21our $MIN_INTERVAL = 1/100;
22
18{ 23{
19 package urxvt::bgdsl; # background language 24 package urxvt::bgdsl; # background language
20 25
21 *repeat_black = \&urxvt::RepeatNone; #TODO wtf 26 *repeat_black = \&urxvt::RepeatNone; #TODO wtf
22 *repeat_wrap = \&urxvt::RepeatNormal; 27 *repeat_wrap = \&urxvt::RepeatNormal;
28 33
29 $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path); 34 $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path);
30 } 35 }
31 36
32 sub root() { 37 sub root() {
38 $new->{rootpmap_sensitive} = 1;
33 die "root op not supported, exg, we need you"; 39 die "root op not supported, exg, we need you";
34 } 40 }
35 41
36# sub clone($) { 42# sub clone($) {
37# $_[0]->clone 43# $_[0]->clone
70 } 76 }
71 77
72 sub blur($$$) { 78 sub blur($$$) {
73 my ($rh, $rv, $img) = @_; 79 my ($rh, $rv, $img) = @_;
74 80
75 $img = $img->clone;
76 $img->blur ($rh, $rv); 81 $img->blur ($rh, $rv);
77 $img
78 } 82 }
79 83
80 sub contrast($$;$$;$) { 84 sub contrast($$;$$;$) {
81 my $img = pop; 85 my $img = pop;
82 my ($r, $g, $b, $a) = @_; 86 my ($r, $g, $b, $a) = @_;
134 138
135# evaluate the current bg expression 139# evaluate the current bg expression
136sub recalculate { 140sub recalculate {
137 my ($self) = @_; 141 my ($self) = @_;
138 142
139 #TODO: rate limit calls 143 # rate limit evaluation
144
145 if ($self->{next_refresh} > urxvt::NOW) {
146 $self->{next_refresh_timer} = urxvt::timer->new->after ($self->{next_refresh} - urxvt::NOW)->cb (sub {
147 $self->recalculate;
148 });
149 return;
150 }
151
152 $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL;
153
154 # set environment to evaluate user expression
140 155
141 local $bgdsl_self = $self; 156 local $bgdsl_self = $self;
142 157
143 local $old = $self->{state}; 158 local $old = $self->{state};
144 local $new = my $state = $self->{state} = {}; 159 local $new = my $state = $self->{state} = {};
145 160
146 ($l, $t, $w, $h) = 161 ($l, $t, $w, $h) =
147 $self->get_geometry; 162 $self->get_geometry;
148 163
164 # evaluate user expression
165
149 my $img = eval { $self->{expr}->() }; 166 my $img = eval { $self->{expr}->() };
150 warn $@ if $@;#d# 167 warn $@ if $@;#d#
168
169 # if the expression is sensitive to external events, prepare reevaluation then
151 170
152 my $repeat; 171 my $repeat;
153 172
154 if (my $again = $state->{again}) { 173 if (my $again = $state->{again}) {
155 $repeat = 1; 174 $repeat = 1;
173 $self->enable (size_change => sub { $_[0]->recalculate }); 192 $self->enable (size_change => sub { $_[0]->recalculate });
174 } else { 193 } else {
175 $self->disable ("size_change"); 194 $self->disable ("size_change");
176 } 195 }
177 196
197 if (delete $state->{rootpmap_sensitive}) {
198 $repeat = 1;
199 $self->enable (rootpmap_change => sub { $_[0]->recalculate });
200 } else {
201 $self->disable ("rootpmap_change");
202 }
203
204 # clear stuff we no longer need
205
178 %$old = (); 206 %$old = ();
179 207
180 unless ($repeat) { 208 unless ($repeat) {
181 delete $self->{state}; 209 delete $self->{state};
182 delete $self->{expr}; 210 delete $self->{expr};
183 } 211 }
184 212
213 # prepare and set background pixmap
214
185 $img = $img->sub_rect (0, 0, $w, $h) 215 $img = $img->sub_rect (0, 0, $w, $h)
186 if $img->w != $w || $img->h != $h; 216 if $img->w != $w || $img->h != $h;
187 217
188 $self->set_background ($img); 218 $self->set_background ($img);
189 $self->scr_recolour (0); 219 $self->scr_recolour (0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines