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