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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines