| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
root |
1.3 |
=head1 NAME |
| 4 |
|
|
|
| 5 |
|
|
example-refresh-hooks - example of how to use refresh hooks |
| 6 |
|
|
|
| 7 |
root |
1.4 |
=head1 DESCRIPTION |
| 8 |
root |
1.3 |
|
| 9 |
|
|
Displays a very simple digital clock in the upper right corner of the |
| 10 |
|
|
window. Illustrates overwriting the refresh callbacks to create your own |
| 11 |
|
|
overlays or changes. |
| 12 |
|
|
|
| 13 |
|
|
=cut |
| 14 |
root |
1.1 |
|
| 15 |
|
|
sub on_init { |
| 16 |
|
|
my ($self) = @_; |
| 17 |
|
|
|
| 18 |
|
|
# force a refresh every second |
| 19 |
|
|
$self->{digital_clock_refresh} = urxvt::timer |
| 20 |
|
|
->new |
| 21 |
root |
1.2 |
->start (1 + int urxvt::NOW) |
| 22 |
|
|
->interval (1) |
| 23 |
|
|
->cb (sub { $self->want_refresh }); |
| 24 |
root |
1.1 |
|
| 25 |
|
|
() |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
# before refreshing: replace upper right with the clock display |
| 29 |
|
|
sub on_refresh_begin { |
| 30 |
|
|
my ($self) = @_; |
| 31 |
|
|
|
| 32 |
|
|
my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0]; |
| 33 |
|
|
my $xpos = $self->ncol - length $time; |
| 34 |
|
|
|
| 35 |
|
|
$xpos >= 0 |
| 36 |
|
|
or return; |
| 37 |
|
|
|
| 38 |
|
|
$self->{digital_clock_rend} = $self->ROW_r (0, [(urxvt::DEFAULT_RSTYLE) x length $time], $xpos); |
| 39 |
|
|
$self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos); |
| 40 |
|
|
|
| 41 |
|
|
() |
| 42 |
|
|
} |
| 43 |
|
|
|
| 44 |
|
|
# after refreshing: restore previous screen contents |
| 45 |
|
|
sub on_refresh_end { |
| 46 |
|
|
my ($self) = @_; |
| 47 |
|
|
|
| 48 |
|
|
exists $self->{digital_clock_text} |
| 49 |
|
|
or return; |
| 50 |
|
|
|
| 51 |
|
|
$self->ROW_r (0, delete $self->{digital_clock_rend}); |
| 52 |
|
|
$self->ROW_t (0, delete $self->{digital_clock_text}); |
| 53 |
|
|
|
| 54 |
|
|
() |
| 55 |
|
|
} |
| 56 |
|
|
|
| 57 |
|
|
|