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.101 by root, Sat Jul 24 11:58:27 2021 UTC vs.
Revision 1.106 by root, Tue Nov 29 04:44:27 2022 UTC

56is behind the text, replacing the normal background colour. 56is behind the text, replacing the normal background colour.
57 57
58It 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
59the 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.
60 60
61While the full power of Perl is available, the operators have been design 61While the full power of Perl is available, the operators have been
62to be as simple as possible. 62designed to be as simple as possible.
63 63
64For 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
65use: 65use:
66 66
67 urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' 67 urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }'
986 986
987 return $img 987 return $img
988 if FOCUS; 988 if FOCUS;
989 989
990 my $fade = @_ >= 1 ? $_[0] : defined $self->resource ("fade") ? $self->resource ("fade") * 0.01 : 0; 990 my $fade = @_ >= 1 ? $_[0] : defined $self->resource ("fade") ? $self->resource ("fade") * 0.01 : 0;
991 my $color = @_ >= 2 ? $_[1] : $self->resource ("color+" . urxvt::Color_fade); 991 my $color = @_ >= 2 ? $_[1] : $self->resource ("color+" . &urxvt::Color_fade ()); # Color_fade not always available
992 992
993 $img = $img->tint ($color) if $color ne "rgb:00/00/00"; 993 $img = $img->tint ($color) if $color ne "rgb:00/00/00";
994 $img = $img->muladd (1 - $fade, 0) if $fade; 994 $img = $img->muladd (1 - $fade, 0) if $fade;
995 995
996 $img 996 $img
1322 } 1322 }
1323 1323
1324 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; 1324 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL;
1325 1325
1326 unless ($arg_self->has_render) { 1326 unless ($arg_self->has_render) {
1327 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";
1328 return; 1328 return;
1329 } 1329 }
1330 1330
1331 # set environment to evaluate user expression 1331 # set environment to evaluate user expression
1332 1332
1452# helper function, quote string as perl without allowing 1452# helper function, quote string as perl without allowing
1453# any code execution or other shenanigans. does not 1453# any code execution or other shenanigans. does not
1454# support binary NULs in string. 1454# support binary NULs in string.
1455sub q0 { 1455sub q0 {
1456 (my $str = shift) =~ s/\x00//g; # make sure there really aren't any embedded NULs 1456 (my $str = shift) =~ s/\x00//g; # make sure there really aren't any embedded NULs
1457 "q\x00$str\x00" 1457 "q\x00\Q$str\E\x00"
1458} 1458}
1459 1459
1460sub old_bg_expr { 1460sub old_bg_expr {
1461 my ($self) = @_; 1461 my ($self) = @_;
1462 1462
1535 } 1535 }
1536 1536
1537 $expr 1537 $expr
1538} 1538}
1539 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
1540sub on_osc_seq { 1581sub on_osc_seq {
1541 my ($self, $op, $arg) = @_; 1582 my ($self, $op, $arg) = @_;
1542 1583
1584 $op eq "20" or $op eq "706"
1585 or return;
1586
1543 $self->{bg_opts} or return; 1587 $self->{bg_opts}
1544 1588 or $self->parse_bgopts;
1545 $op =~ /^(?:20|705)$/ or return;
1546 1589
1547 if ($op eq "20") { 1590 if ($op eq "20") {
1548 if ($arg eq "?") { 1591 if ($arg eq "?") {
1549 my $h_scale = $self->{bg_opts}->{h_scale}; 1592 my $h_scale = $self->{bg_opts}{h_scale};
1550 my $v_scale = $self->{bg_opts}->{v_scale}; 1593 my $v_scale = $self->{bg_opts}{v_scale};
1551 my $h_align = $self->{bg_opts}->{h_align}; 1594 my $h_align = $self->{bg_opts}{h_align};
1552 my $v_align = $self->{bg_opts}->{v_align}; 1595 my $v_align = $self->{bg_opts}{v_align};
1553 $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");
1554 } else { 1597 } else {
1555 $self->old_bg_opts ($arg); 1598 $self->old_bg_opts ($arg);
1556 my $expr = $self->old_bg_expr; 1599 my $expr = $self->old_bg_expr;
1557 $self->set_expr (parse_expr $expr) if $expr; 1600 $self->set_expr (parse_expr $expr) if $expr;
1558 } 1601 }
1559 } elsif ($op eq "705") { 1602 } elsif ($op eq "705") {
1560 $self->{bg_opts}->{tint} = $arg; 1603 $self->{bg_opts}{tint} = $arg;
1561 my $expr = $self->old_bg_expr; 1604 my $expr = $self->old_bg_expr;
1562 $self->set_expr (parse_expr $expr) if $expr; 1605 $self->set_expr (parse_expr $expr) if $expr;
1563 } 1606 }
1564 1607
1565 1 1608 1
1566} 1609}
1567 1610
1568sub find_resource {
1569 my ($self, $res, $opt) = @_;
1570
1571 my $v = $self->x_resource ($opt);
1572 $v = $self->x_resource ($res) unless defined $v;
1573
1574 $v
1575}
1576
1577sub on_start {
1578 my ($self) = @_;
1579
1580 my $expr = $self->x_resource ("%.expr");
1581
1582 if (!$expr) {
1583 $self->{bg_opts} = { h_scale => 100, v_scale => 100,
1584 h_align => 50, v_align => 50 };
1585
1586 $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh");
1587 $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint");
1588 $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr");
1589 $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr");
1590
1591 $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap"));
1592 $expr = $self->old_bg_expr;
1593 }
1594
1595 $self->set_expr (parse_expr $expr);
1596 $self->{border} = $self->x_resource_boolean ("%.border");
1597
1598 $MIN_INTERVAL = $self->x_resource ("%.interval");
1599
1600 ()
1601}
1602

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines