--- rxvt-unicode/src/perl/digital-clock 2006/01/03 01:15:44 1.2 +++ rxvt-unicode/src/perl/digital-clock 2012/06/10 17:39:54 1.11 @@ -1,38 +1,27 @@ #! perl -# this creates a simple digital clock by overwriting the refresh hooks +=head1 NAME -sub on_init { - my ($self) = @_; - - $self->{digital_clock_refresh} = urxvt::timer - ->new - ->start (urxvt::NOW) - ->cb (sub { - $self->{digital_clock_refresh}->start ($self->{digital_clock_refresh}->at + 1); - $self->want_refresh; - }); + digital-clock - display a digital clock overlay - () -} +=head1 DESCRIPTION -sub on_refresh_begin { - my ($self) = @_; +Displays a digital clock using the built-in overlay. - my $time = sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2, 1, 0]; - my $xpos = $self->ncol - length $time; +=cut - $self->{digital_clock_rend} = $self->ROW_r (0, [(0x00020000 + urxvt::DEFAULT_RSTYLE) x length $time], $xpos); - $self->{digital_clock_text} = $self->ROW_t (0, $time, $xpos); - - () -} - -sub on_refresh_end { +sub on_start { my ($self) = @_; - $self->ROW_r (0, $self->{digital_clock_rend}); - $self->ROW_t (0, $self->{digital_clock_text}); + $self->{overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); + $self->{timer} = urxvt::timer + ->new + ->start (1 + int urxvt::NOW) # make sure we update "on" the second + ->interval (1) + ->cb (sub { + $self->{overlay}->set (0, 0, + sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); + }); () }