ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
Revision: 1.4
Committed: Tue Jun 5 13:39:26 2012 UTC (11 years, 11 months ago) by root
Branch: MAIN
Changes since 1.3: +36 -18 lines
Log Message:
*** empty log message ***

File Contents

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