--- rxvt-unicode/src/perl/digital-clock 2006/01/03 01:29:55 1.4 +++ rxvt-unicode/src/perl/digital-clock 2006/01/18 11:05:09 1.8 @@ -1,49 +1,21 @@ #! perl -# this creates a simple digital clock by overwriting the refresh hooks +# this creates a simple digital clock sub on_init { my ($self) = @_; - # force a refresh every second - $self->{digital_clock_refresh} = urxvt::timer + $self->{overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); + $self->{timer} = urxvt::timer ->new - ->start (urxvt::NOW) + ->start (1 + int urxvt::NOW) # make sure we update "on" the second + ->interval (1) ->cb (sub { - $self->{digital_clock_refresh}->start ($self->{digital_clock_refresh}->at + 1); - $self->want_refresh; + $self->{overlay}->set (0, 0, + sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); }); () } - -# before refreshing: replace upper right with the clock display -sub on_refresh_begin { - my ($self) = @_; - - my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0]; - my $xpos = $self->ncol - length $time; - - $xpos >= 0 - or return; - - $self->{digital_clock_rend} = $self->ROW_r (0, [(urxvt::DEFAULT_RSTYLE) x length $time], $xpos); - $self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos); - - () -} - -# after refreshing: restore previous screen contents -sub on_refresh_end { - my ($self) = @_; - - exists $self->{digital_clock_text} - or return; - - $self->ROW_r (0, delete $self->{digital_clock_rend}); - $self->ROW_t (0, delete $self->{digital_clock_text}); - - () -}