… | |
… | |
24 | --background-border |
24 | --background-border |
25 | --background-interval seconds |
25 | --background-interval seconds |
26 | |
26 | |
27 | =head1 QUICK AND DIRTY CHEAT SHEET |
27 | =head1 QUICK AND DIRTY CHEAT SHEET |
28 | |
28 | |
29 | Just load a random jpeg image and tile the background with it without |
29 | Load a random jpeg image and tile the background with it without scaling |
30 | scaling or anything else: |
30 | or anything else: |
31 | |
31 | |
32 | load "/path/to/img.jpg" |
32 | load "/path/to/img.jpg" |
33 | |
33 | |
34 | The same, but use mirroring/reflection instead of tiling: |
34 | The same, but use mirroring/reflection instead of tiling: |
35 | |
35 | |
… | |
… | |
1148 | vertical radius of 0 disables blurring. |
1148 | vertical radius of 0 disables blurring. |
1149 | |
1149 | |
1150 | =back |
1150 | =back |
1151 | |
1151 | |
1152 | =head2 OSC sequences |
1152 | =head2 OSC sequences |
|
|
1153 | |
|
|
1154 | This extension will react to the following OSC sequences. Note that |
|
|
1155 | this extension will not be autoloaded when these are used currenmtly, |
|
|
1156 | so to make urxvt recognize them, you have to enable the C<background> |
|
|
1157 | extension. One way to achieve that is to use the C<--background-expr ''> |
|
|
1158 | command line argument or by specifying an empty C<URxvt.background.expr:>> |
|
|
1159 | resource. |
1153 | |
1160 | |
1154 | =over 4 |
1161 | =over 4 |
1155 | |
1162 | |
1156 | =item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>. |
1163 | =item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>. |
1157 | |
1164 | |
… | |
… | |
1214 | =cut |
1221 | =cut |
1215 | |
1222 | |
1216 | } |
1223 | } |
1217 | |
1224 | |
1218 | sub parse_expr { |
1225 | sub parse_expr { |
|
|
1226 | my ($expr) = @_; |
|
|
1227 | |
|
|
1228 | # an empty expression is valid and represents the default background |
|
|
1229 | if ($expr !~ /\S/) { |
|
|
1230 | $expr = sub { |
|
|
1231 | undef |
|
|
1232 | }; |
|
|
1233 | } else { |
1219 | my $expr = eval |
1234 | $expr = eval |
1220 | "sub {\n" |
1235 | "sub {\n" |
1221 | . "package urxvt::bgdsl;\n" |
1236 | . "package urxvt::bgdsl;\n" |
1222 | . "#line 0 'background expression'\n" |
1237 | . "#line 0 'background expression'\n" |
1223 | . "$_[0]\n" |
1238 | . "$expr\n" |
1224 | . "}"; |
1239 | . "}"; |
1225 | die if $@; |
1240 | die if $@; |
|
|
1241 | } |
|
|
1242 | |
1226 | $expr |
1243 | $expr |
1227 | } |
1244 | } |
1228 | |
1245 | |
1229 | # compiles a parsed expression |
1246 | # compiles a parsed expression |
1230 | sub set_expr { |
1247 | sub set_expr { |
… | |
… | |
1302 | return; |
1319 | return; |
1303 | } |
1320 | } |
1304 | |
1321 | |
1305 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
1322 | $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
1306 | |
1323 | |
|
|
1324 | unless ($arg_self->has_render) { |
|
|
1325 | warn "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
|
|
1326 | return; |
|
|
1327 | } |
|
|
1328 | |
1307 | # set environment to evaluate user expression |
1329 | # set environment to evaluate user expression |
1308 | |
1330 | |
1309 | local $self = $arg_self; |
1331 | local $self = $arg_self; |
1310 | local $HOME = $ENV{HOME}; |
1332 | local $HOME = $ENV{HOME}; |
1311 | local $frame = $self->{root}; |
1333 | local $frame = $self->{root}; |
… | |
… | |
1316 | # evaluate user expression |
1338 | # evaluate user expression |
1317 | |
1339 | |
1318 | my @img = eval { $self->{expr}->() }; |
1340 | my @img = eval { $self->{expr}->() }; |
1319 | die $@ if $@; |
1341 | die $@ if $@; |
1320 | die "background-expr did not return anything.\n" unless @img; |
1342 | die "background-expr did not return anything.\n" unless @img; |
|
|
1343 | |
|
|
1344 | if ($img[0]) { |
1321 | die "background-expr: expected image(s), got something else.\n" |
1345 | die "background-expr: expected image(s), got something else.\n" |
1322 | if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; |
1346 | if grep { !UNIVERSAL::isa $_, "urxvt::img" } @img; |
1323 | |
1347 | |
1324 | my $img = urxvt::bgdsl::merge @img; |
1348 | my $img = urxvt::bgdsl::merge @img; |
1325 | |
1349 | |
1326 | $frame->[FR_AGAIN]{size} = 1 |
1350 | $frame->[FR_AGAIN]{size} = 1 |
1327 | if $img->repeat_mode != urxvt::RepeatNormal; |
1351 | if $img->repeat_mode != urxvt::RepeatNormal; |
1328 | |
1352 | |
1329 | # if the expression is sensitive to external events, prepare reevaluation then |
1353 | # if the expression is sensitive to external events, prepare reevaluation then |
1330 | $self->compile_frame ($frame, sub { $arg_self->recalculate }); |
1354 | $self->compile_frame ($frame, sub { $arg_self->recalculate }); |
1331 | |
1355 | |
1332 | # clear stuff we no longer need |
1356 | # clear stuff we no longer need |
1333 | |
1357 | |
1334 | # unless (%{ $frame->[FR_STATE] }) { |
1358 | # unless (%{ $frame->[FR_STATE] }) { |
1335 | # delete $self->{state}; |
1359 | # delete $self->{state}; |
1336 | # delete $self->{expr}; |
1360 | # delete $self->{expr}; |
1337 | # } |
1361 | # } |
1338 | |
1362 | |
1339 | # set background pixmap |
1363 | # set background pixmap |
1340 | |
1364 | |
1341 | $self->set_background ($img, $self->{border}); |
1365 | $self->set_background ($img, $self->{border}); |
|
|
1366 | } else { |
|
|
1367 | $self->clr_background; |
|
|
1368 | } |
|
|
1369 | |
1342 | $self->scr_recolor (0); |
1370 | $self->scr_recolor (0); |
1343 | $self->want_refresh; |
1371 | $self->want_refresh; |
1344 | } |
1372 | } |
1345 | |
1373 | |
1346 | sub old_bg_opts { |
1374 | sub old_bg_opts { |
… | |
… | |
1353 | return unless $str[0] or $self->{bg_opts}->{path}; |
1381 | return unless $str[0] or $self->{bg_opts}->{path}; |
1354 | |
1382 | |
1355 | my $bg_opts = $self->{bg_opts}; |
1383 | my $bg_opts = $self->{bg_opts}; |
1356 | |
1384 | |
1357 | if ($str[0]) { |
1385 | if ($str[0]) { |
1358 | $bg_opts->{tile} = 0; |
1386 | $bg_opts->{tile} = 0; |
1359 | $bg_opts->{keep_aspect} = 0; |
1387 | $bg_opts->{keep_aspect} = 0; |
1360 | $bg_opts->{root_align} = 0; |
1388 | $bg_opts->{root_align} = 0; |
1361 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
1389 | $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100; |
1362 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
1390 | $bg_opts->{h_align} = $bg_opts->{v_align} = 50; |
1363 | $bg_opts->{path} = unpack "H*", $str[0]; |
1391 | $bg_opts->{path} = $str[0]; |
1364 | } |
1392 | } |
1365 | |
1393 | |
1366 | my @oplist = split /:/, $str[1]; |
1394 | my @oplist = split /:/, $str[1]; |
1367 | |
1395 | |
1368 | for (@oplist) { |
1396 | for (@oplist) { |
… | |
… | |
1417 | $bg_opts->{v_align} = $y if defined $y; |
1445 | $bg_opts->{v_align} = $y if defined $y; |
1418 | } |
1446 | } |
1419 | } |
1447 | } |
1420 | } |
1448 | } |
1421 | |
1449 | |
|
|
1450 | # helper function, quote string as perl without allowing |
|
|
1451 | # any code execution or other shenanigans. does not |
|
|
1452 | # support binary NULs in string. |
|
|
1453 | sub q0 { |
|
|
1454 | (my $str = shift) =~ s/\x00//g; # make sure there really aren't any embedded NULs |
|
|
1455 | "q\x00$str\x00" |
|
|
1456 | } |
|
|
1457 | |
1422 | sub old_bg_expr { |
1458 | sub old_bg_expr { |
1423 | my ($self) = @_; |
1459 | my ($self) = @_; |
1424 | |
1460 | |
1425 | my $expr; |
1461 | my $expr; |
1426 | |
1462 | |
… | |
… | |
1441 | } |
1477 | } |
1442 | |
1478 | |
1443 | my $tint = $bg_opts->{tint}; |
1479 | my $tint = $bg_opts->{tint}; |
1444 | |
1480 | |
1445 | if ($tint) { |
1481 | if ($tint) { |
|
|
1482 | $tint = q0 $tint; |
1446 | $expr .= "tint $tint, "; |
1483 | $expr .= "tint $tint,"; |
1447 | } |
1484 | } |
1448 | |
1485 | |
1449 | my $blur = $bg_opts->{blur}; |
1486 | my $blur = $bg_opts->{blur}; |
1450 | |
1487 | |
1451 | if ($blur and $blur =~ /^ =? ([0-9]+)? (?:[xX] ([0-9]+))? $/x) { |
1488 | if ($blur and $blur =~ /^ =? ([0-9]+)? (?:[xX] ([0-9]+))? $/x) { |
… | |
… | |
1482 | if ($h_scale != 0 and $v_scale != 0) { |
1519 | if ($h_scale != 0 and $v_scale != 0) { |
1483 | my $op = $bg_opts->{keep_aspect} ? "fit" : "resize"; |
1520 | my $op = $bg_opts->{keep_aspect} ? "fit" : "resize"; |
1484 | $file_expr .= "$op TW * $h_scale, TH * $v_scale, "; |
1521 | $file_expr .= "$op TW * $h_scale, TH * $v_scale, "; |
1485 | } |
1522 | } |
1486 | |
1523 | |
|
|
1524 | my $path = q0 $bg_opts->{path}; |
|
|
1525 | |
1487 | $file_expr .= "keep { load pack \"H*\", \"$bg_opts->{path}\" })"; |
1526 | $file_expr .= "keep { load $path })"; |
1488 | |
1527 | |
1489 | if ($expr) { |
1528 | if ($expr) { |
1490 | $expr .= ", tint (\"[50]white\", $file_expr)"; |
1529 | $expr .= ", tint (\"[50]white\", $file_expr)"; |
1491 | } else { |
1530 | } else { |
1492 | $expr = $file_expr; |
1531 | $expr = $file_expr; |
… | |
… | |
1499 | sub on_osc_seq { |
1538 | sub on_osc_seq { |
1500 | my ($self, $op, $arg) = @_; |
1539 | my ($self, $op, $arg) = @_; |
1501 | |
1540 | |
1502 | $self->{bg_opts} or return; |
1541 | $self->{bg_opts} or return; |
1503 | |
1542 | |
1504 | $op =~ /^(20|705)$/ or return; |
1543 | $op =~ /^(?:20|705)$/ or return; |
1505 | |
1544 | |
1506 | if ($op eq "20") { |
1545 | if ($op eq "20") { |
1507 | if ($arg eq "?") { |
1546 | if ($arg eq "?") { |
1508 | my $h_scale = $self->{bg_opts}->{h_scale}; |
1547 | my $h_scale = $self->{bg_opts}->{h_scale}; |
1509 | my $v_scale = $self->{bg_opts}->{v_scale}; |
1548 | my $v_scale = $self->{bg_opts}->{v_scale}; |
… | |
… | |
1540 | |
1579 | |
1541 | if (!$expr) { |
1580 | if (!$expr) { |
1542 | $self->{bg_opts} = { h_scale => 100, v_scale => 100, |
1581 | $self->{bg_opts} = { h_scale => 100, v_scale => 100, |
1543 | h_align => 50, v_align => 50 }; |
1582 | h_align => 50, v_align => 50 }; |
1544 | |
1583 | |
1545 | $self->{bg_opts}->{shade} = $self->find_resource ("shading", "sh"); |
1584 | $self->{bg_opts}{shade} = $self->find_resource ("shading", "sh"); |
1546 | $self->{bg_opts}->{tint} = $self->find_resource ("tintColor", "tint"); |
1585 | $self->{bg_opts}{tint} = $self->find_resource ("tintColor", "tint"); |
1547 | $self->{bg_opts}->{blur} = $self->find_resource ("blurRadius", "blr"); |
1586 | $self->{bg_opts}{blur} = $self->find_resource ("blurRadius", "blr"); |
1548 | $self->{bg_opts}->{root} = $self->find_resource ("transparent", "tr"); |
1587 | $self->{bg_opts}{root} = $self->find_resource ("transparent", "tr"); |
1549 | |
1588 | |
1550 | $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap")); |
1589 | $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap")); |
1551 | $expr = $self->old_bg_expr; |
1590 | $expr = $self->old_bg_expr; |
1552 | } |
1591 | } |
1553 | |
1592 | |
1554 | $expr or return; |
|
|
1555 | |
|
|
1556 | $self->has_render |
|
|
1557 | or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n"; |
|
|
1558 | |
|
|
1559 | $self->set_expr (parse_expr $expr); |
1593 | $self->set_expr (parse_expr $expr); |
1560 | $self->{border} = $self->x_resource_boolean ("%.border"); |
1594 | $self->{border} = $self->x_resource_boolean ("%.border"); |
1561 | |
1595 | |
1562 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
1596 | $MIN_INTERVAL = $self->x_resource ("%.interval"); |
1563 | |
1597 | |