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