… | |
… | |
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 | |
19 | background - manage terminal background |
21 | background - manage terminal background |
20 | |
22 | |
… | |
… | |
54 | is behind the text, replacing the normal background colour. |
56 | is behind the text, replacing the normal background colour. |
55 | |
57 | |
56 | It does so by evaluating a Perl expression that I<calculates> the image on |
58 | It does so by evaluating a Perl expression that I<calculates> the image on |
57 | the fly, for example, by grabbing the root background or loading a file. |
59 | the fly, for example, by grabbing the root background or loading a file. |
58 | |
60 | |
59 | While the full power of Perl is available, the operators have been design |
61 | While the full power of Perl is available, the operators have been |
60 | to be as simple as possible. |
62 | designed to be as simple as possible. |
61 | |
63 | |
62 | For example, to load an image and scale it to the window size, you would |
64 | For example, to load an image and scale it to the window size, you would |
63 | use: |
65 | use: |
64 | |
66 | |
65 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
67 | urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' |
… | |
… | |
984 | |
986 | |
985 | return $img |
987 | return $img |
986 | if FOCUS; |
988 | if FOCUS; |
987 | |
989 | |
988 | 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; |
989 | 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 |
990 | |
992 | |
991 | $img = $img->tint ($color) if $color ne "rgb:00/00/00"; |
993 | $img = $img->tint ($color) if $color ne "rgb:00/00/00"; |
992 | $img = $img->muladd (1 - $fade, 0) if $fade; |
994 | $img = $img->muladd (1 - $fade, 0) if $fade; |
993 | |
995 | |
994 | $img |
996 | $img |
… | |
… | |
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 | |
… | |
… | |
1446 | } |
1448 | } |
1447 | } |
1449 | } |
1448 | } |
1450 | } |
1449 | |
1451 | |
1450 | # helper function, quote string as perl without allowing |
1452 | # helper function, quote string as perl without allowing |
1451 | # any code execution or other shenanigans. does not |
1453 | # any code execution or other shenanigans. |
1452 | # support binary NULs in string. |
|
|
1453 | sub q0 { |
1454 | sub q0 { |
1454 | (my $str = shift) =~ s/\x00//g; # make sure there really aren't any embedded NULs |
|
|
1455 | "q\x00$str\x00" |
1455 | "qq\x00\Q$_\E\x00" |
1456 | } |
1456 | } |
1457 | |
1457 | |
1458 | sub old_bg_expr { |
1458 | sub old_bg_expr { |
1459 | my ($self) = @_; |
1459 | my ($self) = @_; |
1460 | |
1460 | |
… | |
… | |
1533 | } |
1533 | } |
1534 | |
1534 | |
1535 | $expr |
1535 | $expr |
1536 | } |
1536 | } |
1537 | |
1537 | |
|
|
1538 | sub find_resource { |
|
|
1539 | my ($self, $res, $opt) = @_; |
|
|
1540 | |
|
|
1541 | my $v = $self->x_resource ($opt); |
|
|
1542 | $v = $self->x_resource ($res) unless defined $v; |
|
|
1543 | |
|
|
1544 | $v |
|
|
1545 | } |
|
|
1546 | |
|
|
1547 | sub parse_bgopts { |
|
|
1548 | my ($self) = @_; |
|
|
1549 | |
|
|
1550 | my $expr = $self->x_resource ("%.expr"); |
|
|
1551 | |
|
|
1552 | if (!$expr) { |
|
|
1553 | $self->{bg_opts} = { h_scale => 100, v_scale => 100, |
|
|
1554 | h_align => 50, v_align => 50 }; |
|
|
1555 | |
|
|
1556 | $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh"); |
|
|
1557 | $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint"); |
|
|
1558 | $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr"); |
|
|
1559 | $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr"); |
|
|
1560 | |
|
|
1561 | $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap")); |
|
|
1562 | $expr = $self->old_bg_expr; |
|
|
1563 | } |
|
|
1564 | |
|
|
1565 | $self->set_expr (parse_expr $expr); |
|
|
1566 | $self->{border} = $self->x_resource_boolean ("%.border"); |
|
|
1567 | |
|
|
1568 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
|
|
1569 | } |
|
|
1570 | |
|
|
1571 | sub on_start { |
|
|
1572 | my ($self) = @_; |
|
|
1573 | |
|
|
1574 | $self->parse_bgopts; |
|
|
1575 | |
|
|
1576 | () |
|
|
1577 | } |
|
|
1578 | |
1538 | sub on_osc_seq { |
1579 | sub on_osc_seq { |
1539 | my ($self, $op, $arg) = @_; |
1580 | my ($self, $op, $arg) = @_; |
1540 | |
1581 | |
|
|
1582 | $op eq "20" or $op eq "706" |
|
|
1583 | or return; |
|
|
1584 | |
1541 | $self->{bg_opts} or return; |
1585 | $self->{bg_opts} |
1542 | |
1586 | or $self->parse_bgopts; |
1543 | $op =~ /^(?:20|705)$/ or return; |
|
|
1544 | |
1587 | |
1545 | if ($op eq "20") { |
1588 | if ($op eq "20") { |
1546 | if ($arg eq "?") { |
1589 | if ($arg eq "?") { |
1547 | my $h_scale = $self->{bg_opts}->{h_scale}; |
1590 | my $h_scale = $self->{bg_opts}{h_scale}; |
1548 | my $v_scale = $self->{bg_opts}->{v_scale}; |
1591 | my $v_scale = $self->{bg_opts}{v_scale}; |
1549 | my $h_align = $self->{bg_opts}->{h_align}; |
1592 | my $h_align = $self->{bg_opts}{h_align}; |
1550 | my $v_align = $self->{bg_opts}->{v_align}; |
1593 | my $v_align = $self->{bg_opts}{v_align}; |
1551 | $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007"); |
1594 | $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007"); |
1552 | } else { |
1595 | } else { |
1553 | $self->old_bg_opts ($arg); |
1596 | $self->old_bg_opts ($arg); |
1554 | my $expr = $self->old_bg_expr; |
1597 | my $expr = $self->old_bg_expr; |
1555 | $self->set_expr (parse_expr $expr) if $expr; |
1598 | $self->set_expr (parse_expr $expr) if $expr; |
1556 | } |
1599 | } |
1557 | } elsif ($op eq "705") { |
1600 | } elsif ($op eq "705") { |
1558 | $self->{bg_opts}->{tint} = $arg; |
1601 | $self->{bg_opts}{tint} = $arg; |
1559 | my $expr = $self->old_bg_expr; |
1602 | my $expr = $self->old_bg_expr; |
1560 | $self->set_expr (parse_expr $expr) if $expr; |
1603 | $self->set_expr (parse_expr $expr) if $expr; |
1561 | } |
1604 | } |
1562 | |
1605 | |
1563 | 1 |
1606 | 1 |
1564 | } |
1607 | } |
1565 | |
1608 | |
1566 | sub 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 | |
|
|
1575 | sub 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 | |
|
|