1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", &x, &y'; |
3 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; |
|
|
4 | $EXPR = ' |
|
|
5 | rotate W, H, 50, 50, counter 1/60, repeat_mirror, |
|
|
6 | clip X, Y, W, H, repeat_mirror, |
|
|
7 | load "/root/pix/das_fette_schwein.jpg" |
|
|
8 | '; |
4 | #$EXPR = 'blur root, 10, 10' |
9 | #$EXPR = 'blur root, 10, 10' |
5 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
10 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
6 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
11 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
7 | |
12 | |
8 | use Safe; |
13 | use Safe; |
9 | |
14 | |
|
|
15 | our ($bgdsl_self, $old, $new); |
|
|
16 | our ($l, $t, $w, $h); |
|
|
17 | |
10 | { |
18 | { |
11 | package urxvt::bgdsl::vars; |
|
|
12 | |
|
|
13 | our ($self, $old, $new); |
|
|
14 | our ($x, $y, $w, $h); |
|
|
15 | |
|
|
16 | package urxvt::bgdsl; # background language |
19 | package urxvt::bgdsl; # background language |
17 | |
20 | |
18 | *repeat_black = \&urxvt::RepeatNone; #TODO wtf |
21 | *repeat_black = \&urxvt::RepeatNone; #TODO wtf |
19 | *repeat_wrap = \&urxvt::RepeatNormal; |
22 | *repeat_wrap = \&urxvt::RepeatNormal; |
20 | *repeat_pad = \&urxvt::RepeatPad; |
23 | *repeat_pad = \&urxvt::RepeatPad; |
21 | *repeat_mirror = \&urxvt::RepeatReflect; |
24 | *repeat_mirror = \&urxvt::RepeatReflect; |
22 | |
25 | |
23 | sub load($) { |
26 | sub load($) { |
24 | my ($path) = @_; |
27 | my ($path) = @_; |
25 | |
28 | |
26 | $new->{load}{$path} = $old->{load}{$path} || $self->new_img_from_file ($path); |
29 | $new->{load}{$path} = $old->{load}{$path} || $bgdsl_self->new_img_from_file ($path); |
27 | } |
30 | } |
28 | |
31 | |
29 | sub root() { |
32 | sub root() { |
30 | die "root op not supported, exg, we need you"; |
33 | die "root op not supported, exg, we need you"; |
31 | } |
34 | } |
32 | |
35 | |
|
|
36 | # sub clone($) { |
|
|
37 | # $_[0]->clone |
|
|
38 | # } |
|
|
39 | |
|
|
40 | sub clip($$$$$;$) { |
|
|
41 | my $img = pop; |
|
|
42 | $img->sub_rect ($_[0], $_[1], $_[2], $_[3], $_[4]) |
|
|
43 | } |
|
|
44 | |
33 | sub resize($$$) { |
45 | sub resize($$$) { |
34 | $_[0]->scale ($_[1], $_[2]) |
46 | my $img = pop; |
|
|
47 | $img->scale ($_[0], $_[1]) |
35 | } |
48 | } |
36 | |
49 | |
|
|
50 | # TODO: ugly |
37 | sub move($$$) { |
51 | sub move($$;$) { |
38 | # TODO: must be simpler |
52 | my $img = pop; |
39 | $_[0]->transform ($_[0]->w, $_[0]->h, $_[1], |
53 | $img->sub_rect ( |
|
|
54 | $_[0], $_[1], |
|
|
55 | $img->w, $img->h, |
40 | 1, 0, -$_[2], |
56 | $_[2], |
41 | 0, 1, -$_[3], |
|
|
42 | 0, 0, 1, |
|
|
43 | ) |
57 | ) |
44 | } |
58 | } |
45 | |
59 | |
46 | sub rotate($$$$) { |
60 | sub rotate($$$$$$;$) { |
47 | $_[0]->rotate ($_[0], $_[1], $_[2], $_[3] * (3.14159265 / 180)) |
61 | my $img = pop; |
|
|
62 | $img->rotate ( |
|
|
63 | $_[0], |
|
|
64 | $_[1], |
|
|
65 | $_[2] * $img->w * .01, |
|
|
66 | $_[3] * $img->h * .01, |
|
|
67 | $_[4] * (3.14159265 / 180), |
|
|
68 | $_[5], |
|
|
69 | ) |
48 | } |
70 | } |
49 | |
71 | |
50 | sub blur($$$) { |
72 | sub blur($$$) { |
51 | my ($img, $rh, $rv) = @_; |
73 | my ($rh, $rv, $img) = @_; |
52 | |
74 | |
53 | $img = $img->clone; |
75 | $img = $img->clone; |
54 | $img->clone->blur ($rh, $rv); |
76 | $img->blur ($rh, $rv); |
55 | $img |
77 | $img |
56 | } |
78 | } |
57 | |
79 | |
58 | sub contrast($$;$$;$) { |
80 | sub contrast($$;$$;$) { |
|
|
81 | my $img = pop; |
59 | my ($img, $r, $g, $b, $a) = @_; |
82 | my ($r, $g, $b, $a) = @_; |
|
|
83 | |
60 | ($g, $b) = ($r, $r) if @_ < 4; |
84 | ($g, $b) = ($r, $r) if @_ < 4; |
61 | $a = 1 if @_ < 5; |
85 | $a = 1 if @_ < 5; |
|
|
86 | |
62 | $img = $img->clone; |
87 | $img = $img->clone; |
63 | $img->contrast ($r, $g, $b, $a); |
88 | $img->contrast ($r, $g, $b, $a); |
64 | $img |
89 | $img |
65 | } |
90 | } |
66 | |
91 | |
67 | sub brightness($$;$$;$) { |
92 | sub brightness($$;$$;$) { |
|
|
93 | my $img = pop; |
68 | my ($img, $r, $g, $b, $a) = @_; |
94 | my ($r, $g, $b, $a) = @_; |
|
|
95 | |
69 | ($g, $b) = ($r, $r) if @_ < 4; |
96 | ($g, $b) = ($r, $r) if @_ < 4; |
70 | $a = 1 if @_ < 5; |
97 | $a = 1 if @_ < 5; |
|
|
98 | |
71 | $img = $img->clone; |
99 | $img = $img->clone; |
72 | $img->brightness ($r, $g, $b, $a); |
100 | $img->brightness ($r, $g, $b, $a); |
73 | $img |
101 | $img |
74 | } |
102 | } |
75 | |
103 | |
76 | sub x() { $new->{position_sensitive} = 1; $x } |
104 | sub X() { $new->{position_sensitive} = 1; $l } |
77 | sub y() { $new->{position_sensitive} = 1; $y } |
105 | sub Y() { $new->{position_sensitive} = 1; $t } |
78 | sub w() { $new->{size_sensitive} = 1; $w } |
106 | sub W() { $new->{size_sensitive} = 1; $w } |
79 | sub h() { $new->{size_sensitive} = 1; $h } |
107 | sub H() { $new->{size_sensitive} = 1; $h } |
|
|
108 | |
80 | sub now() { urxvt::NOW } |
109 | sub now() { urxvt::NOW } |
81 | |
110 | |
82 | sub again($) { |
111 | sub again($) { |
83 | $new->{again} = $_[0]; |
112 | $new->{again} = $_[0]; |
84 | } |
113 | } |
85 | |
114 | |
86 | sub counter($) { |
115 | sub counter($) { |
87 | $new->{again} = $_[0]; |
116 | $new->{again} = $_[0]; |
88 | $self->{counter}++ + 0 |
117 | $bgdsl_self->{counter} + 0 |
89 | } |
118 | } |
90 | } |
119 | } |
91 | |
120 | |
92 | sub parse_expr { |
121 | sub parse_expr { |
93 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
122 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
… | |
… | |
97 | |
126 | |
98 | # compiles a parsed expression |
127 | # compiles a parsed expression |
99 | sub set_expr { |
128 | sub set_expr { |
100 | my ($self, $expr) = @_; |
129 | my ($self, $expr) = @_; |
101 | |
130 | |
102 | local $Data::Dumper::Deparse=1; use Data::Dumper; warn Dumper $expr;#d# |
|
|
103 | $self->{expr} = $expr; |
131 | $self->{expr} = $expr; |
104 | $self->recalculate; |
132 | $self->recalculate; |
105 | } |
133 | } |
106 | |
134 | |
107 | # evaluate the current bg expression |
135 | # evaluate the current bg expression |
108 | sub recalculate { |
136 | sub recalculate { |
109 | my ($self) = @_; |
137 | my ($self) = @_; |
110 | |
138 | |
|
|
139 | #TODO: rate limit calls |
|
|
140 | |
111 | local $urxvt::bgdsl::vars::self = $self; |
141 | local $bgdsl_self = $self; |
112 | |
142 | |
113 | local $urxvt::bgdsl::vars::old = $self->{state}; |
143 | local $old = $self->{state}; |
114 | local $urxvt::bgdsl::vars::new = my $state = $self->{state} = {}; |
144 | local $new = my $state = $self->{state} = {}; |
115 | |
145 | |
116 | ($urxvt::bgdsl::vars::x, $urxvt::bgdsl::vars::y, $urxvt::bgdsl::vars::w, $urxvt::bgdsl::vars::h) = |
146 | ($l, $t, $w, $h) = |
117 | $self->get_geometry; |
147 | $self->get_geometry; |
118 | |
148 | |
119 | my $img = eval { $self->{expr}->() }; |
149 | my $img = eval { $self->{expr}->() }; |
120 | warn $@ if $@;#d# |
150 | warn $@ if $@;#d# |
121 | |
151 | |
122 | my $repeat; |
152 | my $repeat; |
123 | |
153 | |
124 | if (my $again = $state->{again}) { |
154 | if (my $again = $state->{again}) { |
125 | $repeat = 1; |
155 | $repeat = 1; |
126 | $state->{again} = urxvt::timer->new->after ($again)->cb (sub { $self->recalculate }); |
156 | $state->{timer} = $again == $old->{again} |
|
|
157 | ? $old->{timer} |
|
|
158 | : urxvt::timer->new->after ($again)->interval ($again)->cb (sub { |
|
|
159 | ++$self->{counter}; |
|
|
160 | $self->recalculate |
|
|
161 | }); |
127 | } |
162 | } |
128 | |
163 | |
129 | if (delete $state->{position_sensitive}) { |
164 | if (delete $state->{position_sensitive}) { |
130 | $repeat = 1; |
165 | $repeat = 1; |
131 | $self->enable (position_change => sub { $_[0]->recalculate }); |
166 | $self->enable (position_change => sub { $_[0]->recalculate }); |
… | |
… | |
138 | $self->enable (size_change => sub { $_[0]->recalculate }); |
173 | $self->enable (size_change => sub { $_[0]->recalculate }); |
139 | } else { |
174 | } else { |
140 | $self->disable ("size_change"); |
175 | $self->disable ("size_change"); |
141 | } |
176 | } |
142 | |
177 | |
143 | # TODO: install handlers for geometry changes &c |
178 | %$old = (); |
144 | |
179 | |
145 | warn $img; |
180 | unless ($repeat) { |
|
|
181 | delete $self->{state}; |
|
|
182 | delete $self->{expr}; |
|
|
183 | } |
|
|
184 | |
|
|
185 | $img = $img->sub_rect (0, 0, $w, $h) |
|
|
186 | if $img->w != $w || $img->h != $h; |
|
|
187 | |
146 | $self->set_background ($img); |
188 | $self->set_background ($img); |
147 | $self->scr_recolour (0); |
189 | $self->scr_recolour (0); |
148 | $self->want_refresh; |
190 | $self->want_refresh; |
149 | } |
191 | } |
150 | |
192 | |