1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # this creates a simple digital clock by overwriting the refresh hooks |
3 | # this creates a simple digital clock |
4 | |
4 | |
5 | sub on_init { |
5 | sub on_init { |
6 | my ($self) = @_; |
6 | my ($self) = @_; |
7 | |
7 | |
8 | $self->{digital_clock_refresh} = urxvt::timer |
8 | $self->{overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); |
|
|
9 | $self->{timer} = urxvt::timer |
9 | ->new |
10 | ->new |
10 | ->start (urxvt::NOW) |
11 | ->start (int urxvt::NOW) # make sure we update "on" the second |
|
|
12 | ->interval (1) |
11 | ->cb (sub { |
13 | ->cb (sub { |
12 | $self->{timer}->start ($self->{timer}->at + 1); |
14 | $self->{overlay}->set (0, 0, |
13 | $self->want_refresh; |
15 | sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); |
14 | }); |
16 | }); |
15 | |
17 | |
16 | () |
18 | () |
17 | } |
19 | } |
18 | |
20 | |
19 | sub on_refresh_begin { |
|
|
20 | my ($self) = @_; |
|
|
21 | |
21 | |
22 | my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0]; |
|
|
23 | my $xpos = $self->ncol - length $time; |
|
|
24 | |
|
|
25 | $self->{digital_clock_rend} = $self->ROW_r (0, [(0x00020000 + urxvt::DEFAULT_RSTYLE) x length $time], $xpos); |
|
|
26 | $self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos); |
|
|
27 | |
|
|
28 | () |
|
|
29 | } |
|
|
30 | |
|
|
31 | sub on_refresh_end { |
|
|
32 | my ($self) = @_; |
|
|
33 | |
|
|
34 | $self->ROW_r (0, $self->{digital_clock_rend}); |
|
|
35 | $self->ROW_t (0, $self->{digital_clock_text}); |
|
|
36 | |
|
|
37 | () |
|
|
38 | } |
|
|
39 | |
|
|
40 | |
|
|