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