1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:RESOURCE:$$:string:background expression |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
4 | #:META:RESOURCE:$$-enable:boolean:some boolean |
4 | #:META:X_RESOURCE:%.enable:boolean:some boolean |
|
|
5 | #:META:X_RESOURCE:%.extra.:value:extra config |
5 | |
6 | |
6 | our $EXPR = 'move load "/root/pix/das_fette_schwein.jpg", repeat_wrap, X, Y'; |
7 | our $EXPR = 'clip move X, Y, load "MagnoliaAlpha.png"'; |
7 | $EXPR = ' |
8 | #$EXPR = ' |
8 | rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
9 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
9 | clip X, Y, W, H, repeat_mirror, |
10 | # clip X, Y, W, H, repeat_mirror, |
10 | load "/root/pix/das_fette_schwein.jpg" |
11 | # load "/root/pix/das_fette_schwein.jpg" |
11 | '; |
12 | #'; |
|
|
13 | #$EXPR = 'solid "red"'; |
12 | #$EXPR = 'blur root, 10, 10' |
14 | #$EXPR = 'blur root, 10, 10' |
13 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
15 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
14 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
16 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
15 | |
17 | |
16 | use Safe; |
18 | use Safe; |
17 | |
19 | |
18 | our ($bgdsl_self, $old, $new); |
20 | our ($bgdsl_self, $old, $new); |
19 | our ($l, $t, $w, $h); |
21 | our ($l, $t, $w, $h); |
20 | |
22 | |
21 | # enforce at leats this time between updates |
23 | # enforce at least this interval between updates |
22 | our $MIN_INTERVAL = 1/100; |
24 | our $MIN_INTERVAL = 1/100; |
23 | |
25 | |
24 | { |
26 | { |
25 | package urxvt::bgdsl; # background language |
27 | package urxvt::bgdsl; # background language |
26 | |
28 | |
27 | *repeat_black = \&urxvt::RepeatNone; #TODO wtf |
29 | # *repeat_empty = \&urxvt::RepeatNone; |
28 | *repeat_wrap = \&urxvt::RepeatNormal; |
30 | # *repeat_tile = \&urxvt::RepeatNormal; |
29 | *repeat_pad = \&urxvt::RepeatPad; |
31 | # *repeat_pad = \&urxvt::RepeatPad; |
30 | *repeat_mirror = \&urxvt::RepeatReflect; |
32 | # *repeat_mirror = \&urxvt::RepeatReflect; |
|
|
33 | |
|
|
34 | =head2 PROVIDERS/GENERATORS |
|
|
35 | |
|
|
36 | =over 4 |
|
|
37 | |
|
|
38 | =item load $path |
|
|
39 | |
|
|
40 | =cut |
31 | |
41 | |
32 | sub load($) { |
42 | sub load($) { |
33 | my ($path) = @_; |
43 | my ($path) = @_; |
34 | |
44 | |
35 | $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); |
… | |
… | |
38 | sub root() { |
48 | sub root() { |
39 | $new->{rootpmap_sensitive} = 1; |
49 | $new->{rootpmap_sensitive} = 1; |
40 | die "root op not supported, exg, we need you"; |
50 | die "root op not supported, exg, we need you"; |
41 | } |
51 | } |
42 | |
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 VARIABLES |
|
|
62 | |
|
|
63 | =over 4 |
|
|
64 | |
|
|
65 | =cut |
|
|
66 | |
|
|
67 | sub X() { $new->{position_sensitive} = 1; $l } |
|
|
68 | sub Y() { $new->{position_sensitive} = 1; $t } |
|
|
69 | sub W() { $new->{size_sensitive} = 1; $w } |
|
|
70 | sub H() { $new->{size_sensitive} = 1; $h } |
|
|
71 | |
|
|
72 | sub now() { urxvt::NOW } |
|
|
73 | |
|
|
74 | sub again($) { |
|
|
75 | $new->{again} = $_[0]; |
|
|
76 | } |
|
|
77 | |
|
|
78 | sub counter($) { |
|
|
79 | $new->{again} = $_[0]; |
|
|
80 | $bgdsl_self->{counter} + 0 |
|
|
81 | } |
|
|
82 | |
|
|
83 | =back |
|
|
84 | |
|
|
85 | =head2 OPERATORS |
|
|
86 | |
|
|
87 | =over 4 |
|
|
88 | |
|
|
89 | =cut |
|
|
90 | |
43 | # sub clone($) { |
91 | # sub clone($) { |
44 | # $_[0]->clone |
92 | # $_[0]->clone |
45 | # } |
93 | # } |
46 | |
94 | |
47 | sub clip($$$$$;$) { |
95 | sub clip($;$$;$$) { |
|
|
96 | my $img = pop; |
48 | my $img = pop; |
97 | my $h = pop || H; |
|
|
98 | my $w = pop || W; |
49 | $img->sub_rect ($_[0], $_[1], $_[2], $_[3], $_[4]) |
99 | $img->sub_rect ($_[0], $_[1], $w, $h) |
50 | } |
100 | } |
51 | |
101 | |
52 | sub resize($$$) { |
102 | sub resize($$$) { |
53 | my $img = pop; |
103 | my $img = pop; |
54 | $img->scale ($_[0], $_[1]) |
104 | $img->scale ($_[0], $_[1]) |
55 | } |
105 | } |
56 | |
106 | |
57 | # TODO: ugly |
107 | # TODO: ugly |
58 | sub move($$;$) { |
108 | sub move($$;$) { |
|
|
109 | my $img = pop->clone; |
|
|
110 | $img->move ($_[0], $_[1]); |
|
|
111 | $img |
59 | my $img = pop; |
112 | # my $img = pop; |
60 | $img->sub_rect ( |
113 | # $img->sub_rect ( |
61 | $_[0], $_[1], |
114 | # $_[0], $_[1], |
62 | $img->w, $img->h, |
115 | # $img->w, $img->h, |
63 | $_[2], |
116 | # $_[2], |
64 | ) |
117 | # ) |
65 | } |
118 | } |
66 | |
119 | |
67 | sub rotate($$$$$$;$) { |
120 | sub rotate($$$$$$) { |
68 | my $img = pop; |
121 | my $img = pop; |
69 | $img->rotate ( |
122 | $img->rotate ( |
70 | $_[0], |
123 | $_[0], |
71 | $_[1], |
124 | $_[1], |
72 | $_[2] * $img->w * .01, |
125 | $_[2] * $img->w * .01, |
73 | $_[3] * $img->h * .01, |
126 | $_[3] * $img->h * .01, |
74 | $_[4] * (3.14159265 / 180), |
127 | $_[4] * (3.14159265 / 180), |
75 | $_[5], |
|
|
76 | ) |
128 | ) |
77 | } |
129 | } |
78 | |
130 | |
79 | sub blur($$$) { |
131 | sub blur($$$) { |
80 | my ($rh, $rv, $img) = @_; |
132 | my ($rh, $rv, $img) = @_; |
… | |
… | |
104 | $img = $img->clone; |
156 | $img = $img->clone; |
105 | $img->brightness ($r, $g, $b, $a); |
157 | $img->brightness ($r, $g, $b, $a); |
106 | $img |
158 | $img |
107 | } |
159 | } |
108 | |
160 | |
109 | sub X() { $new->{position_sensitive} = 1; $l } |
161 | =back |
110 | sub Y() { $new->{position_sensitive} = 1; $t } |
|
|
111 | sub W() { $new->{size_sensitive} = 1; $w } |
|
|
112 | sub H() { $new->{size_sensitive} = 1; $h } |
|
|
113 | |
162 | |
114 | sub now() { urxvt::NOW } |
163 | =cut |
115 | |
164 | |
116 | sub again($) { |
|
|
117 | $new->{again} = $_[0]; |
|
|
118 | } |
|
|
119 | |
|
|
120 | sub counter($) { |
|
|
121 | $new->{again} = $_[0]; |
|
|
122 | $bgdsl_self->{counter} + 0 |
|
|
123 | } |
|
|
124 | } |
165 | } |
125 | |
166 | |
126 | sub parse_expr { |
167 | sub parse_expr { |
127 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
168 | my $expr = eval "sub {\npackage urxvt::bgdsl;\n#line 0 'background expression'\n$_[0]\n}"; |
128 | die if $@; |
169 | die if $@; |
… | |
… | |
160 | local $new = my $state = $self->{state} = {}; |
201 | local $new = my $state = $self->{state} = {}; |
161 | |
202 | |
162 | ($l, $t, $w, $h) = |
203 | ($l, $t, $w, $h) = |
163 | $self->get_geometry; |
204 | $self->get_geometry; |
164 | |
205 | |
|
|
206 | warn "$l,$t,$w,$h\n";#d# |
|
|
207 | |
165 | # evaluate user expression |
208 | # evaluate user expression |
166 | |
209 | |
167 | my $img = eval { $self->{expr}->() }; |
210 | my $img = eval { $self->{expr}->() }; |
168 | warn $@ if $@;#d# |
211 | warn $@ if $@;#d# |
|
|
212 | die if !UNIVERSAL::isa $img, "urxvt::img"; |
169 | |
213 | |
170 | # if the expression is sensitive to external events, prepare reevaluation then |
214 | # if the expression is sensitive to external events, prepare reevaluation then |
171 | |
215 | |
172 | my $repeat; |
216 | my $repeat; |
173 | |
217 | |