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.99 by sf-exg, Sat May 8 07:45:48 2021 UTC vs.
Revision 1.104 by root, Sat Dec 4 22:56:49 2021 UTC

11#:META:RESOURCE:tintColor:color:tint background with color 11#:META:RESOURCE:tintColor:color:tint background with color
12#:META:RESOURCE:sh:number:shade background by number % 12#:META:RESOURCE:sh:number:shade background by number %
13#:META:RESOURCE:shading:number:shade background by number % 13#:META:RESOURCE:shading:number:shade background by number %
14#:META:RESOURCE:blr:HxV:gaussian-blur background with radii 14#:META:RESOURCE:blr:HxV:gaussian-blur background with radii
15#:META:RESOURCE:blurRadius:HxV:gaussian-blur background with radii 15#:META:RESOURCE:blurRadius:HxV:gaussian-blur background with radii
16#:META:OSC:20:change/query background image
17#:META:OSC:705:change transparent background tint colour
16 18
17=head1 NAME 19=head1 NAME
18 20
19background - manage terminal background 21background - manage terminal background
20 22
54is behind the text, replacing the normal background colour. 56is behind the text, replacing the normal background colour.
55 57
56It does so by evaluating a Perl expression that I<calculates> the image on 58It does so by evaluating a Perl expression that I<calculates> the image on
57the fly, for example, by grabbing the root background or loading a file. 59the fly, for example, by grabbing the root background or loading a file.
58 60
59While the full power of Perl is available, the operators have been design 61While the full power of Perl is available, the operators have been
60to be as simple as possible. 62designed to be as simple as possible.
61 63
62For example, to load an image and scale it to the window size, you would 64For example, to load an image and scale it to the window size, you would
63use: 65use:
64 66
65 urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' 67 urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }'
259 261
260=head1 REFERENCE 262=head1 REFERENCE
261 263
262=head2 COMMAND LINE SWITCHES 264=head2 COMMAND LINE SWITCHES
263 265
264=over 4 266=over
265 267
266=item --background-expr perl-expression 268=item --background-expr perl-expression
267 269
268Specifies the Perl expression to evaluate. 270Specifies the Perl expression to evaluate.
269 271
310 312
311These functions provide an image, by loading it from disk, grabbing it 313These functions provide an image, by loading it from disk, grabbing it
312from the root screen or by simply generating it. They are used as starting 314from the root screen or by simply generating it. They are used as starting
313points to get an image you can play with. 315points to get an image you can play with.
314 316
315=over 4 317=over
316 318
317=item load $path 319=item load $path
318 320
319Loads the image at the given C<$path>. The image is set to plane tiling 321Loads the image at the given C<$path>. The image is set to plane tiling
320mode. 322mode.
439=head2 TILING MODES 441=head2 TILING MODES
440 442
441The following operators modify the tiling mode of an image, that is, the 443The following operators modify the tiling mode of an image, that is, the
442way that pixels outside the image area are painted when the image is used. 444way that pixels outside the image area are painted when the image is used.
443 445
444=over 4 446=over
445 447
446=item tile $img 448=item tile $img
447 449
448Tiles the whole plane with the image and returns this new image - or in 450Tiles the whole plane with the image and returns this new image - or in
449other words, it returns a copy of the image in plane tiling mode. 451other words, it returns a copy of the image in plane tiling mode.
524dimensions. They are not (Perl-) variables, they just return stuff that 526dimensions. They are not (Perl-) variables, they just return stuff that
525varies. Most of them make your expression sensitive to some events, for 527varies. Most of them make your expression sensitive to some events, for
526example using C<TW> (terminal width) means your expression is evaluated 528example using C<TW> (terminal width) means your expression is evaluated
527again when the terminal is resized. 529again when the terminal is resized.
528 530
529=over 4 531=over
530 532
531=item TX 533=item TX
532 534
533=item TY 535=item TY
534 536
627 629
628=head2 SHAPE CHANGING OPERATORS 630=head2 SHAPE CHANGING OPERATORS
629 631
630The following operators modify the shape, size or position of the image. 632The following operators modify the shape, size or position of the image.
631 633
632=over 4 634=over
633 635
634=item clip $img 636=item clip $img
635 637
636=item clip $width, $height, $img 638=item clip $width, $height, $img
637 639
824 826
825=head2 COLOUR MODIFICATIONS 827=head2 COLOUR MODIFICATIONS
826 828
827The following operators change the pixels of the image. 829The following operators change the pixels of the image.
828 830
829=over 4 831=over
830 832
831=item tint $color, $img 833=item tint $color, $img
832 834
833Tints the image in the given colour. 835Tints the image in the given colour.
834 836
999=head2 OTHER STUFF 1001=head2 OTHER STUFF
1000 1002
1001Anything that didn't fit any of the other categories, even after applying 1003Anything that didn't fit any of the other categories, even after applying
1002force and closing our eyes. 1004force and closing our eyes.
1003 1005
1004=over 4 1006=over
1005 1007
1006=item keep { ... } 1008=item keep { ... }
1007 1009
1008This operator takes a code block as argument, that is, one or more 1010This operator takes a code block as argument, that is, one or more
1009statements enclosed by braces. 1011statements enclosed by braces.
1042OSC sequences for setting a background image. These settings are 1044OSC sequences for setting a background image. These settings are
1043B<deprecated> and will be removed in future versions. 1045B<deprecated> and will be removed in future versions.
1044 1046
1045=head2 OPTIONS AND RESOURCES 1047=head2 OPTIONS AND RESOURCES
1046 1048
1047=over 4 1049=over
1048 1050
1049=item B<-pixmap> I<file[;oplist]> 1051=item B<-pixmap> I<file[;oplist]>
1050 1052
1051=item B<backgroundPixmap:> I<file[;oplist]> 1053=item B<backgroundPixmap:> I<file[;oplist]>
1052 1054
1054optionally specify a colon separated list of operations to modify it. 1056optionally specify a colon separated list of operations to modify it.
1055Note that you may need to quote the C<;> character when using the 1057Note that you may need to quote the C<;> character when using the
1056command line option, as C<;> is usually a metacharacter in shells. 1058command line option, as C<;> is usually a metacharacter in shells.
1057Supported operations are: 1059Supported operations are:
1058 1060
1059=over 4 1061=over
1060 1062
1061=item B<WxH+X+Y> 1063=item B<WxH+X+Y>
1062 1064
1063sets scale and position. B<"W" / "H"> specify the horizontal/vertical 1065sets scale and position. B<"W" / "H"> specify the horizontal/vertical
1064scale (percent), and B<"X" / "Y"> locate the image centre (percent). A 1066scale (percent), and B<"X" / "Y"> locate the image centre (percent). A
1081 1083
1082The default scale and position setting is C<100x100+50+50>. 1084The default scale and position setting is C<100x100+50+50>.
1083Alternatively, a predefined set of templates can be used to achieve 1085Alternatively, a predefined set of templates can be used to achieve
1084the most common setups: 1086the most common setups:
1085 1087
1086=over 4 1088=over
1087 1089
1088=item B<style=tiled> 1090=item B<style=tiled>
1089 1091
1090the image is tiled with no scaling. Equivalent to 0x0+0+0:op=tile 1092the image is tiled with no scaling. Equivalent to 0x0+0+0:op=tile
1091 1093
1156so to make urxvt recognize them, you have to enable the C<background> 1158so to make urxvt recognize them, you have to enable the C<background>
1157extension. One way to achieve that is to use the C<--background-expr ''> 1159extension. One way to achieve that is to use the C<--background-expr ''>
1158command line argument or by specifying an empty C<URxvt.background.expr:>> 1160command line argument or by specifying an empty C<URxvt.background.expr:>>
1159resource. 1161resource.
1160 1162
1161=over 4 1163=over
1162 1164
1163=item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>. 1165=item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>.
1164 1166
1165=item B<< C<ESC ] 20 ; Pt ST> >> Change/Query background image 1167=item B<< C<ESC ] 20 ; Pt ST> >> Change/Query background image
1166parameters: the value of B<< C<Pt> >> can be one of the following 1168parameters: the value of B<< C<Pt> >> can be one of the following
1167commands: 1169commands:
1168 1170
1169=over 4 1171=over
1170 1172
1171=item B<< C<?> >> 1173=item B<< C<?> >>
1172 1174
1173display scale and position in the title 1175display scale and position in the title
1174 1176
1320 } 1322 }
1321 1323
1322 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; 1324 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL;
1323 1325
1324 unless ($arg_self->has_render) { 1326 unless ($arg_self->has_render) {
1325 warn "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; 1327 warn "background extension needs RENDER extension 0.11 or higher, ignoring background-expr.\n";
1326 return; 1328 return;
1327 } 1329 }
1328 1330
1329 # set environment to evaluate user expression 1331 # set environment to evaluate user expression
1330 1332
1345 die "background-expr: expected image(s), got something else.\n" 1347 die "background-expr: expected image(s), got something else.\n"
1346 if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; 1348 if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img;
1347 1349
1348 my $img = urxvt::bgdsl::merge @img; 1350 my $img = urxvt::bgdsl::merge @img;
1349 1351
1350 $frame->[FR_AGAIN]{size} = 1 1352 $frame->[urxvt::bgdsl::FR_AGAIN]{size} = 1
1351 if $img->repeat_mode != urxvt::RepeatNormal; 1353 if $img->repeat_mode != urxvt::RepeatNormal;
1352 1354
1353 # if the expression is sensitive to external events, prepare reevaluation then 1355 # if the expression is sensitive to external events, prepare reevaluation then
1354 $self->compile_frame ($frame, sub { $arg_self->recalculate }); 1356 $self->compile_frame ($frame, sub { $arg_self->recalculate });
1355 1357
1533 } 1535 }
1534 1536
1535 $expr 1537 $expr
1536} 1538}
1537 1539
1540sub find_resource {
1541 my ($self, $res, $opt) = @_;
1542
1543 my $v = $self->x_resource ($opt);
1544 $v = $self->x_resource ($res) unless defined $v;
1545
1546 $v
1547}
1548
1549sub parse_bgopts {
1550 my ($self) = @_;
1551
1552 my $expr = $self->x_resource ("%.expr");
1553
1554 if (!$expr) {
1555 $self->{bg_opts} = { h_scale => 100, v_scale => 100,
1556 h_align => 50, v_align => 50 };
1557
1558 $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh");
1559 $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint");
1560 $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr");
1561 $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr");
1562
1563 $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap"));
1564 $expr = $self->old_bg_expr;
1565 }
1566
1567 $self->set_expr (parse_expr $expr);
1568 $self->{border} = $self->x_resource_boolean ("%.border");
1569
1570 $MIN_INTERVAL = $self->x_resource ("%.interval");
1571}
1572
1573sub on_start {
1574 my ($self) = @_;
1575
1576 $self->parse_bgopts;
1577
1578 ()
1579}
1580
1538sub on_osc_seq { 1581sub on_osc_seq {
1539 my ($self, $op, $arg) = @_; 1582 my ($self, $op, $arg) = @_;
1540 1583
1584 $op eq "20" or $op eq "706"
1585 or return;
1586
1541 $self->{bg_opts} or return; 1587 $self->{bg_opts}
1542 1588 or $self->parse_bgopts;
1543 $op =~ /^(?:20|705)$/ or return;
1544 1589
1545 if ($op eq "20") { 1590 if ($op eq "20") {
1546 if ($arg eq "?") { 1591 if ($arg eq "?") {
1547 my $h_scale = $self->{bg_opts}->{h_scale}; 1592 my $h_scale = $self->{bg_opts}{h_scale};
1548 my $v_scale = $self->{bg_opts}->{v_scale}; 1593 my $v_scale = $self->{bg_opts}{v_scale};
1549 my $h_align = $self->{bg_opts}->{h_align}; 1594 my $h_align = $self->{bg_opts}{h_align};
1550 my $v_align = $self->{bg_opts}->{v_align}; 1595 my $v_align = $self->{bg_opts}{v_align};
1551 $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007"); 1596 $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007");
1552 } else { 1597 } else {
1553 $self->old_bg_opts ($arg); 1598 $self->old_bg_opts ($arg);
1554 my $expr = $self->old_bg_expr; 1599 my $expr = $self->old_bg_expr;
1555 $self->set_expr (parse_expr $expr) if $expr; 1600 $self->set_expr (parse_expr $expr) if $expr;
1556 } 1601 }
1557 } elsif ($op eq "705") { 1602 } elsif ($op eq "705") {
1558 $self->{bg_opts}->{tint} = $arg; 1603 $self->{bg_opts}{tint} = $arg;
1559 my $expr = $self->old_bg_expr; 1604 my $expr = $self->old_bg_expr;
1560 $self->set_expr (parse_expr $expr) if $expr; 1605 $self->set_expr (parse_expr $expr) if $expr;
1561 } 1606 }
1562 1607
1563 1 1608 1
1564} 1609}
1565 1610
1566sub find_resource {
1567 my ($self, $res, $opt) = @_;
1568
1569 my $v = $self->x_resource ($opt);
1570 $v = $self->x_resource ($res) unless defined $v;
1571
1572 $v
1573}
1574
1575sub on_start {
1576 my ($self) = @_;
1577
1578 my $expr = $self->x_resource ("%.expr");
1579
1580 if (!$expr) {
1581 $self->{bg_opts} = { h_scale => 100, v_scale => 100,
1582 h_align => 50, v_align => 50 };
1583
1584 $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh");
1585 $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint");
1586 $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr");
1587 $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr");
1588
1589 $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap"));
1590 $expr = $self->old_bg_expr;
1591 }
1592
1593 $self->set_expr (parse_expr $expr);
1594 $self->{border} = $self->x_resource_boolean ("%.border");
1595
1596 $MIN_INTERVAL = $self->x_resource ("%.interval");
1597
1598 ()
1599}
1600

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines