1 | #! perl |
1 | #! perl |
2 | |
2 | |
|
|
3 | #:META:RESOURCE:$$:string |
|
|
4 | |
3 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; |
5 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; |
4 | $EXPR = 'rotate load "/root/pix/das_fette_schwein.jpg", W, H, 50, 50, counter 1/60, repeat_mirror'; |
6 | $EXPR = ' |
|
|
7 | rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
|
|
8 | clip X, Y, W, H, repeat_mirror, |
|
|
9 | load "/root/pix/das_fette_schwein.jpg" |
|
|
10 | '; |
5 | #$EXPR = 'blur root, 10, 10' |
11 | #$EXPR = 'blur root, 10, 10' |
6 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
12 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
7 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
13 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
8 | |
14 | |
9 | use Safe; |
15 | use Safe; |
10 | |
16 | |
11 | our ($bgdsl_self, $old, $new); |
17 | our ($bgdsl_self, $old, $new); |
12 | our ($l, $t, $w, $h); |
18 | our ($l, $t, $w, $h); |
|
|
19 | |
|
|
20 | # enforce at leats this time between updates |
|
|
21 | our $MIN_INTERVAL = 1/100; |
13 | |
22 | |
14 | { |
23 | { |
15 | package urxvt::bgdsl; # background language |
24 | package urxvt::bgdsl; # background language |
16 | |
25 | |
17 | *repeat_black = \&urxvt::RepeatNone; #TODO wtf |
26 | *repeat_black = \&urxvt::RepeatNone; #TODO wtf |
… | |
… | |
24 | |
33 | |
25 | $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); |
26 | } |
35 | } |
27 | |
36 | |
28 | sub root() { |
37 | sub root() { |
|
|
38 | $new->{rootpmap_sensitive} = 1; |
29 | die "root op not supported, exg, we need you"; |
39 | die "root op not supported, exg, we need you"; |
30 | } |
40 | } |
31 | |
41 | |
32 | # sub clone($) { |
42 | # sub clone($) { |
33 | # $_[0]->clone |
43 | # $_[0]->clone |
34 | # } |
44 | # } |
35 | |
45 | |
36 | sub subrect($$$$$;$) { |
46 | sub clip($$$$$;$) { |
|
|
47 | my $img = pop; |
37 | $_[0]->sub_rect ($_[1], $_[2], $_[3], $_[4], $_[5]) |
48 | $img->sub_rect ($_[0], $_[1], $_[2], $_[3], $_[4]) |
38 | } |
49 | } |
39 | |
50 | |
40 | sub resize($$$) { |
51 | sub resize($$$) { |
41 | $_[0]->scale ($_[1], $_[2]) |
52 | my $img = pop; |
|
|
53 | $img->scale ($_[0], $_[1]) |
42 | } |
54 | } |
43 | |
55 | |
|
|
56 | # TODO: ugly |
44 | sub move($$$;$) { |
57 | sub move($$;$) { |
45 | # TODO: must be simpler |
58 | my $img = pop; |
46 | $_[0]->transform ($_[0]->w, $_[0]->h, |
59 | $img->sub_rect ( |
47 | 1, 0, $_[1], |
60 | $_[0], $_[1], |
48 | 0, 1, $_[2], |
61 | $img->w, $img->h, |
49 | 0, 0, 1, |
|
|
50 | $_[3], |
62 | $_[2], |
51 | ) |
63 | ) |
52 | } |
64 | } |
53 | |
65 | |
54 | sub rotate($$$$$$;$) { |
66 | sub rotate($$$$$$;$) { |
|
|
67 | my $img = pop; |
55 | $_[0]->rotate ( |
68 | $img->rotate ( |
|
|
69 | $_[0], |
56 | $_[1], |
70 | $_[1], |
57 | $_[2], |
|
|
58 | $_[3] * $_[0]->w * .01, |
71 | $_[2] * $img->w * .01, |
59 | $_[4] * $_[0]->h * .01, |
72 | $_[3] * $img->h * .01, |
60 | $_[5] * (3.14159265 / 180), |
73 | $_[4] * (3.14159265 / 180), |
61 | $_[6], |
74 | $_[5], |
62 | ) |
75 | ) |
63 | } |
76 | } |
64 | |
77 | |
65 | sub blur($$$) { |
78 | sub blur($$$) { |
66 | my ($img, $rh, $rv) = @_; |
79 | my ($rh, $rv, $img) = @_; |
67 | |
80 | |
68 | $img = $img->clone; |
|
|
69 | $img->blur ($rh, $rv); |
81 | $img->blur ($rh, $rv); |
70 | $img |
|
|
71 | } |
82 | } |
72 | |
83 | |
73 | sub contrast($$;$$;$) { |
84 | sub contrast($$;$$;$) { |
|
|
85 | my $img = pop; |
74 | my ($img, $r, $g, $b, $a) = @_; |
86 | my ($r, $g, $b, $a) = @_; |
75 | |
87 | |
76 | ($g, $b) = ($r, $r) if @_ < 4; |
88 | ($g, $b) = ($r, $r) if @_ < 4; |
77 | $a = 1 if @_ < 5; |
89 | $a = 1 if @_ < 5; |
78 | |
90 | |
79 | $img = $img->clone; |
91 | $img = $img->clone; |
80 | $img->contrast ($r, $g, $b, $a); |
92 | $img->contrast ($r, $g, $b, $a); |
81 | $img |
93 | $img |
82 | } |
94 | } |
83 | |
95 | |
84 | sub brightness($$;$$;$) { |
96 | sub brightness($$;$$;$) { |
|
|
97 | my $img = pop; |
85 | my ($img, $r, $g, $b, $a) = @_; |
98 | my ($r, $g, $b, $a) = @_; |
86 | |
99 | |
87 | ($g, $b) = ($r, $r) if @_ < 4; |
100 | ($g, $b) = ($r, $r) if @_ < 4; |
88 | $a = 1 if @_ < 5; |
101 | $a = 1 if @_ < 5; |
89 | |
102 | |
90 | $img = $img->clone; |
103 | $img = $img->clone; |
… | |
… | |
103 | $new->{again} = $_[0]; |
116 | $new->{again} = $_[0]; |
104 | } |
117 | } |
105 | |
118 | |
106 | sub counter($) { |
119 | sub counter($) { |
107 | $new->{again} = $_[0]; |
120 | $new->{again} = $_[0]; |
108 | $bgdsl_self->{counter}++ + 0 |
121 | $bgdsl_self->{counter} + 0 |
109 | } |
122 | } |
110 | } |
123 | } |
111 | |
124 | |
112 | sub parse_expr { |
125 | sub parse_expr { |
113 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
126 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
… | |
… | |
125 | |
138 | |
126 | # evaluate the current bg expression |
139 | # evaluate the current bg expression |
127 | sub recalculate { |
140 | sub recalculate { |
128 | my ($self) = @_; |
141 | my ($self) = @_; |
129 | |
142 | |
|
|
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 |
|
|
155 | |
130 | local $bgdsl_self = $self; |
156 | local $bgdsl_self = $self; |
131 | |
157 | |
132 | local $old = $self->{state}; |
158 | local $old = $self->{state}; |
133 | local $new = my $state = $self->{state} = {}; |
159 | local $new = my $state = $self->{state} = {}; |
134 | |
160 | |
135 | ($l, $t, $w, $h) = |
161 | ($l, $t, $w, $h) = |
136 | $self->get_geometry; |
162 | $self->get_geometry; |
137 | |
163 | |
|
|
164 | # evaluate user expression |
|
|
165 | |
138 | my $img = eval { $self->{expr}->() }; |
166 | my $img = eval { $self->{expr}->() }; |
139 | warn $@ if $@;#d# |
167 | warn $@ if $@;#d# |
140 | |
168 | |
141 | %$old = (); |
169 | # if the expression is sensitive to external events, prepare reevaluation then |
142 | |
170 | |
143 | my $repeat; |
171 | my $repeat; |
144 | |
172 | |
145 | if (my $again = $state->{again}) { |
173 | if (my $again = $state->{again}) { |
146 | $repeat = 1; |
174 | $repeat = 1; |
147 | $state->{again} = urxvt::timer->new->after ($again)->cb (sub { $self->recalculate }); |
175 | $state->{timer} = $again == $old->{again} |
|
|
176 | ? $old->{timer} |
|
|
177 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
|
|
178 | ++$self->{counter}; |
|
|
179 | $self->recalculate |
|
|
180 | }); |
148 | } |
181 | } |
149 | |
182 | |
150 | if (delete $state->{position_sensitive}) { |
183 | if (delete $state->{position_sensitive}) { |
151 | $repeat = 1; |
184 | $repeat = 1; |
152 | $self->enable (position_change => sub { $_[0]->recalculate }); |
185 | $self->enable (position_change => sub { $_[0]->recalculate }); |
… | |
… | |
159 | $self->enable (size_change => sub { $_[0]->recalculate }); |
192 | $self->enable (size_change => sub { $_[0]->recalculate }); |
160 | } else { |
193 | } else { |
161 | $self->disable ("size_change"); |
194 | $self->disable ("size_change"); |
162 | } |
195 | } |
163 | |
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 | |
|
|
206 | %$old = (); |
|
|
207 | |
164 | unless ($repeat) { |
208 | unless ($repeat) { |
165 | delete $self->{state}; |
209 | delete $self->{state}; |
166 | delete $self->{expr}; |
210 | delete $self->{expr}; |
167 | } |
211 | } |
168 | |
212 | |
|
|
213 | # prepare and set background pixmap |
|
|
214 | |
169 | $img = $img->sub_rect (0, 0, $w, $h) |
215 | $img = $img->sub_rect (0, 0, $w, $h) |
170 | if $img->w != $w || $img->h != $h; |
216 | if $img->w != $w || $img->h != $h; |
171 | |
217 | |
172 | $self->set_background ($img); |
218 | $self->set_background ($img); |
173 | $self->scr_recolour (0); |
219 | $self->scr_recolour (0); |