1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | #:META:X_RESOURCE:%.expr:string:background expression |
|
|
4 | #:META:X_RESOURCE:%.enable:boolean:some boolean |
|
|
5 | #:META:X_RESOURCE:%.extra.*:value:extra config |
2 | |
6 | |
3 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; |
7 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; |
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 | |
13 | use Safe; |
18 | use Safe; |
14 | |
19 | |
15 | our ($bgdsl_self, $old, $new); |
20 | our ($bgdsl_self, $old, $new); |
16 | our ($l, $t, $w, $h); |
21 | our ($l, $t, $w, $h); |
17 | |
22 | |
|
|
23 | # enforce at least this interval between updates |
18 | our $MIN_INTERVAL = 1/60; |
24 | our $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_black = \&urxvt::RepeatNone; #TODO wtf |
24 | *repeat_wrap = \&urxvt::RepeatNormal; |
30 | *repeat_wrap = \&urxvt::RepeatNormal; |
25 | *repeat_pad = \&urxvt::RepeatPad; |
31 | *repeat_pad = \&urxvt::RepeatPad; |
26 | *repeat_mirror = \&urxvt::RepeatReflect; |
32 | *repeat_mirror = \&urxvt::RepeatReflect; |
27 | |
33 | |
|
|
34 | =head2 PROVIDERS/GENERATORS |
|
|
35 | |
|
|
36 | =over 4 |
|
|
37 | |
|
|
38 | =item load $path |
|
|
39 | |
|
|
40 | =cut |
|
|
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); |
32 | } |
46 | } |
33 | |
47 | |
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 | } |
|
|
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 OPERATORS |
|
|
62 | |
|
|
63 | =over 4 |
|
|
64 | |
|
|
65 | =cut |
38 | |
66 | |
39 | # sub clone($) { |
67 | # sub clone($) { |
40 | # $_[0]->clone |
68 | # $_[0]->clone |
41 | # } |
69 | # } |
42 | |
70 | |
… | |
… | |
73 | } |
101 | } |
74 | |
102 | |
75 | sub blur($$$) { |
103 | sub blur($$$) { |
76 | my ($rh, $rv, $img) = @_; |
104 | my ($rh, $rv, $img) = @_; |
77 | |
105 | |
78 | $img = $img->clone; |
|
|
79 | $img->blur ($rh, $rv); |
106 | $img->blur ($rh, $rv); |
80 | $img |
|
|
81 | } |
107 | } |
82 | |
108 | |
83 | sub contrast($$;$$;$) { |
109 | sub contrast($$;$$;$) { |
84 | my $img = pop; |
110 | my $img = pop; |
85 | my ($r, $g, $b, $a) = @_; |
111 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
117 | |
143 | |
118 | sub counter($) { |
144 | sub counter($) { |
119 | $new->{again} = $_[0]; |
145 | $new->{again} = $_[0]; |
120 | $bgdsl_self->{counter} + 0 |
146 | $bgdsl_self->{counter} + 0 |
121 | } |
147 | } |
|
|
148 | |
|
|
149 | =back |
|
|
150 | |
|
|
151 | =cut |
|
|
152 | |
122 | } |
153 | } |
123 | |
154 | |
124 | sub parse_expr { |
155 | sub parse_expr { |
125 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
156 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
126 | die if $@; |
157 | die if $@; |
… | |
… | |
137 | |
168 | |
138 | # evaluate the current bg expression |
169 | # evaluate the current bg expression |
139 | sub recalculate { |
170 | sub recalculate { |
140 | my ($self) = @_; |
171 | my ($self) = @_; |
141 | |
172 | |
|
|
173 | # rate limit evaluation |
|
|
174 | |
142 | if ($self->{next_refresh} > urxvt::NOW) { |
175 | if ($self->{next_refresh} > urxvt::NOW) { |
143 | $self->{next_refresh_timer} = urxvt::timer->new->after ($self->{next_refresh} - urxvt::NOW)->cb (sub { |
176 | $self->{next_refresh_timer} = urxvt::timer->new->after ($self->{next_refresh} - urxvt::NOW)->cb (sub { |
144 | $self->recalculate; |
177 | $self->recalculate; |
145 | }); |
178 | }); |
|
|
179 | return; |
146 | } |
180 | } |
147 | |
181 | |
148 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
182 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
149 | |
183 | |
150 | #TODO: rate limit calls |
184 | # set environment to evaluate user expression |
151 | |
185 | |
152 | local $bgdsl_self = $self; |
186 | local $bgdsl_self = $self; |
153 | |
187 | |
154 | local $old = $self->{state}; |
188 | local $old = $self->{state}; |
155 | local $new = my $state = $self->{state} = {}; |
189 | local $new = my $state = $self->{state} = {}; |
156 | |
190 | |
157 | ($l, $t, $w, $h) = |
191 | ($l, $t, $w, $h) = |
158 | $self->get_geometry; |
192 | $self->get_geometry; |
159 | |
193 | |
|
|
194 | # evaluate user expression |
|
|
195 | |
160 | my $img = eval { $self->{expr}->() }; |
196 | my $img = eval { $self->{expr}->() }; |
161 | warn $@ if $@;#d# |
197 | warn $@ if $@;#d# |
|
|
198 | die if !UNIVERSAL::isa $img, "urxvt::img"; |
|
|
199 | |
|
|
200 | # if the expression is sensitive to external events, prepare reevaluation then |
162 | |
201 | |
163 | my $repeat; |
202 | my $repeat; |
164 | |
203 | |
165 | if (my $again = $state->{again}) { |
204 | if (my $again = $state->{again}) { |
166 | $repeat = 1; |
205 | $repeat = 1; |
… | |
… | |
191 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
230 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
192 | } else { |
231 | } else { |
193 | $self->disable ("rootpmap_change"); |
232 | $self->disable ("rootpmap_change"); |
194 | } |
233 | } |
195 | |
234 | |
|
|
235 | # clear stuff we no longer need |
|
|
236 | |
196 | %$old = (); |
237 | %$old = (); |
197 | |
238 | |
198 | unless ($repeat) { |
239 | unless ($repeat) { |
199 | delete $self->{state}; |
240 | delete $self->{state}; |
200 | delete $self->{expr}; |
241 | delete $self->{expr}; |
201 | } |
242 | } |
202 | |
243 | |
|
|
244 | # prepare and set background pixmap |
|
|
245 | |
203 | $img = $img->sub_rect (0, 0, $w, $h) |
246 | $img = $img->sub_rect (0, 0, $w, $h) |
204 | if $img->w != $w || $img->h != $h; |
247 | if $img->w != $w || $img->h != $h; |
205 | |
248 | |
206 | $self->set_background ($img); |
249 | $self->set_background ($img); |
207 | $self->scr_recolour (0); |
250 | $self->scr_recolour (0); |
… | |
… | |
209 | } |
252 | } |
210 | |
253 | |
211 | sub on_start { |
254 | sub on_start { |
212 | my ($self) = @_; |
255 | my ($self) = @_; |
213 | |
256 | |
|
|
257 | warn $self->x_resource ("background.enable"); |
|
|
258 | |
214 | $self->set_expr (parse_expr $EXPR); |
259 | $self->set_expr (parse_expr $EXPR); |
215 | |
260 | |
216 | () |
261 | () |
217 | } |
262 | } |
218 | |
263 | |