ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/example-refresh-hooks
Revision: 1.3
Committed: Sun Jun 10 17:31:53 2012 UTC (11 years, 11 months ago) by root
Branch: MAIN
Changes since 1.2: +11 -1 lines
Log Message:
move perl docs to extensions

File Contents

# User Rev Content
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     =head1 DESCRPTION
8    
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