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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines