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