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