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.9 by root, Tue Jun 5 14:46:54 2012 UTC vs.
Revision 1.21 by root, Thu Jun 7 09:25:23 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#:META:X_RESOURCE:%.enable:boolean:some boolean
5#:META:X_RESOURCE:%.extra.:value:extra config
6
7our $EXPR = 'clip -50, -50, 150, 100, move X, Y, load "MagnoliaAlpha.png"';
4$EXPR = ' 8#$EXPR = '
5 rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, 9# rotate W, H, 50, 50, counter 1/59.95, repeat_mirror,
6 clip X, Y, W, H, repeat_mirror, 10# clip X, Y, W, H, repeat_mirror,
7 load "/root/pix/das_fette_schwein.jpg" 11# load "/root/pix/das_fette_schwein.jpg"
8'; 12#';
13#$EXPR = 'solid "red"';
9#$EXPR = 'blur root, 10, 10' 14#$EXPR = 'blur root, 10, 10'
10#$EXPR = 'blur move (root, -x, -y), 5, 5' 15#$EXPR = 'blur move (root, -x, -y), 5, 5'
11#resize load "/root/pix/das_fette_schwein.jpg", w, h 16#resize load "/root/pix/das_fette_schwein.jpg", w, h
12 17
13use Safe; 18use Safe;
14 19
15our ($bgdsl_self, $old, $new); 20our ($bgdsl_self, $old, $new);
16our ($l, $t, $w, $h); 21our ($l, $t, $w, $h);
17 22
23# enforce at least this interval between updates
18our $MIN_INTERVAL = 1/60; 24our $MIN_INTERVAL = 1/100;
19 25
20{ 26{
21 package urxvt::bgdsl; # background language 27 package urxvt::bgdsl; # background language
22 28
23 *repeat_black = \&urxvt::RepeatNone; #TODO wtf 29# *repeat_empty = \&urxvt::RepeatNone;
24 *repeat_wrap = \&urxvt::RepeatNormal; 30# *repeat_tile = \&urxvt::RepeatNormal;
25 *repeat_pad = \&urxvt::RepeatPad; 31# *repeat_pad = \&urxvt::RepeatPad;
26 *repeat_mirror = \&urxvt::RepeatReflect; 32# *repeat_mirror = \&urxvt::RepeatReflect;
33
34=head2 PROVIDERS/GENERATORS
35
36=over 4
37
38=item load $path
39
40=cut
27 41
28 sub load($) { 42 sub load($) {
29 my ($path) = @_; 43 my ($path) = @_;
30 44
31 $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path); 45 $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path);
34 sub root() { 48 sub root() {
35 $new->{rootpmap_sensitive} = 1; 49 $new->{rootpmap_sensitive} = 1;
36 die "root op not supported, exg, we need you"; 50 die "root op not supported, exg, we need you";
37 } 51 }
38 52
53 sub solid($;$$) {
54 my $img = $bgdsl_self->new_img (urxvt::PictStandardARGB32, $_[1] || 1, $_[2] || 1);
55 $img->fill ($_[0]);
56 $img
57 }
58
59=back
60
61=head2 VARIABLES
62
63=over 4
64
65=cut
66
67 sub X() { $new->{position_sensitive} = 1; $l }
68 sub Y() { $new->{position_sensitive} = 1; $t }
69 sub W() { $new->{size_sensitive} = 1; $w }
70 sub H() { $new->{size_sensitive} = 1; $h }
71
72 sub now() { urxvt::NOW }
73
74 sub again($) {
75 $new->{again} = $_[0];
76 }
77
78 sub counter($) {
79 $new->{again} = $_[0];
80 $bgdsl_self->{counter} + 0
81 }
82
83=back
84
85=head2 OPERATORS
86
87=over 4
88
89=cut
90
39# sub clone($) { 91# sub clone($) {
40# $_[0]->clone 92# $_[0]->clone
41# } 93# }
42 94
43 sub clip($$$$$;$) { 95 sub clip($;$$;$$) {
96 my $img = pop;
44 my $img = pop; 97 my $h = pop || H;
98 my $w = pop || W;
45 $img->sub_rect ($_[0], $_[1], $_[2], $_[3], $_[4]) 99 $img->sub_rect ($_[0], $_[1], $w, $h)
46 } 100 }
47 101
48 sub resize($$$) { 102 sub resize($$$) {
49 my $img = pop; 103 my $img = pop;
50 $img->scale ($_[0], $_[1]) 104 $img->scale ($_[0], $_[1])
51 } 105 }
52 106
53 # TODO: ugly 107 # TODO: ugly
54 sub move($$;$) { 108 sub move($$;$) {
109 my $img = pop->clone;
110 $img->move ($_[0], $_[1]);
111 $img
55 my $img = pop; 112# my $img = pop;
56 $img->sub_rect ( 113# $img->sub_rect (
57 $_[0], $_[1], 114# $_[0], $_[1],
58 $img->w, $img->h, 115# $img->w, $img->h,
59 $_[2], 116# $_[2],
60 ) 117# )
61 } 118 }
62 119
63 sub rotate($$$$$$;$) { 120 sub rotate($$$$$$) {
64 my $img = pop; 121 my $img = pop;
65 $img->rotate ( 122 $img->rotate (
66 $_[0], 123 $_[0],
67 $_[1], 124 $_[1],
68 $_[2] * $img->w * .01, 125 $_[2] * $img->w * .01,
69 $_[3] * $img->h * .01, 126 $_[3] * $img->h * .01,
70 $_[4] * (3.14159265 / 180), 127 $_[4] * (3.14159265 / 180),
71 $_[5],
72 ) 128 )
73 } 129 }
74 130
75 sub blur($$$) { 131 sub blur($$$) {
76 my ($rh, $rv, $img) = @_; 132 my ($rh, $rv, $img) = @_;
77 133
78 $img = $img->clone;
79 $img->blur ($rh, $rv); 134 $img->blur ($rh, $rv);
80 $img
81 } 135 }
82 136
83 sub contrast($$;$$;$) { 137 sub contrast($$;$$;$) {
84 my $img = pop; 138 my $img = pop;
85 my ($r, $g, $b, $a) = @_; 139 my ($r, $g, $b, $a) = @_;
102 $img = $img->clone; 156 $img = $img->clone;
103 $img->brightness ($r, $g, $b, $a); 157 $img->brightness ($r, $g, $b, $a);
104 $img 158 $img
105 } 159 }
106 160
107 sub X() { $new->{position_sensitive} = 1; $l } 161=back
108 sub Y() { $new->{position_sensitive} = 1; $t }
109 sub W() { $new->{size_sensitive} = 1; $w }
110 sub H() { $new->{size_sensitive} = 1; $h }
111 162
112 sub now() { urxvt::NOW } 163=cut
113 164
114 sub again($) {
115 $new->{again} = $_[0];
116 }
117
118 sub counter($) {
119 $new->{again} = $_[0];
120 $bgdsl_self->{counter} + 0
121 }
122} 165}
123 166
124sub parse_expr { 167sub parse_expr {
125 my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; 168 my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}";
126 die if $@; 169 die if $@;
137 180
138# evaluate the current bg expression 181# evaluate the current bg expression
139sub recalculate { 182sub recalculate {
140 my ($self) = @_; 183 my ($self) = @_;
141 184
185 # rate limit evaluation
186
142 if ($self->{next_refresh} > urxvt::NOW) { 187 if ($self->{next_refresh} > urxvt::NOW) {
143 $self->{next_refresh_timer} = urxvt::timer->new->after ($self->{next_refresh} - urxvt::NOW)->cb (sub { 188 $self->{next_refresh_timer} = urxvt::timer->new->after ($self->{next_refresh} - urxvt::NOW)->cb (sub {
144 $self->recalculate; 189 $self->recalculate;
145 }); 190 });
191 return;
146 } 192 }
147 193
148 $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; 194 $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL;
149 195
150 #TODO: rate limit calls 196 # set environment to evaluate user expression
151 197
152 local $bgdsl_self = $self; 198 local $bgdsl_self = $self;
153 199
154 local $old = $self->{state}; 200 local $old = $self->{state};
155 local $new = my $state = $self->{state} = {}; 201 local $new = my $state = $self->{state} = {};
156 202
157 ($l, $t, $w, $h) = 203 ($l, $t, $w, $h) =
158 $self->get_geometry; 204 $self->get_geometry;
159 205
206 # evaluate user expression
207
160 my $img = eval { $self->{expr}->() }; 208 my $img = eval { $self->{expr}->() };
161 warn $@ if $@;#d# 209 warn $@ if $@;#d#
210 die if !UNIVERSAL::isa $img, "urxvt::img";
211
212 # if the expression is sensitive to external events, prepare reevaluation then
162 213
163 my $repeat; 214 my $repeat;
164 215
165 if (my $again = $state->{again}) { 216 if (my $again = $state->{again}) {
166 $repeat = 1; 217 $repeat = 1;
191 $self->enable (rootpmap_change => sub { $_[0]->recalculate }); 242 $self->enable (rootpmap_change => sub { $_[0]->recalculate });
192 } else { 243 } else {
193 $self->disable ("rootpmap_change"); 244 $self->disable ("rootpmap_change");
194 } 245 }
195 246
247 # clear stuff we no longer need
248
196 %$old = (); 249 %$old = ();
197 250
198 unless ($repeat) { 251 unless ($repeat) {
199 delete $self->{state}; 252 delete $self->{state};
200 delete $self->{expr}; 253 delete $self->{expr};
201 } 254 }
202 255
256 # prepare and set background pixmap
257
203 $img = $img->sub_rect (0, 0, $w, $h) 258 $img = $img->sub_rect (0, 0, $w, $h)
204 if $img->w != $w || $img->h != $h; 259 if $img->w != $w || $img->h != $h;
205 260
206 $self->set_background ($img); 261 $self->set_background ($img);
207 $self->scr_recolour (0); 262 $self->scr_recolour (0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines