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; |
|
|
69 | $img->blur ($rh, $rv); |
78 | $img->blur ($rh, $rv); |
70 | $img |
|
|
71 | } |
79 | } |
72 | |
80 | |
73 | sub contrast($$;$$;$) { |
81 | sub contrast($$;$$;$) { |
|
|
82 | my $img = pop; |
74 | my ($img, $r, $g, $b, $a) = @_; |
83 | my ($r, $g, $b, $a) = @_; |
75 | |
84 | |
76 | ($g, $b) = ($r, $r) if @_ < 4; |
85 | ($g, $b) = ($r, $r) if @_ < 4; |
77 | $a = 1 if @_ < 5; |
86 | $a = 1 if @_ < 5; |
78 | |
87 | |
79 | $img = $img->clone; |
88 | $img = $img->clone; |
80 | $img->contrast ($r, $g, $b, $a); |
89 | $img->contrast ($r, $g, $b, $a); |
81 | $img |
90 | $img |
82 | } |
91 | } |
83 | |
92 | |
84 | sub brightness($$;$$;$) { |
93 | sub brightness($$;$$;$) { |
|
|
94 | my $img = pop; |
85 | my ($img, $r, $g, $b, $a) = @_; |
95 | my ($r, $g, $b, $a) = @_; |
86 | |
96 | |
87 | ($g, $b) = ($r, $r) if @_ < 4; |
97 | ($g, $b) = ($r, $r) if @_ < 4; |
88 | $a = 1 if @_ < 5; |
98 | $a = 1 if @_ < 5; |
89 | |
99 | |
90 | $img = $img->clone; |
100 | $img = $img->clone; |
… | |
… | |
103 | $new->{again} = $_[0]; |
113 | $new->{again} = $_[0]; |
104 | } |
114 | } |
105 | |
115 | |
106 | sub counter($) { |
116 | sub counter($) { |
107 | $new->{again} = $_[0]; |
117 | $new->{again} = $_[0]; |
108 | $bgdsl_self->{counter}++ + 0 |
118 | $bgdsl_self->{counter} + 0 |
109 | } |
119 | } |
110 | } |
120 | } |
111 | |
121 | |
112 | sub parse_expr { |
122 | sub parse_expr { |
113 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
123 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
… | |
… | |
125 | |
135 | |
126 | # evaluate the current bg expression |
136 | # evaluate the current bg expression |
127 | sub recalculate { |
137 | sub recalculate { |
128 | my ($self) = @_; |
138 | my ($self) = @_; |
129 | |
139 | |
|
|
140 | # rate limit evaluation |
|
|
141 | |
|
|
142 | if ($self->{next_refresh} > urxvt::NOW) { |
|
|
143 | $self->{next_refresh_timer} = urxvt::timer->new->after ($self->{next_refresh} - urxvt::NOW)->cb (sub { |
|
|
144 | $self->recalculate; |
|
|
145 | }); |
|
|
146 | } |
|
|
147 | |
|
|
148 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
|
|
149 | |
|
|
150 | # set environment to evaluate user expression |
|
|
151 | |
130 | local $bgdsl_self = $self; |
152 | local $bgdsl_self = $self; |
131 | |
153 | |
132 | local $old = $self->{state}; |
154 | local $old = $self->{state}; |
133 | local $new = my $state = $self->{state} = {}; |
155 | local $new = my $state = $self->{state} = {}; |
134 | |
156 | |
135 | ($l, $t, $w, $h) = |
157 | ($l, $t, $w, $h) = |
136 | $self->get_geometry; |
158 | $self->get_geometry; |
137 | |
159 | |
|
|
160 | # evaluate user expression |
|
|
161 | |
138 | my $img = eval { $self->{expr}->() }; |
162 | my $img = eval { $self->{expr}->() }; |
139 | warn $@ if $@;#d# |
163 | warn $@ if $@;#d# |
140 | |
164 | |
141 | %$old = (); |
165 | # if the expression is sensitive to external events, prepare reevaluation then |
142 | |
166 | |
143 | my $repeat; |
167 | my $repeat; |
144 | |
168 | |
145 | if (my $again = $state->{again}) { |
169 | if (my $again = $state->{again}) { |
146 | $repeat = 1; |
170 | $repeat = 1; |
147 | $state->{again} = urxvt::timer->new->after ($again)->cb (sub { $self->recalculate }); |
171 | $state->{timer} = $again == $old->{again} |
|
|
172 | ? $old->{timer} |
|
|
173 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
|
|
174 | ++$self->{counter}; |
|
|
175 | $self->recalculate |
|
|
176 | }); |
148 | } |
177 | } |
149 | |
178 | |
150 | if (delete $state->{position_sensitive}) { |
179 | if (delete $state->{position_sensitive}) { |
151 | $repeat = 1; |
180 | $repeat = 1; |
152 | $self->enable (position_change => sub { $_[0]->recalculate }); |
181 | $self->enable (position_change => sub { $_[0]->recalculate }); |
… | |
… | |
159 | $self->enable (size_change => sub { $_[0]->recalculate }); |
188 | $self->enable (size_change => sub { $_[0]->recalculate }); |
160 | } else { |
189 | } else { |
161 | $self->disable ("size_change"); |
190 | $self->disable ("size_change"); |
162 | } |
191 | } |
163 | |
192 | |
|
|
193 | if (delete $state->{rootpmap_sensitive}) { |
|
|
194 | $repeat = 1; |
|
|
195 | $self->enable (rootpmap_change => sub { $_[0]->recalculate }); |
|
|
196 | } else { |
|
|
197 | $self->disable ("rootpmap_change"); |
|
|
198 | } |
|
|
199 | |
|
|
200 | # clear stuff we no longer need |
|
|
201 | |
|
|
202 | %$old = (); |
|
|
203 | |
164 | unless ($repeat) { |
204 | unless ($repeat) { |
165 | delete $self->{state}; |
205 | delete $self->{state}; |
166 | delete $self->{expr}; |
206 | delete $self->{expr}; |
167 | } |
207 | } |
168 | |
208 | |
|
|
209 | # prepare and set background pixmap |
|
|
210 | |
169 | $img = $img->sub_rect (0, 0, $w, $h) |
211 | $img = $img->sub_rect (0, 0, $w, $h) |
170 | if $img->w != $w || $img->h != $h; |
212 | if $img->w != $w || $img->h != $h; |
171 | |
213 | |
172 | $self->set_background ($img); |
214 | $self->set_background ($img); |
173 | $self->scr_recolour (0); |
215 | $self->scr_recolour (0); |