1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
4 | #:META:X_RESOURCE:%.border.:boolean:respect the terminal border |
4 | #:META:X_RESOURCE:%.border:boolean:respect the terminal border |
|
|
5 | #:META:X_RESOURCE:%.interval:seconds:minimum time between updates |
5 | |
6 | |
6 | #TODO: once, rootalign |
7 | #TODO: once, rootalign |
7 | |
8 | |
8 | =head1 NAME |
9 | =head1 NAME |
9 | |
10 | |
… | |
… | |
11 | |
12 | |
12 | =head1 SYNOPSIS |
13 | =head1 SYNOPSIS |
13 | |
14 | |
14 | urxvt --background-expr 'background expression' |
15 | urxvt --background-expr 'background expression' |
15 | --background-border |
16 | --background-border |
|
|
17 | --background-interval seconds |
16 | |
18 | |
17 | =head1 DESCRIPTION |
19 | =head1 DESCRIPTION |
18 | |
20 | |
19 | This extension manages the terminal background by creating a picture that |
21 | This extension manages the terminal background by creating a picture that |
20 | is behind the text, replacing the normal background colour. |
22 | is behind the text, replacing the normal background colour. |
… | |
… | |
189 | overwriting borders and any other areas, such as the scrollbar. |
191 | overwriting borders and any other areas, such as the scrollbar. |
190 | |
192 | |
191 | Specifying this flag changes the behaviour, so that the image only |
193 | Specifying this flag changes the behaviour, so that the image only |
192 | replaces the background of the character area. |
194 | replaces the background of the character area. |
193 | |
195 | |
|
|
196 | =item --background-interval seconds |
|
|
197 | |
|
|
198 | Since some operations in the underlying XRender extension can effetively |
|
|
199 | freeze your X-server for prolonged time, this extension enforces a minimum |
|
|
200 | time between updates, which is normally about 0.1 seconds. |
|
|
201 | |
|
|
202 | If you want to do updates more often, you can decrease this safety |
|
|
203 | interval with this switch. |
|
|
204 | |
194 | =back |
205 | =back |
195 | |
206 | |
196 | =cut |
207 | =cut |
197 | |
208 | |
198 | our $HOME; |
209 | our $HOME; |
199 | our ($self, $old, $new); |
210 | our ($self, $old, $new); |
200 | our ($x, $y, $w, $h); |
211 | our ($x, $y, $w, $h); |
201 | |
212 | |
202 | # enforce at least this interval between updates |
213 | # enforce at least this interval between updates |
203 | our $MIN_INTERVAL = 1/100; |
214 | our $MIN_INTERVAL = 6/59.951; |
204 | |
215 | |
205 | { |
216 | { |
206 | package urxvt::bgdsl; # background language |
217 | package urxvt::bgdsl; # background language |
207 | |
218 | |
208 | use List::Util qw(min max sum shuffle); |
219 | use List::Util qw(min max sum shuffle); |
… | |
… | |
263 | my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); |
274 | my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); |
264 | $img->fill ($colour); |
275 | $img->fill ($colour); |
265 | $img |
276 | $img |
266 | } |
277 | } |
267 | |
278 | |
|
|
279 | =item clone $img |
|
|
280 | |
|
|
281 | Returns an exact copy of the image. This is useful if you want to have |
|
|
282 | multiple copies of the same image to apply different effects to. |
|
|
283 | |
|
|
284 | =cut |
|
|
285 | |
|
|
286 | sub clone($) { |
|
|
287 | $_[0]->clone |
|
|
288 | } |
|
|
289 | |
268 | =back |
290 | =back |
269 | |
291 | |
|
|
292 | =head2 TILING MODES |
|
|
293 | |
|
|
294 | The following operators modify the tiling mode of an image, that is, the |
|
|
295 | way that pixels outside the image area are painted when the image is used. |
|
|
296 | |
|
|
297 | =over 4 |
|
|
298 | |
|
|
299 | =item tile $img |
|
|
300 | |
|
|
301 | Tiles the whole plane with the image and returns this new image - or in |
|
|
302 | other words, it returns a copy of the image in plane tiling mode. |
|
|
303 | |
|
|
304 | Example: load an image and tile it over the background, without |
|
|
305 | resizing. The C<tile> call is superfluous because C<load> already defaults |
|
|
306 | to tiling mode. |
|
|
307 | |
|
|
308 | tile load "mybg.png" |
|
|
309 | |
|
|
310 | =item mirror $img |
|
|
311 | |
|
|
312 | Similar to tile, but reflects the image each time it uses a new copy, so |
|
|
313 | that top edges always touch top edges, right edges always touch right |
|
|
314 | edges and so on (with normal tiling, left edges always touch right edges |
|
|
315 | and top always touch bottom edges). |
|
|
316 | |
|
|
317 | Example: load an image and mirror it over the background, avoiding sharp |
|
|
318 | edges at the image borders at the expense of mirroring the image itself |
|
|
319 | |
|
|
320 | mirror load "mybg.png" |
|
|
321 | |
|
|
322 | =item pad $img |
|
|
323 | |
|
|
324 | Takes an image and modifies it so that all pixels outside the image area |
|
|
325 | become transparent. This mode is most useful when you want to place an |
|
|
326 | image over another image or the background colour while leaving all |
|
|
327 | background pixels outside the image unchanged. |
|
|
328 | |
|
|
329 | Example: load an image and display it in the upper left corner. The rest |
|
|
330 | of the space is left "empty" (transparent or wahtever your compisotr does |
|
|
331 | in alpha mode, else background colour). |
|
|
332 | |
|
|
333 | pad load "mybg.png" |
|
|
334 | |
|
|
335 | =item extend $img |
|
|
336 | |
|
|
337 | Extends the image over the whole plane, using the closest pixel in the |
|
|
338 | area outside the image. This mode is mostly useful when you more complex |
|
|
339 | filtering operations and want the pixels outside the image to have the |
|
|
340 | same values as the pixels near the edge. |
|
|
341 | |
|
|
342 | Example: just for curiosity, how does this pixel extension stuff work? |
|
|
343 | |
|
|
344 | extend move 50, 50, load "mybg.png" |
|
|
345 | |
|
|
346 | =cut |
|
|
347 | |
|
|
348 | sub pad($) { |
|
|
349 | my $img = $_[0]->clone; |
|
|
350 | $img->repeat_mode (urxvt::RepeatNone); |
|
|
351 | $img |
|
|
352 | } |
|
|
353 | |
|
|
354 | sub tile($) { |
|
|
355 | my $img = $_[0]->clone; |
|
|
356 | $img->repeat_mode (urxvt::RepeatNormal); |
|
|
357 | $img |
|
|
358 | } |
|
|
359 | |
|
|
360 | sub mirror($) { |
|
|
361 | my $img = $_[0]->clone; |
|
|
362 | $img->repeat_mode (urxvt::RepeatReflect); |
|
|
363 | $img |
|
|
364 | } |
|
|
365 | |
|
|
366 | sub extend($) { |
|
|
367 | my $img = $_[0]->clone; |
|
|
368 | $img->repeat_mode (urxvt::RepeatPad); |
|
|
369 | $img |
|
|
370 | } |
|
|
371 | |
|
|
372 | =back |
|
|
373 | |
270 | =head2 VARIABLES |
374 | =head2 VARIABLE VALUES |
271 | |
375 | |
272 | The following functions provide variable data such as the terminal window |
376 | The following functions provide variable data such as the terminal window |
273 | dimensions. They are not (Perl-) variables, they jsut return stuff that |
377 | dimensions. They are not (Perl-) variables, they just return stuff that |
274 | varies. Most of them make your expression sensitive to some events, for |
378 | varies. Most of them make your expression sensitive to some events, for |
275 | example using C<TW> (terminal width) means your expression is evaluated |
379 | example using C<TW> (terminal width) means your expression is evaluated |
276 | again when the terminal is resized. |
380 | again when the terminal is resized. |
277 | |
381 | |
278 | =over 4 |
382 | =over 4 |
… | |
… | |
352 | $self->{counter} + 0 |
456 | $self->{counter} + 0 |
353 | } |
457 | } |
354 | |
458 | |
355 | =back |
459 | =back |
356 | |
460 | |
357 | =head2 TILING MODES |
461 | =head2 SHAPE CHANGING OPERATORS |
358 | |
462 | |
359 | The following operators modify the tiling mode of an image, that is, the |
463 | The following operators modify the shape, size or position of the image. |
360 | way that pixels outside the image area are painted when the image is used. |
|
|
361 | |
464 | |
362 | =over 4 |
465 | =over 4 |
363 | |
|
|
364 | =item tile $img |
|
|
365 | |
|
|
366 | Tiles the whole plane with the image and returns this new image - or in |
|
|
367 | other words, it returns a copy of the image in plane tiling mode. |
|
|
368 | |
|
|
369 | Example: load an image and tile it over the background, without |
|
|
370 | resizing. The C<tile> call is superfluous because C<load> already defaults |
|
|
371 | to tiling mode. |
|
|
372 | |
|
|
373 | tile load "mybg.png" |
|
|
374 | |
|
|
375 | =item mirror $img |
|
|
376 | |
|
|
377 | Similar to tile, but reflects the image each time it uses a new copy, so |
|
|
378 | that top edges always touch top edges, right edges always touch right |
|
|
379 | edges and so on (with normal tiling, left edges always touch right edges |
|
|
380 | and top always touch bottom edges). |
|
|
381 | |
|
|
382 | Example: load an image and mirror it over the background, avoiding sharp |
|
|
383 | edges at the image borders at the expense of mirroring the image itself |
|
|
384 | |
|
|
385 | mirror load "mybg.png" |
|
|
386 | |
|
|
387 | =item pad $img |
|
|
388 | |
|
|
389 | Takes an image and modifies it so that all pixels outside the image area |
|
|
390 | become transparent. This mode is most useful when you want to place an |
|
|
391 | image over another image or the background colour while leaving all |
|
|
392 | background pixels outside the image unchanged. |
|
|
393 | |
|
|
394 | Example: load an image and display it in the upper left corner. The rest |
|
|
395 | of the space is left "empty" (transparent or wahtever your compisotr does |
|
|
396 | in alpha mode, else background colour). |
|
|
397 | |
|
|
398 | pad load "mybg.png" |
|
|
399 | |
|
|
400 | =item extend $img |
|
|
401 | |
|
|
402 | Extends the image over the whole plane, using the closest pixel in the |
|
|
403 | area outside the image. This mode is mostly useful when you more complex |
|
|
404 | filtering operations and want the pixels outside the image to have the |
|
|
405 | same values as the pixels near the edge. |
|
|
406 | |
|
|
407 | Example: just for curiosity, how does this pixel extension stuff work? |
|
|
408 | |
|
|
409 | extend move 50, 50, load "mybg.png" |
|
|
410 | |
|
|
411 | =cut |
|
|
412 | |
|
|
413 | sub pad($) { |
|
|
414 | my $img = $_[0]->clone; |
|
|
415 | $img->repeat_mode (urxvt::RepeatNone); |
|
|
416 | $img |
|
|
417 | } |
|
|
418 | |
|
|
419 | sub tile($) { |
|
|
420 | my $img = $_[0]->clone; |
|
|
421 | $img->repeat_mode (urxvt::RepeatNormal); |
|
|
422 | $img |
|
|
423 | } |
|
|
424 | |
|
|
425 | sub mirror($) { |
|
|
426 | my $img = $_[0]->clone; |
|
|
427 | $img->repeat_mode (urxvt::RepeatReflect); |
|
|
428 | $img |
|
|
429 | } |
|
|
430 | |
|
|
431 | sub extend($) { |
|
|
432 | my $img = $_[0]->clone; |
|
|
433 | $img->repeat_mode (urxvt::RepeatPad); |
|
|
434 | $img |
|
|
435 | } |
|
|
436 | |
|
|
437 | =back |
|
|
438 | |
|
|
439 | =head2 PIXEL OPERATORS |
|
|
440 | |
|
|
441 | The following operators modify the image pixels in various ways. |
|
|
442 | |
|
|
443 | =over 4 |
|
|
444 | |
|
|
445 | =item clone $img |
|
|
446 | |
|
|
447 | Returns an exact copy of the image. |
|
|
448 | |
|
|
449 | =cut |
|
|
450 | |
|
|
451 | sub clone($) { |
|
|
452 | $_[0]->clone |
|
|
453 | } |
|
|
454 | |
466 | |
455 | =item clip $img |
467 | =item clip $img |
456 | |
468 | |
457 | =item clip $width, $height, $img |
469 | =item clip $width, $height, $img |
458 | |
470 | |
… | |
… | |
552 | |
564 | |
553 | Example: move the image right by 20 pixels and down by 30. |
565 | Example: move the image right by 20 pixels and down by 30. |
554 | |
566 | |
555 | move 20, 30, ... |
567 | move 20, 30, ... |
556 | |
568 | |
|
|
569 | =item align $xalign, $yalign, $img |
|
|
570 | |
|
|
571 | Aligns the image according to a factor - C<0> means the image is moved to |
|
|
572 | the left or top edge (for C<$xalign> or C<$yalign>), C<0.5> means it is |
|
|
573 | exactly centered and C<1> means it touches the right or bottom edge. |
|
|
574 | |
|
|
575 | Example: remove any visible border around an image, center it vertically but move |
|
|
576 | it to the right hand side. |
|
|
577 | |
|
|
578 | align 1, 0.5, pad $img |
|
|
579 | |
|
|
580 | =item center $img |
|
|
581 | |
|
|
582 | =item center $width, $height, $img |
|
|
583 | |
|
|
584 | Centers the image, i.e. the center of the image is moved to the center of |
|
|
585 | the terminal window (or the box specified by C<$width> and C<$height> if |
|
|
586 | given). |
|
|
587 | |
|
|
588 | Example: load an image and center it. |
|
|
589 | |
|
|
590 | center pad load "mybg.png" |
|
|
591 | |
557 | =item rootalign $img |
592 | =item rootalign $img |
558 | |
593 | |
559 | Moves the image so that it appears glued to the screen as opposed to the |
594 | Moves the image so that it appears glued to the screen as opposed to the |
560 | window. This gives the illusion of a larger area behind the window. It is |
595 | window. This gives the illusion of a larger area behind the window. It is |
561 | exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the |
596 | exactly equivalent to C<move -TX, -TY>, that is, it moves the image to the |
… | |
… | |
566 | rootalign mirror load "mybg.png" |
601 | rootalign mirror load "mybg.png" |
567 | |
602 | |
568 | Example: take the screen background and align it, giving the illusion of |
603 | Example: take the screen background and align it, giving the illusion of |
569 | transparency as long as the window isn't in front of other windows. |
604 | transparency as long as the window isn't in front of other windows. |
570 | |
605 | |
571 | rootalign root |
606 | rootalign root |
572 | |
607 | |
573 | =cut |
608 | =cut |
574 | |
609 | |
575 | sub move($$;$) { |
610 | sub move($$;$) { |
576 | my $img = pop->clone; |
611 | my $img = pop->clone; |
577 | $img->move ($_[0], $_[1]); |
612 | $img->move ($_[0], $_[1]); |
578 | $img |
613 | $img |
579 | } |
614 | } |
580 | |
615 | |
|
|
616 | sub align($;$$) { |
|
|
617 | my $img = pop; |
|
|
618 | |
|
|
619 | move $_[0] * (TW - $img->w), |
|
|
620 | $_[1] * (TH - $img->h), |
|
|
621 | $img |
|
|
622 | } |
|
|
623 | |
|
|
624 | sub center($;$$) { |
|
|
625 | my $img = pop; |
|
|
626 | my $w = $_[0] || TW; |
|
|
627 | my $h = $_[1] || TH; |
|
|
628 | |
|
|
629 | move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img |
|
|
630 | } |
|
|
631 | |
581 | sub rootalign($) { |
632 | sub rootalign($) { |
582 | move -TX, -TY, $_[0] |
633 | move -TX, -TY, $_[0] |
583 | } |
634 | } |
584 | |
635 | |
|
|
636 | =back |
|
|
637 | |
|
|
638 | =head2 COLOUR MODIFICATIONS |
|
|
639 | |
|
|
640 | The following operators change the pixels of the image. |
|
|
641 | |
|
|
642 | =over 4 |
|
|
643 | |
585 | =item contrast $factor, $img |
644 | =item contrast $factor, $img |
586 | |
645 | |
587 | =item contrast $r, $g, $b, $img |
646 | =item contrast $r, $g, $b, $img |
588 | |
647 | |
589 | =item contrast $r, $g, $b, $a, $img |
648 | =item contrast $r, $g, $b, $a, $img |
590 | |
649 | |
591 | Adjusts the I<contrast> of an image. |
650 | Adjusts the I<contrast> of an image. |
592 | |
651 | |
593 | #TODO# |
652 | The first form applies a single C<$factor> to red, green and blue, the |
|
|
653 | second form applies separate factors to each colour channel, and the last |
|
|
654 | form includes the alpha channel. |
594 | |
655 | |
|
|
656 | Values from 0 to 1 lower the contrast, values higher than 1 increase the |
|
|
657 | contrast. |
|
|
658 | |
|
|
659 | Due to limitations in the underlying XRender extension, lowering contrast |
|
|
660 | also reduces brightness, while increasing contrast currently also |
|
|
661 | increases brightness. |
|
|
662 | |
595 | =item brightness $factor, $img |
663 | =item brightness $bias, $img |
596 | |
664 | |
597 | =item brightness $r, $g, $b, $img |
665 | =item brightness $r, $g, $b, $img |
598 | |
666 | |
599 | =item brightness $r, $g, $b, $a, $img |
667 | =item brightness $r, $g, $b, $a, $img |
600 | |
668 | |
601 | Adjusts the brightness of an image. |
669 | Adjusts the brightness of an image. |
|
|
670 | |
|
|
671 | The first form applies a single C<$bias> to red, green and blue, the |
|
|
672 | second form applies separate biases to each colour channel, and the last |
|
|
673 | form includes the alpha channel. |
|
|
674 | |
|
|
675 | Values less than 0 reduce brightness, while values larger than 0 increase |
|
|
676 | it. Useful range is from -1 to 1 - the former results in a black, the |
|
|
677 | latter in a white picture. |
|
|
678 | |
|
|
679 | Due to idiosynchrasies in the underlying XRender extension, biases less |
|
|
680 | than zero can be I<very> slow. |
602 | |
681 | |
603 | =cut |
682 | =cut |
604 | |
683 | |
605 | sub contrast($$;$$;$) { |
684 | sub contrast($$;$$;$) { |
606 | my $img = pop; |
685 | my $img = pop; |
… | |
… | |
783 | or return; |
862 | or return; |
784 | |
863 | |
785 | $self->set_expr (parse_expr $expr); |
864 | $self->set_expr (parse_expr $expr); |
786 | $self->{border} = $self->x_resource_boolean ("background.border"); |
865 | $self->{border} = $self->x_resource_boolean ("background.border"); |
787 | |
866 | |
|
|
867 | $MIN_INTERVAL = $self->x_resource ("background.interval"); |
|
|
868 | |
788 | () |
869 | () |
789 | } |
870 | } |
790 | |
871 | |