ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
(Generate patch)

Comparing rxvt-unicode/src/perl/background (file contents):
Revision 1.43 by root, Sun Jun 10 11:23:20 2012 UTC vs.
Revision 1.48 by root, Sun Jun 10 15:01:14 2012 UTC

1#! perl 1#! perl
2 2
3#:META:X_RESOURCE:%.expr:string:background expression 3#:META:X_RESOURCE:%.expr:string:background expression
4#:META:X_RESOURCE:%.border.:boolean:respect the terminal border 4#:META:X_RESOURCE:%.border:boolean:respect the terminal border
5#:META:X_RESOURCE:%.interval:seconds:minimum time between updates
5 6
6#TODO: once, rootalign 7#TODO: once, rootalign
7 8
8=head1 NAME 9=head1 NAME
9 10
11 12
12=head1 SYNOPSIS 13=head1 SYNOPSIS
13 14
14 urxvt --background-expr 'background expression' 15 urxvt --background-expr 'background expression'
15 --background-border 16 --background-border
17 --background-interval seconds
16 18
17=head1 DESCRIPTION 19=head1 DESCRIPTION
18 20
19This extension manages the terminal background by creating a picture that 21This extension manages the terminal background by creating a picture that
20is behind the text, replacing the normal background colour. 22is behind the text, replacing the normal background colour.
189overwriting borders and any other areas, such as the scrollbar. 191overwriting borders and any other areas, such as the scrollbar.
190 192
191Specifying this flag changes the behaviour, so that the image only 193Specifying this flag changes the behaviour, so that the image only
192replaces the background of the character area. 194replaces the background of the character area.
193 195
196=item --background-interval seconds
197
198Since some operations in the underlying XRender extension can effetively
199freeze your X-server for prolonged time, this extension enforces a minimum
200time between updates, which is normally about 0.1 seconds.
201
202If you want to do updates more often, you can decrease this safety
203interval with this switch.
204
194=back 205=back
195 206
196=cut 207=cut
197 208
198our $HOME; 209our $HOME;
199our ($self, $old, $new); 210our ($self, $old, $new);
200our ($x, $y, $w, $h); 211our ($x, $y, $w, $h);
201 212
202# enforce at least this interval between updates 213# enforce at least this interval between updates
203our $MIN_INTERVAL = 1/100; 214our $MIN_INTERVAL = 6/59.951;
204 215
205{ 216{
206 package urxvt::bgdsl; # background language 217 package urxvt::bgdsl; # background language
207 218
208 use List::Util qw(min max sum shuffle); 219 use List::Util qw(min max sum shuffle);
263 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); 274 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1);
264 $img->fill ($colour); 275 $img->fill ($colour);
265 $img 276 $img
266 } 277 }
267 278
279=item clone $img
280
281Returns an exact copy of the image. This is useful if you want to have
282multiple copies of the same image to apply different effects to.
283
284=cut
285
286 sub clone($) {
287 $_[0]->clone
288 }
289
268=back 290=back
269 291
292=head2 TILING MODES
293
294The following operators modify the tiling mode of an image, that is, the
295way that pixels outside the image area are painted when the image is used.
296
297=over 4
298
299=item tile $img
300
301Tiles the whole plane with the image and returns this new image - or in
302other words, it returns a copy of the image in plane tiling mode.
303
304Example: load an image and tile it over the background, without
305resizing. The C<tile> call is superfluous because C<load> already defaults
306to tiling mode.
307
308 tile load "mybg.png"
309
310=item mirror $img
311
312Similar to tile, but reflects the image each time it uses a new copy, so
313that top edges always touch top edges, right edges always touch right
314edges and so on (with normal tiling, left edges always touch right edges
315and top always touch bottom edges).
316
317Example: load an image and mirror it over the background, avoiding sharp
318edges at the image borders at the expense of mirroring the image itself
319
320 mirror load "mybg.png"
321
322=item pad $img
323
324Takes an image and modifies it so that all pixels outside the image area
325become transparent. This mode is most useful when you want to place an
326image over another image or the background colour while leaving all
327background pixels outside the image unchanged.
328
329Example: load an image and display it in the upper left corner. The rest
330of the space is left "empty" (transparent or wahtever your compisotr does
331in alpha mode, else background colour).
332
333 pad load "mybg.png"
334
335=item extend $img
336
337Extends the image over the whole plane, using the closest pixel in the
338area outside the image. This mode is mostly useful when you more complex
339filtering operations and want the pixels outside the image to have the
340same values as the pixels near the edge.
341
342Example: just for curiosity, how does this pixel extension stuff work?
343
344 extend move 50, 50, load "mybg.png"
345
346=cut
347
348 sub pad($) {
349 my $img = $_[0]->clone;
350 $img->repeat_mode (urxvt::RepeatNone);
351 $img
352 }
353
354 sub tile($) {
355 my $img = $_[0]->clone;
356 $img->repeat_mode (urxvt::RepeatNormal);
357 $img
358 }
359
360 sub mirror($) {
361 my $img = $_[0]->clone;
362 $img->repeat_mode (urxvt::RepeatReflect);
363 $img
364 }
365
366 sub extend($) {
367 my $img = $_[0]->clone;
368 $img->repeat_mode (urxvt::RepeatPad);
369 $img
370 }
371
372=back
373
270=head2 VARIABLES 374=head2 VARIABLE VALUES
271 375
272The following functions provide variable data such as the terminal window 376The following functions provide variable data such as the terminal window
273dimensions. They are not (Perl-) variables, they jsut return stuff that 377dimensions. They are not (Perl-) variables, they just return stuff that
274varies. Most of them make your expression sensitive to some events, for 378varies. Most of them make your expression sensitive to some events, for
275example using C<TW> (terminal width) means your expression is evaluated 379example using C<TW> (terminal width) means your expression is evaluated
276again when the terminal is resized. 380again when the terminal is resized.
277 381
278=over 4 382=over 4
352 $self->{counter} + 0 456 $self->{counter} + 0
353 } 457 }
354 458
355=back 459=back
356 460
357=head2 TILING MODES 461=head2 SHAPE CHANGING OPERATORS
358 462
359The following operators modify the tiling mode of an image, that is, the 463The following operators modify the shape, size or position of the image.
360way that pixels outside the image area are painted when the image is used.
361 464
362=over 4 465=over 4
363
364=item tile $img
365
366Tiles the whole plane with the image and returns this new image - or in
367other words, it returns a copy of the image in plane tiling mode.
368
369Example: load an image and tile it over the background, without
370resizing. The C<tile> call is superfluous because C<load> already defaults
371to tiling mode.
372
373 tile load "mybg.png"
374
375=item mirror $img
376
377Similar to tile, but reflects the image each time it uses a new copy, so
378that top edges always touch top edges, right edges always touch right
379edges and so on (with normal tiling, left edges always touch right edges
380and top always touch bottom edges).
381
382Example: load an image and mirror it over the background, avoiding sharp
383edges at the image borders at the expense of mirroring the image itself
384
385 mirror load "mybg.png"
386
387=item pad $img
388
389Takes an image and modifies it so that all pixels outside the image area
390become transparent. This mode is most useful when you want to place an
391image over another image or the background colour while leaving all
392background pixels outside the image unchanged.
393
394Example: load an image and display it in the upper left corner. The rest
395of the space is left "empty" (transparent or wahtever your compisotr does
396in alpha mode, else background colour).
397
398 pad load "mybg.png"
399
400=item extend $img
401
402Extends the image over the whole plane, using the closest pixel in the
403area outside the image. This mode is mostly useful when you more complex
404filtering operations and want the pixels outside the image to have the
405same values as the pixels near the edge.
406
407Example: just for curiosity, how does this pixel extension stuff work?
408
409 extend move 50, 50, load "mybg.png"
410
411=cut
412
413 sub pad($) {
414 my $img = $_[0]->clone;
415 $img->repeat_mode (urxvt::RepeatNone);
416 $img
417 }
418
419 sub tile($) {
420 my $img = $_[0]->clone;
421 $img->repeat_mode (urxvt::RepeatNormal);
422 $img
423 }
424
425 sub mirror($) {
426 my $img = $_[0]->clone;
427 $img->repeat_mode (urxvt::RepeatReflect);
428 $img
429 }
430
431 sub extend($) {
432 my $img = $_[0]->clone;
433 $img->repeat_mode (urxvt::RepeatPad);
434 $img
435 }
436
437=back
438
439=head2 PIXEL OPERATORS
440
441The following operators modify the image pixels in various ways.
442
443=over 4
444
445=item clone $img
446
447Returns an exact copy of the image.
448
449=cut
450
451 sub clone($) {
452 $_[0]->clone
453 }
454 466
455=item clip $img 467=item clip $img
456 468
457=item clip $width, $height, $img 469=item clip $width, $height, $img
458 470
552 564
553Example: move the image right by 20 pixels and down by 30. 565Example: move the image right by 20 pixels and down by 30.
554 566
555 move 20, 30, ... 567 move 20, 30, ...
556 568
569=item align $xalign, $yalign, $img
570
571Aligns the image according to a factor - C<0> means the image is moved to
572the left or top edge (for C<$xalign> or C<$yalign>), C<0.5> means it is
573exactly centered and C<1> means it touches the right or bottom edge.
574
575Example: remove any visible border around an image, center it vertically but move
576it to the right hand side.
577
578 align 1, 0.5, pad $img
579
580=item center $img
581
582=item center $width, $height, $img
583
584Centers the image, i.e. the center of the image is moved to the center of
585the terminal window (or the box specified by C<$width> and C<$height> if
586given).
587
588Example: load an image and center it.
589
590 center pad load "mybg.png"
591
557=item rootalign $img 592=item rootalign $img
558 593
559Moves the image so that it appears glued to the screen as opposed to the 594Moves the image so that it appears glued to the screen as opposed to the
560window. This gives the illusion of a larger area behind the window. It is 595window. This gives the illusion of a larger area behind the window. It is
561exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the 596exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the
566 rootalign mirror load "mybg.png" 601 rootalign mirror load "mybg.png"
567 602
568Example: take the screen background and align it, giving the illusion of 603Example: take the screen background and align it, giving the illusion of
569transparency as long as the window isn't in front of other windows. 604transparency as long as the window isn't in front of other windows.
570 605
571 rootalign root 606 rootalign root
572 607
573=cut 608=cut
574 609
575 sub move($$;$) { 610 sub move($$;$) {
576 my $img = pop->clone; 611 my $img = pop->clone;
577 $img->move ($_[0], $_[1]); 612 $img->move ($_[0], $_[1]);
578 $img 613 $img
579 } 614 }
580 615
616 sub align($;$$) {
617 my $img = pop;
618
619 move $_[0] * (TW - $img->w),
620 $_[1] * (TH - $img->h),
621 $img
622 }
623
624 sub center($;$$) {
625 my $img = pop;
626 my $w = $_[0] || TW;
627 my $h = $_[1] || TH;
628
629 move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img
630 }
631
581 sub rootalign($) { 632 sub rootalign($) {
582 move -TX, -TY, $_[0] 633 move -TX, -TY, $_[0]
583 } 634 }
584 635
636=back
637
638=head2 COLOUR MODIFICATIONS
639
640The following operators change the pixels of the image.
641
642=over 4
643
585=item contrast $factor, $img 644=item contrast $factor, $img
586 645
587=item contrast $r, $g, $b, $img 646=item contrast $r, $g, $b, $img
588 647
589=item contrast $r, $g, $b, $a, $img 648=item contrast $r, $g, $b, $a, $img
590 649
591Adjusts the I<contrast> of an image. 650Adjusts the I<contrast> of an image.
592 651
593#TODO# 652The first form applies a single C<$factor> to red, green and blue, the
653second form applies separate factors to each colour channel, and the last
654form includes the alpha channel.
594 655
656Values from 0 to 1 lower the contrast, values higher than 1 increase the
657contrast.
658
659Due to limitations in the underlying XRender extension, lowering contrast
660also reduces brightness, while increasing contrast currently also
661increases brightness.
662
595=item brightness $factor, $img 663=item brightness $bias, $img
596 664
597=item brightness $r, $g, $b, $img 665=item brightness $r, $g, $b, $img
598 666
599=item brightness $r, $g, $b, $a, $img 667=item brightness $r, $g, $b, $a, $img
600 668
601Adjusts the brightness of an image. 669Adjusts the brightness of an image.
670
671The first form applies a single C<$bias> to red, green and blue, the
672second form applies separate biases to each colour channel, and the last
673form includes the alpha channel.
674
675Values less than 0 reduce brightness, while values larger than 0 increase
676it. Useful range is from -1 to 1 - the former results in a black, the
677latter in a white picture.
678
679Due to idiosynchrasies in the underlying XRender extension, biases less
680than zero can be I<very> slow.
602 681
603=cut 682=cut
604 683
605 sub contrast($$;$$;$) { 684 sub contrast($$;$$;$) {
606 my $img = pop; 685 my $img = pop;
717 796
718 # evaluate user expression 797 # evaluate user expression
719 798
720 my $img = eval { $self->{expr}->() }; 799 my $img = eval { $self->{expr}->() };
721 warn $@ if $@;#d# 800 warn $@ if $@;#d#
722 die if !UNIVERSAL::isa $img, "urxvt::img"; 801 die "background-expr did not return an image.\n" if !UNIVERSAL::isa $img, "urxvt::img";
723 802
724 $state->{size_sensitive} = 1 803 $state->{size_sensitive} = 1
725 if $img->repeat_mode != urxvt::RepeatNormal; 804 if $img->repeat_mode != urxvt::RepeatNormal;
726 805
727 # if the expression is sensitive to external events, prepare reevaluation then 806 # if the expression is sensitive to external events, prepare reevaluation then
777} 856}
778 857
779sub on_start { 858sub on_start {
780 my ($self) = @_; 859 my ($self) = @_;
781 860
782 my $expr = $self->x_resource ("background.expr") 861 my $expr = $self->x_resource ("%.expr")
783 or return; 862 or return;
784 863
864 $self->has_render
865 or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n";
866
785 $self->set_expr (parse_expr $expr); 867 $self->set_expr (parse_expr $expr);
786 $self->{border} = $self->x_resource_boolean ("background.border"); 868 $self->{border} = $self->x_resource_boolean ("%.border");
869
870 $MIN_INTERVAL = $self->x_resource ("%.interval");
787 871
788 () 872 ()
789} 873}
790 874

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines