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.79 by root, Tue Sep 4 22:41:11 2012 UTC vs.
Revision 1.96 by root, Tue Sep 17 17:57:49 2019 UTC

1#! perl 1#! perl
2 2
3#:META:X_RESOURCE:%.expr:string:background expression 3#:META:RESOURCE:%.expr:string:background expression
4#:META:X_RESOURCE:%.border:boolean:respect the terminal border 4#:META:RESOURCE:%.border:boolean:respect the terminal border
5#:META:X_RESOURCE:%.interval:seconds:minimum time between updates 5#:META:RESOURCE:%.interval:seconds:minimum time between updates
6#:META:RESOURCE:pixmap:file[;geom]:set image as background
7#:META:RESOURCE:backgroundPixmap:file[;geom]:set image as background
8#:META:RESOURCE:tr:boolean:set root pixmap as background
9#:META:RESOURCE:transparent:boolean:set root pixmap as background
10#:META:RESOURCE:tint:color:tint background with color
11#:META:RESOURCE:tintColor:color:tint background with color
12#:META:RESOURCE:sh:number:shade background by number %
13#:META:RESOURCE:shading:number:shade background by number %
14#:META:RESOURCE:blr:HxV:gaussian-blur background with radii
15#:META:RESOURCE:blurRadius:HxV:gaussian-blur background with radii
6 16
7=head1 NAME 17=head1 NAME
8 18
9background - manage terminal background 19background - manage terminal background
10 20
54 64
55 urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }' 65 urxvt --background-expr 'scale keep { load "/path/to/mybg.png" }'
56 66
57Or specified as a X resource: 67Or specified as a X resource:
58 68
59 URxvt.background-expr: scale keep { load "/path/to/mybg.png" } 69 URxvt.background.expr: scale keep { load "/path/to/mybg.png" }
60 70
61=head1 THEORY OF OPERATION 71=head1 THEORY OF OPERATION
62 72
63At startup, just before the window is mapped for the first time, the 73At startup, just before the window is mapped for the first time, the
64expression is evaluated and must yield an image. The image is then 74expression is evaluated and must yield an image. The image is then
132get a percentage): 142get a percentage):
133 143
134 scale 2, load "$HOME/mypic.png" 144 scale 2, load "$HOME/mypic.png"
135 145
136This enlarges the image by a factor of 2 (200%). As you can see, C<scale> 146This enlarges the image by a factor of 2 (200%). As you can see, C<scale>
137has now two arguments, the C<200> and the C<load> expression, while 147has now two arguments, the C<2> and the C<load> expression, while
138C<load> only has one argument. Arguments are separated from each other by 148C<load> only has one argument. Arguments are separated from each other by
139commas. 149commas.
140 150
141Scale also accepts two arguments, which are then separate factors for both 151Scale also accepts two arguments, which are then separate factors for both
142horizontal and vertical dimensions. For example, this halves the image 152horizontal and vertical dimensions. For example, this halves the image
279=cut 289=cut
280 290
281our %_IMG_CACHE; 291our %_IMG_CACHE;
282our $HOME; 292our $HOME;
283our ($self, $frame); 293our ($self, $frame);
284our ($x, $y, $w, $h); 294our ($x, $y, $w, $h, $focus);
285 295
286# enforce at least this interval between updates 296# enforce at least this interval between updates
287our $MIN_INTERVAL = 6/59.951; 297our $MIN_INTERVAL = 6/59.951;
288 298
289{ 299{
308 318
309Loads the image at the given C<$path>. The image is set to plane tiling 319Loads the image at the given C<$path>. The image is set to plane tiling
310mode. 320mode.
311 321
312If the image is already in memory (e.g. because another terminal instance 322If the image is already in memory (e.g. because another terminal instance
313uses it), then the in-memory copy us returned instead. 323uses it), then the in-memory copy is returned instead.
314 324
315=item load_uc $path 325=item load_uc $path
316 326
317Load uncached - same as load, but does not cache the image, which means it 327Load uncached - same as load, but does not cache the image, which means it
318is I<always> loaded from the filesystem again, even if another copy of it 328is I<always> loaded from the filesystem again, even if another copy of it
524 534
525Return the X and Y coordinates of the terminal window (the terminal 535Return the X and Y coordinates of the terminal window (the terminal
526window is the full window by default, and the character area only when in 536window is the full window by default, and the character area only when in
527border-respect mode). 537border-respect mode).
528 538
529Using these functions make your expression sensitive to window moves. 539Using these functions makes your expression sensitive to window moves.
530 540
531These functions are mainly useful to align images to the root window. 541These functions are mainly useful to align images to the root window.
532 542
533Example: load an image and align it so it looks as if anchored to the 543Example: load an image and align it so it looks as if anchored to the
534background (that's exactly what C<rootalign> does btw.): 544background (that's exactly what C<rootalign> does btw.):
541 551
542Return the width (C<TW>) and height (C<TH>) of the terminal window (the 552Return the width (C<TW>) and height (C<TH>) of the terminal window (the
543terminal window is the full window by default, and the character area only 553terminal window is the full window by default, and the character area only
544when in border-respect mode). 554when in border-respect mode).
545 555
546Using these functions make your expression sensitive to window resizes. 556Using these functions makes your expression sensitive to window resizes.
547 557
548These functions are mainly useful to scale images, or to clip images to 558These functions are mainly useful to scale images, or to clip images to
549the window size to conserve memory. 559the window size to conserve memory.
550 560
551Example: take the screen background, clip it to the window size, blur it a 561Example: take the screen background, clip it to the window size, blur it a
552bit, align it to the window position and use it as background. 562bit, align it to the window position and use it as background.
553 563
554 clip move -TX, -TY, keep { blur 5, root } 564 clip move -TX, -TY, keep { blur 5, root }
555 565
556=cut 566=item FOCUS
557 567
568Returns a boolean indicating whether the terminal window has keyboard
569focus, in which case it returns true.
570
571Using this function makes your expression sensitive to focus changes.
572
573A common use case is to fade the background image when the terminal loses
574focus, often together with the C<-fade> command line option. In fact,
575there is a special function for just that use case: C<focus_fade>.
576
577Example: use two entirely different background images, depending on
578whether the window has focus.
579
580 FOCUS ? keep { load "has_focus.jpg" } : keep { load "no_focus.jpg" }
581
582=cut
583
558 sub TX() { $frame->[FR_AGAIN]{position} = 1; $x } 584 sub TX () { $frame->[FR_AGAIN]{position} = 1; $x }
559 sub TY() { $frame->[FR_AGAIN]{position} = 1; $y } 585 sub TY () { $frame->[FR_AGAIN]{position} = 1; $y }
560 sub TW() { $frame->[FR_AGAIN]{size} = 1; $w } 586 sub TW () { $frame->[FR_AGAIN]{size} = 1; $w }
561 sub TH() { $frame->[FR_AGAIN]{size} = 1; $h } 587 sub TH () { $frame->[FR_AGAIN]{size} = 1; $h }
588 sub FOCUS() { $frame->[FR_AGAIN]{focus} = 1; $focus }
562 589
563=item now 590=item now
564 591
565Returns the current time as (fractional) seconds since the epoch. 592Returns the current time as (fractional) seconds since the epoch.
566 593
641=item scale $width_factor, $height_factor, $img 668=item scale $width_factor, $height_factor, $img
642 669
643Scales the image by the given factors in horizontal 670Scales the image by the given factors in horizontal
644(C<$width>) and vertical (C<$height>) direction. 671(C<$width>) and vertical (C<$height>) direction.
645 672
646If only one factor is give, it is used for both directions. 673If only one factor is given, it is used for both directions.
647 674
648If no factors are given, scales the image to the window size without 675If no factors are given, scales the image to the window size without
649keeping aspect. 676keeping aspect.
650 677
651=item resize $width, $height, $img 678=item resize $width, $height, $img
776=item rotate $center_x, $center_y, $degrees, $img 803=item rotate $center_x, $center_y, $degrees, $img
777 804
778Rotates the image clockwise by C<$degrees> degrees, around the point at 805Rotates the image clockwise by C<$degrees> degrees, around the point at
779C<$center_x> and C<$center_y> (specified as factor of image width/height). 806C<$center_x> and C<$center_y> (specified as factor of image width/height).
780 807
781Example: rotate the image by 90 degrees around it's center. 808Example: rotate the image by 90 degrees around its center.
782 809
783 rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" } 810 rotate 0.5, 0.5, 90, keep { load "$HOME/mybg.png" }
784 811
785=cut 812=cut
786 813
817 844
818 sub tint($$) { 845 sub tint($$) {
819 $_[1]->tint ($_[0]) 846 $_[1]->tint ($_[0])
820 } 847 }
821 848
849=item shade $factor, $img
850
851Shade the image by the given factor.
852
853=cut
854
855 sub shade($$) {
856 $_[1]->shade ($_[0])
857 }
858
822=item contrast $factor, $img 859=item contrast $factor, $img
823 860
824=item contrast $r, $g, $b, $img 861=item contrast $r, $g, $b, $img
825 862
826=item contrast $r, $g, $b, $a, $img 863=item contrast $r, $g, $b, $a, $img
885 $img 922 $img
886 } 923 }
887 924
888=item muladd $mul, $add, $img # EXPERIMENTAL 925=item muladd $mul, $add, $img # EXPERIMENTAL
889 926
890First multipliesthe pixels by C<$mul>, then adds C<$add>. This cna be used 927First multiplies the pixels by C<$mul>, then adds C<$add>. This can be used
891to implement brightness and contrast at the same time, with a wider value 928to implement brightness and contrast at the same time, with a wider value
892range than contrast and brightness operators. 929range than contrast and brightness operators.
893 930
894Due to numerous bugs in XRender implementations, it can also introduce a 931Due to numerous bugs in XRender implementations, it can also introduce a
895number of visual artifacts. 932number of visual artifacts.
920=cut 957=cut
921 958
922 sub blur($$;$) { 959 sub blur($$;$) {
923 my $img = pop; 960 my $img = pop;
924 $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) 961 $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0])
962 }
963
964=item focus_fade $img
965
966=item focus_fade $factor, $img
967
968=item focus_fade $factor, $color, $img
969
970Fades the image by the given factor (and colour) when focus is lost (the
971same as the C<-fade>/C<-fadecolor> command line options, which also supply
972the default values for C<factor> and C<$color>. Unlike with C<-fade>, the
973C<$factor> is a real value, not a percentage value (that is, 0..1, not
9740..100).
975
976Example: do the right thing when focus fading is requested.
977
978 focus_fade load "mybg.jpg";
979
980=cut
981
982 sub focus_fade($;$$) {
983 my $img = pop;
984
985 return $img
986 if FOCUS;
987
988 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);
990
991 $img = $img->tint ($color) if $color ne "rgb:00/00/00";
992 $img = $img->muladd (1 - $fade, 0) if $fade;
993
994 $img
925 } 995 }
926 996
927=back 997=back
928 998
929=head2 OTHER STUFF 999=head2 OTHER STUFF
961 1031
962This leaves the question of how to force reevaluation of the block, 1032This leaves the question of how to force reevaluation of the block,
963in case the root background changes: If expression inside the block 1033in case the root background changes: If expression inside the block
964is sensitive to some event (root background changes, window geometry 1034is sensitive to some event (root background changes, window geometry
965changes), then it will be reevaluated automatically as needed. 1035changes), then it will be reevaluated automatically as needed.
1036
1037=back
1038
1039=head1 OLD BACKGROUND IMAGE SETTINGS
1040
1041This extension also provides support for the old options/resources and
1042OSC sequences for setting a background image. These settings are
1043B<deprecated> and will be removed in future versions.
1044
1045=head2 OPTIONS AND RESOURCES
1046
1047=over 4
1048
1049=item B<-pixmap> I<file[;oplist]>
1050
1051=item B<backgroundPixmap:> I<file[;oplist]>
1052
1053Use the specified image file as the window's background and also
1054optionally specify a colon separated list of operations to modify it.
1055Note that you may need to quote the C<;> character when using the
1056command line option, as C<;> is usually a metacharacter in shells.
1057Supported operations are:
1058
1059=over 4
1060
1061=item B<WxH+X+Y>
1062
1063sets scale and position. B<"W" / "H"> specify the horizontal/vertical
1064scale (percent), and B<"X" / "Y"> locate the image centre (percent). A
1065scale of 0 disables scaling.
1066
1067=item B<op=tile>
1068
1069enables tiling
1070
1071=item B<op=keep-aspect>
1072
1073maintain the image aspect ratio when scaling
1074
1075=item B<op=root-align>
1076
1077use the position of the terminal window relative to the root window as
1078the image offset, simulating a root window background
1079
1080=back
1081
1082The default scale and position setting is C<100x100+50+50>.
1083Alternatively, a predefined set of templates can be used to achieve
1084the most common setups:
1085
1086=over 4
1087
1088=item B<style=tiled>
1089
1090the image is tiled with no scaling. Equivalent to 0x0+0+0:op=tile
1091
1092=item B<style=aspect-stretched>
1093
1094the image is scaled to fill the whole window maintaining the aspect
1095ratio and centered. Equivalent to 100x100+50+50:op=keep-aspect
1096
1097=item B<style=stretched>
1098
1099the image is scaled to fill the whole window. Equivalent to 100x100
1100
1101=item B<style=centered>
1102
1103the image is centered with no scaling. Equivalent to 0x0+50+50
1104
1105=item B<style=root-tiled>
1106
1107the image is tiled with no scaling and using 'root' positioning.
1108Equivalent to 0x0:op=tile:op=root-align
1109
1110=back
1111
1112If multiple templates are specified the last one wins. Note that a
1113template overrides all the scale, position and operations settings.
1114
1115If used in conjunction with pseudo-transparency, the specified image
1116will be blended over the transparent background using alpha-blending.
1117
1118=item B<-tr>|B<+tr>
1119
1120=item B<transparent:> I<boolean>
1121
1122Turn on/off pseudo-transparency by using the root pixmap as background.
1123
1124=item B<-tint> I<colour>
1125
1126=item B<tintColor:> I<colour>
1127
1128Tint the transparent background with the given colour. Note that a
1129black tint yields a completely black image while a white tint yields
1130the image unchanged.
1131
1132=item B<-sh> I<number>
1133
1134=item B<shading:> I<number>
1135
1136Darken (0 .. 99) or lighten (101 .. 200) the transparent background.
1137A value of 100 means no shading.
1138
1139=item B<-blr> I<HxV>
1140
1141=item B<blurRadius:> I<HxV>
1142
1143Apply gaussian blur with the specified radius to the transparent
1144background. If a single number is specified, the vertical and
1145horizontal radii are considered to be the same. Setting one of the
1146radii to 1 and the other to a large number creates interesting effects
1147on some backgrounds. The maximum radius value is 128. An horizontal or
1148vertical radius of 0 disables blurring.
1149
1150=back
1151
1152=head2 OSC sequences
1153
1154=over 4
1155
1156=item B<< C<ESC ] 705 ; Pt ST> >> Change transparent background tint colour to B<< C<Pt> >>.
1157
1158=item B<< C<ESC ] 20 ; Pt ST> >> Change/Query background image
1159parameters: the value of B<< C<Pt> >> can be one of the following
1160commands:
1161
1162=over 4
1163
1164=item B<< C<?> >>
1165
1166display scale and position in the title
1167
1168=item B<< C<;WxH+X+Y> >>
1169
1170change scale and/or position
1171
1172=item B<< C<FILE;WxH+X+Y> >>
1173
1174change background image
1175
1176=back
966 1177
967=cut 1178=cut
968 1179
969 sub keep(&) { 1180 sub keep(&) {
970 my $id = $_[0]+0; 1181 my $id = $_[0]+0;
1068 if ($again->{rootpmap}) { 1279 if ($again->{rootpmap}) {
1069 $state->{rootpmap} = $self->on (rootpmap_change => $cb); 1280 $state->{rootpmap} = $self->on (rootpmap_change => $cb);
1070 } else { 1281 } else {
1071 delete $state->{rootpmap}; 1282 delete $state->{rootpmap};
1072 } 1283 }
1284
1285 if ($again->{focus}) {
1286 $state->{focus} = $self->on (focus_in => $cb, focus_out => $cb);
1287 } else {
1288 delete $state->{focus};
1289 }
1073} 1290}
1074 1291
1075# evaluate the current bg expression 1292# evaluate the current bg expression
1076sub recalculate { 1293sub recalculate {
1077 my ($arg_self) = @_; 1294 my ($arg_self) = @_;
1085 return; 1302 return;
1086 } 1303 }
1087 1304
1088 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; 1305 $arg_self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL;
1089 1306
1307 unless ($arg_self->has_render) {
1308 warn "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n";
1309 return;
1310 }
1311
1090 # set environment to evaluate user expression 1312 # set environment to evaluate user expression
1091 1313
1092 local $self = $arg_self; 1314 local $self = $arg_self;
1093 local $HOME = $ENV{HOME}; 1315 local $HOME = $ENV{HOME};
1094 local $frame = $self->{root}; 1316 local $frame = $self->{root};
1095 1317
1096 ($x, $y, $w, $h) = $self->background_geometry ($self->{border}); 1318 ($x, $y, $w, $h) = $self->background_geometry ($self->{border});
1319 $focus = $self->focus;
1097 1320
1098 # evaluate user expression 1321 # evaluate user expression
1099 1322
1100 my @img = eval { $self->{expr}->() }; 1323 my @img = eval { $self->{expr}->() };
1101 die $@ if $@; 1324 die $@ if $@;
1119# } 1342# }
1120 1343
1121 # set background pixmap 1344 # set background pixmap
1122 1345
1123 $self->set_background ($img, $self->{border}); 1346 $self->set_background ($img, $self->{border});
1124 $self->scr_recolour (0); 1347 $self->scr_recolor (0);
1125 $self->want_refresh; 1348 $self->want_refresh;
1126} 1349}
1127 1350
1351sub old_bg_opts {
1352 my ($self, $arg) = @_;
1353
1354 $arg or return;
1355
1356 my @str = split /;/, $arg;
1357
1358 return unless $str[0] or $self->{bg_opts}->{path};
1359
1360 my $bg_opts = $self->{bg_opts};
1361
1362 if ($str[0]) {
1363 $bg_opts->{tile} = 0;
1364 $bg_opts->{keep_aspect} = 0;
1365 $bg_opts->{root_align} = 0;
1366 $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100;
1367 $bg_opts->{h_align} = $bg_opts->{v_align} = 50;
1368 $bg_opts->{path} = unpack "H*", $str[0];
1369 }
1370
1371 my @oplist = split /:/, $str[1];
1372
1373 for (@oplist) {
1374 if (/style=tiled/i) {
1375 $bg_opts->{tile} = 1;
1376 $bg_opts->{keep_aspect} = 0;
1377 $bg_opts->{root_align} = 0;
1378 $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0;
1379 $bg_opts->{h_align} = $bg_opts->{v_align} = 0;
1380 } elsif (/style=aspect-stretched/i) {
1381 $bg_opts->{tile} = 0;
1382 $bg_opts->{keep_aspect} = 1;
1383 $bg_opts->{root_align} = 0;
1384 $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100;
1385 $bg_opts->{h_align} = $bg_opts->{v_align} = 50;
1386 } elsif (/style=stretched/i) {
1387 $bg_opts->{tile} = 0;
1388 $bg_opts->{keep_aspect} = 0;
1389 $bg_opts->{root_align} = 0;
1390 $bg_opts->{h_scale} = $bg_opts->{v_scale} = 100;
1391 $bg_opts->{h_align} = $bg_opts->{v_align} = 50;
1392 } elsif (/style=centered/i) {
1393 $bg_opts->{tile} = 0;
1394 $bg_opts->{keep_aspect} = 0;
1395 $bg_opts->{root_align} = 0;
1396 $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0;
1397 $bg_opts->{h_align} = $bg_opts->{v_align} = 50;
1398 } elsif (/style=root-tiled/i) {
1399 $bg_opts->{tile} = 1;
1400 $bg_opts->{keep_aspect} = 0;
1401 $bg_opts->{root_align} = 1;
1402 $bg_opts->{h_scale} = $bg_opts->{v_scale} = 0;
1403 $bg_opts->{h_align} = $bg_opts->{v_align} = 0;
1404 } elsif (/op=tile/i) {
1405 $bg_opts->{tile} = 1;
1406 } elsif (/op=keep-aspect/i) {
1407 $bg_opts->{keep_aspect} = 1;
1408 } elsif (/op=root-align/i) {
1409 $bg_opts->{root_align} = 1;
1410 } elsif (/^ =? ([0-9]+)? (?:[xX] ([0-9]+))? ([+-][0-9]+)? ([+-][0-9]+)? $/x) {
1411 my ($w, $h, $x, $y) = ($1, $2, $3, $4);
1412
1413 if ($str[0]) {
1414 $w = $h unless defined $w;
1415 $h = $w unless defined $h;
1416 $y = $x unless defined $y;
1417 }
1418
1419 $bg_opts->{h_scale} = $w if defined $w;
1420 $bg_opts->{v_scale} = $h if defined $h;
1421 $bg_opts->{h_align} = $x if defined $x;
1422 $bg_opts->{v_align} = $y if defined $y;
1423 }
1424 }
1425}
1426
1427sub old_bg_expr {
1428 my ($self) = @_;
1429
1430 my $expr;
1431
1432 my $bg_opts = $self->{bg_opts};
1433
1434 if ($bg_opts->{root} =~ /^\s*(?:true|yes|on|1)\s*$/i) {
1435 $expr .= "tile (";
1436
1437 my $shade = $bg_opts->{shade};
1438
1439 if ($shade) {
1440 $shade = List::Util::min $shade, 200;
1441 $shade = List::Util::max $shade, -100;
1442 $shade = 200 - (100 + $shade) if $shade < 0;
1443
1444 $shade = $shade * 0.01 - 1;
1445 $expr .= "shade $shade, ";
1446 }
1447
1448 my $tint = $bg_opts->{tint};
1449
1450 if ($tint) {
1451 $expr .= "tint $tint, ";
1452 }
1453
1454 my $blur = $bg_opts->{blur};
1455
1456 if ($blur and $blur =~ /^ =? ([0-9]+)? (?:[xX] ([0-9]+))? $/x) {
1457 my $hr = defined $1 ? $1 : 1;
1458 my $vr = defined $2 ? $2 : $hr;
1459
1460 if ($hr != 0 and $vr != 0) {
1461 $expr .= "blur $hr, $vr, ";
1462 }
1463 }
1464
1465 $expr .= "rootalign root)";
1466 }
1467
1468 if ($bg_opts->{path}) {
1469 my $file_expr;
1470 my $h_scale = $bg_opts->{h_scale} * 0.01;
1471 my $v_scale = $bg_opts->{v_scale} * 0.01;
1472 my $h_align = $bg_opts->{h_align} * 0.01;
1473 my $v_align = $bg_opts->{v_align} * 0.01;
1474
1475 if (!$bg_opts->{tile}) {
1476 $file_expr .= "pad (";
1477 } else {
1478 $file_expr .= "tile (";
1479 }
1480
1481 if ($bg_opts->{root_align}) {
1482 $file_expr .= "rootalign ";
1483 } else {
1484 $file_expr .= "align $h_align, $v_align, ";
1485 }
1486
1487 if ($h_scale != 0 and $v_scale != 0) {
1488 my $op = $bg_opts->{keep_aspect} ? "fit" : "resize";
1489 $file_expr .= "$op TW * $h_scale, TH * $v_scale, ";
1490 }
1491
1492 $file_expr .= "keep { load pack \"H*\", \"$bg_opts->{path}\" })";
1493
1494 if ($expr) {
1495 $expr .= ", tint (\"[50]white\", $file_expr)";
1496 } else {
1497 $expr = $file_expr;
1498 }
1499 }
1500
1501 $expr
1502}
1503
1504sub on_osc_seq {
1505 my ($self, $op, $arg) = @_;
1506
1507 $self->{bg_opts} or return;
1508
1509 $op =~ /^(?:20|705)$/ or return;
1510
1511 if ($op eq "20") {
1512 if ($arg eq "?") {
1513 my $h_scale = $self->{bg_opts}->{h_scale};
1514 my $v_scale = $self->{bg_opts}->{v_scale};
1515 my $h_align = $self->{bg_opts}->{h_align};
1516 my $v_align = $self->{bg_opts}->{v_align};
1517 $self->cmd_parse ("\033]2;[${h_scale}x${v_scale}+${h_align}+${v_align}]\007");
1518 } else {
1519 $self->old_bg_opts ($arg);
1520 my $expr = $self->old_bg_expr;
1521 $self->set_expr (parse_expr $expr) if $expr;
1522 }
1523 } elsif ($op eq "705") {
1524 $self->{bg_opts}->{tint} = $arg;
1525 my $expr = $self->old_bg_expr;
1526 $self->set_expr (parse_expr $expr) if $expr;
1527 }
1528
1529 1
1530}
1531
1532sub find_resource {
1533 my ($self, $res, $opt) = @_;
1534
1535 my $v = $self->x_resource ($opt);
1536 $v = $self->x_resource ($res) unless defined $v;
1537
1538 $v
1539}
1540
1128sub on_start { 1541sub on_start {
1129 my ($self) = @_; 1542 my ($self) = @_;
1130 1543
1131 my $expr = $self->x_resource ("%.expr") 1544 my $expr = $self->x_resource ("%.expr");
1545
1546 if (!$expr) {
1547 $self->{bg_opts} = { h_scale => 100, v_scale => 100,
1548 h_align => 50, v_align => 50 };
1549
1550 $self->{bg_opts}->{shade} = $self->find_resource ("shading", "sh");
1551 $self->{bg_opts}->{tint} = $self->find_resource ("tintColor", "tint");
1552 $self->{bg_opts}->{blur} = $self->find_resource ("blurRadius", "blr");
1553 $self->{bg_opts}->{root} = $self->find_resource ("transparent", "tr");
1554
1555 $self->old_bg_opts ($self->find_resource ("backgroundPixmap", "pixmap"));
1556 $expr = $self->old_bg_expr;
1557 }
1558
1132 or return; 1559 $expr or return;
1133
1134 $self->has_render
1135 or die "background extension needs RENDER extension 0.10 or higher, ignoring background-expr.\n";
1136 1560
1137 $self->set_expr (parse_expr $expr); 1561 $self->set_expr (parse_expr $expr);
1138 $self->{border} = $self->x_resource_boolean ("%.border"); 1562 $self->{border} = $self->x_resource_boolean ("%.border");
1139 1563
1140 $MIN_INTERVAL = $self->x_resource ("%.interval"); 1564 $MIN_INTERVAL = $self->x_resource ("%.interval");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines