From: root Date: Tue, 3 Jan 2006 04:18:47 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=144bf169061f76b22eb8bc1a6021a685c2647bac;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/Changes b/Changes index 77803385..c8c972f8 100644 --- a/Changes +++ b/Changes @@ -14,7 +14,7 @@ WISH: just for fun, do shade and tint with XRender. perl*-resources and keysym resources. - fix directory permissions on install. - improved sched_yield support. - - meta8 support was forcefully enabled in most configurations, + - meta8 support was forcefully enabled in most configurations. restored configurability of this (useless) feature (reported by Mikachu) diff --git a/MANIFEST b/MANIFEST index dccdba2b..a50c5250 100644 --- a/MANIFEST +++ b/MANIFEST @@ -125,7 +125,7 @@ src/typemap src/rxvtperl.h src/rxvtperl.C -src/perl/simple-overlay-clock +src/perl/example-refresh-hooks src/perl/digital-clock src/perl/selection diff --git a/doc/rxvtperl.3.html b/doc/rxvtperl.3.html index ee88d74b..e6077677 100644 --- a/doc/rxvtperl.3.html +++ b/doc/rxvtperl.3.html @@ -21,8 +21,8 @@
  • General API Considerations
  • Hooks
  • Functions in the urxvt Package
  • -
  • The urxvt::term Class
  • RENDITION
  • +
  • The urxvt::term Class
  • The urxvt::timer Class
  • The urxvt::iow Class
  • @@ -96,15 +96,15 @@ Rot-13 the selection when activated. Used via keyboard trigger:
    digital-clock
    -Displays a very simple digital clock in the upper right corner of the -window. Illustrates overwriting the refresh callbacks to create your own -overlays or changes. +Displays a digital clock using the built-in overlay.

    -
    simple-overlay-clock
    +
    example-refresh-hooks
    -Displays a digital clock using the built-in overlay (colorful, useless). +Displays a very simple digital clock in the upper right corner of the +window. Illustrates overwriting the refresh callbacks to create your own +overlays or changes.

    @@ -270,6 +270,68 @@ Returns the ``current time'' (as per the event loop).

    +

    RENDITION

    +

    Rendition bitsets contain information about colour, font, font styles and +similar information for each screen cell.

    +

    The following ``macros'' deal with changes in rendition sets. You should +never just create a bitset, you should always modify an existing one, +as they contain important information required for correct operation of +rxvt-unicode.

    +
    +
    $rend = urxvt::DEFAULT_RSTYLE
    +
    +
    +Returns the default rendition, as used when the terminal is starting up or +being reset. Useful as a base to start when creating renditions. +
    +

    +
    $rend = urxvt::OVERLAY_RSTYLE
    +
    +
    +Return the rendition mask used for overlays by default. +
    +

    +
    $rendbit = urxvt::RS_Bold, RS_Italic, RS_Blink, RS_RVid, RS_Uline
    +
    +
    +Return the bit that enabled bold, italic, blink, reverse-video and +underline, respectively. To enable such a style, just logically OR it into +the bitset. +
    +

    +
    $foreground = urxvt::GET_BASEFG $rend
    +
    +
    $background = urxvt::GET_BASEBG $rend
    +
    +
    +Return the foreground/background colour index, respectively. +
    +

    +
    $rend = urxvt::SET_FGCOLOR ($rend, $new_colour)
    +
    +
    $rend = urxvt::SET_BGCOLOR ($rend, $new_colour)
    +
    +
    +Replace the foreground/background colour in the rendition mask with the +specified one. +
    +

    +
    $value = urxvt::GET_CUSTOM ($rend)
    +
    +
    +Return the ``custom'' value: Every rendition has 5 bits for use by +extensions. They can be set and changed as you like and are initially +zero. +
    +

    +
    $rend = urxvt::SET_CUSTOM ($rend, $new_value)
    +
    +
    +Change the custom value. +
    +

    +

    +

    The urxvt::term Class

    $value = $term->resource ($name[, $newval])
    @@ -337,39 +399,65 @@ by the next method).
    Return the current selection text and optionally replace it by $newtext.
    -

    -
    $term->scr_overlay ($x, $y, $text)
    -
    -Create a simple multi-line overlay box. See the next method for details. +

    #=item $term->overlay ($x, $y, $text) +# +#Create a simple multi-line overlay box. See the next method for details. +# +#=cut

    +
    +
    +

    sub urxvt::term::scr_overlay { +die; + my ($self, $x, $y, $text) = @_;

    +
    +
    +
    +   my @lines = split /\n/, $text;
    +
    +
    +
    +   my $w = 0;
    +   for (map $self->strwidth ($_), @lines) {
    +      $w = $_ if $w < $_;
    +   }
    +
    +
    +
    +   $self->scr_overlay_new ($x, $y, $w, scalar @lines);
    +   $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines;
    +}

    -
    $term->scr_overlay_new ($x, $y, $width, $height)
    +
    $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]])
    Create a new (empty) overlay at the given position with the given -width/height. A border will be put around the box. If either $x or -$y is negative, then this is counted from the right/bottom side, -respectively. +width/height. $rstyle defines the initial rendition style +(default: OVERLAY_RSTYLE).
    -

    -
    $term->scr_overlay_off
    -
    -Switch the overlay off again. +

    If $border is 2 (default), then a decorative border will be put +around the box.

    +
    +
    +

    If either $x or $y is negative, then this is counted from the +right/bottom side, respectively.

    +
    +
    +

    This method returns an urxvt::overlay object. The overlay will be visible +as long as the perl object is referenced.

    -

    -
    $term->scr_overlay_set_char ($x, $y, $char, $rend = OVERLAY_RSTYLE)
    -
    -Put a single character (specified numerically) at the given overlay -position. +

    Currently, the only method on the urxvt::overlay object is set:

    -
    $term->scr_overlay_set ($x, $y, $text)
    +
    $overlay->set ($x, $y, $text, $rend)
    -Write a string at the given position into the overlay. +Similar to $term->ROW_t and $term->ROW_r in that it puts +text in rxvt-unicode's special encoding and an array of rendition values +at a specific position inside the overlay.

    $cellwidth = $term->strwidth $string
    @@ -444,7 +532,7 @@ line -$term->nsaved.

    If $new_text is specified, it will replace characters in the current line, starting at column $start_col (default 0), which is useful -to replace only parts of a line. The font iindex in the rendition will +to replace only parts of a line. The font index in the rendition will automatically be updated.

    @@ -475,7 +563,7 @@ styles and similar information. See also $term->R

    When setting rendition, the font mask will be ignored.

    -

    See the section on RENDITION, below.

    +

    See the section on RENDITION, above.

    $length = $term->ROW_l ($row_number[, $new_length])
    @@ -503,43 +591,24 @@ Converts rxvt-unicodes text reprsentation into a perl string. See

    -

    RENDITION

    -

    Rendition bitsets contain information about colour, font, font styles and -similar information for each screen cell.

    -

    The following ``macros'' deal with changes in rendition sets. You should -never just create a bitset, you should always modify an existing one, -as they contain important information required for correct operation of -rxvt-unicode.

    -
    -
    $rend = urxvt::DEFAULT_RSTYLE
    -
    -
    -Returns the default rendition, as used when the terminal is starting up or -being reset. Useful as a base -
    -

    -

    -

    The urxvt::timer Class

    This class implements timer watchers/events. Time is represented as a fractional number of seconds since the epoch. Example:

    -   # create a digital clock display in upper right corner
    +   $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0);
        $term->{timer} = urxvt::timer
                         ->new
    -                    ->start (urxvt::NOW)
    +                    ->interval (1)
                         ->cb (sub {
    -                       my ($timer) = @_;
    -                       my $time = $timer->at;
    -                       $timer->start ($time + 1);
    -                       $self->scr_overlay (-1, 0, 
    -                          POSIX::strftime "%H:%M:%S", localtime $time);
    +                       $term->{overlay}->set (0, 0,
    +                          sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]);
                         });
    $timer = new urxvt::timer
    -Create a new timer object in stopped state. +Create a new timer object in started state. It is scheduled to fire +immediately.

    $timer = $timer->cb (sub { my ($timer) = @_; ... })
    @@ -554,12 +623,20 @@ Set the callback to be called when the timer triggers. Return the time this watcher will fire next.

    -
    $timer = $timer->set ($tstamp)
    +
    $timer = $timer->set ($tstamp)
    Set the time the event is generated to $tstamp.

    +
    $timer = $timer->interval ($interval)
    +
    +
    +Normally (and when $interval is 0), the timer will automatically +stop after it has fired once. If $interval is non-zero, then the timer +is automatically rescheduled at the given intervals. +
    +

    $timer = $timer->start
    diff --git a/doc/rxvtperl.3.man.in b/doc/rxvtperl.3.man.in index 9be8ca87..008aef02 100644 --- a/doc/rxvtperl.3.man.in +++ b/doc/rxvtperl.3.man.in @@ -188,12 +188,12 @@ Rot\-13 the selection when activated. Used via keyboard trigger: .RE .IP "digital-clock" 4 .IX Item "digital-clock" +Displays a digital clock using the built-in overlay. +.IP "example-refresh-hooks" 4 +.IX Item "example-refresh-hooks" Displays a very simple digital clock in the upper right corner of the window. Illustrates overwriting the refresh callbacks to create your own overlays or changes. -.IP "simple-overlay-clock" 4 -.IX Item "simple-overlay-clock" -Displays a digital clock using the built-in overlay (colorful, useless). .Sh "General \s-1API\s0 Considerations" .IX Subsection "General API Considerations" All objects (such as terminals, time watchers etc.) are typical @@ -317,6 +317,55 @@ correct place, e.g. on stderr of the connecting urxvtc client. .IP "$time = urxvt::NOW" 4 .IX Item "$time = urxvt::NOW" Returns the \*(L"current time\*(R" (as per the event loop). +.Sh "\s-1RENDITION\s0" +.IX Subsection "RENDITION" +Rendition bitsets contain information about colour, font, font styles and +similar information for each screen cell. +.PP +The following \*(L"macros\*(R" deal with changes in rendition sets. You should +never just create a bitset, you should always modify an existing one, +as they contain important information required for correct operation of +rxvt\-unicode. +.IP "$rend = urxvt::DEFAULT_RSTYLE" 4 +.IX Item "$rend = urxvt::DEFAULT_RSTYLE" +Returns the default rendition, as used when the terminal is starting up or +being reset. Useful as a base to start when creating renditions. +.IP "$rend = urxvt::OVERLAY_RSTYLE" 4 +.IX Item "$rend = urxvt::OVERLAY_RSTYLE" +Return the rendition mask used for overlays by default. +.IP "$rendbit = urxvt::RS_Bold, RS_Italic, RS_Blink, RS_RVid, RS_Uline" 4 +.IX Item "$rendbit = urxvt::RS_Bold, RS_Italic, RS_Blink, RS_RVid, RS_Uline" +Return the bit that enabled bold, italic, blink, reverse-video and +underline, respectively. To enable such a style, just logically \s-1OR\s0 it into +the bitset. +.ie n .IP "$foreground = urxvt::GET_BASEFG $rend" 4 +.el .IP "$foreground = urxvt::GET_BASEFG \f(CW$rend\fR" 4 +.IX Item "$foreground = urxvt::GET_BASEFG $rend" +.PD 0 +.ie n .IP "$background = urxvt::GET_BASEBG $rend" 4 +.el .IP "$background = urxvt::GET_BASEBG \f(CW$rend\fR" 4 +.IX Item "$background = urxvt::GET_BASEBG $rend" +.PD +Return the foreground/background colour index, respectively. +.ie n .IP "$rend = urxvt::SET_FGCOLOR ($rend, $new_colour)" 4 +.el .IP "$rend = urxvt::SET_FGCOLOR ($rend, \f(CW$new_colour\fR)" 4 +.IX Item "$rend = urxvt::SET_FGCOLOR ($rend, $new_colour)" +.PD 0 +.ie n .IP "$rend = urxvt::SET_BGCOLOR ($rend, $new_colour)" 4 +.el .IP "$rend = urxvt::SET_BGCOLOR ($rend, \f(CW$new_colour\fR)" 4 +.IX Item "$rend = urxvt::SET_BGCOLOR ($rend, $new_colour)" +.PD +Replace the foreground/background colour in the rendition mask with the +specified one. +.IP "$value = urxvt::GET_CUSTOM ($rend)" 4 +.IX Item "$value = urxvt::GET_CUSTOM ($rend)" +Return the \*(L"custom\*(R" value: Every rendition has 5 bits for use by +extensions. They can be set and changed as you like and are initially +zero. +.ie n .IP "$rend = urxvt::SET_CUSTOM ($rend, $new_value)" 4 +.el .IP "$rend = urxvt::SET_CUSTOM ($rend, \f(CW$new_value\fR)" 4 +.IX Item "$rend = urxvt::SET_CUSTOM ($rend, $new_value)" +Change the custom value. .ie n .Sh "The ""urxvt::term"" Class" .el .Sh "The \f(CWurxvt::term\fP Class" .IX Subsection "The urxvt::term Class" @@ -378,29 +427,56 @@ by the next method). .el .IP "$oldtext = \f(CW$term\fR\->selection ([$newtext])" 4 .IX Item "$oldtext = $term->selection ([$newtext])" Return the current selection text and optionally replace it by \f(CW$newtext\fR. -.ie n .IP "$term\->scr_overlay ($x, $y\fR, \f(CW$text)" 4 -.el .IP "$term\->scr_overlay ($x, \f(CW$y\fR, \f(CW$text\fR)" 4 -.IX Item "$term->scr_overlay ($x, $y, $text)" -Create a simple multi-line overlay box. See the next method for details. -.ie n .IP "$term\->scr_overlay_new ($x, $y\fR, \f(CW$width\fR, \f(CW$height)" 4 -.el .IP "$term\->scr_overlay_new ($x, \f(CW$y\fR, \f(CW$width\fR, \f(CW$height\fR)" 4 -.IX Item "$term->scr_overlay_new ($x, $y, $width, $height)" +.Sp +#=item \f(CW$term\fR\->overlay ($x, \f(CW$y\fR, \f(CW$text\fR) +# +#Create a simple multi-line overlay box. See the next method for details. +# +#=cut +.Sp +sub urxvt::term::scr_overlay { +die; + my ($self, \f(CW$x\fR, \f(CW$y\fR, \f(CW$text\fR) = \f(CW@_\fR; +.Sp +.Vb 1 +\& my @lines = split /\en/, $text; +.Ve +.Sp +.Vb 4 +\& my $w = 0; +\& for (map $self->strwidth ($_), @lines) { +\& $w = $_ if $w < $_; +\& } +.Ve +.Sp +.Vb 3 +\& $self->scr_overlay_new ($x, $y, $w, scalar @lines); +\& $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; +\&} +.Ve +.ie n .IP "$term\->overlay ($x, $y\fR, \f(CW$width\fR, \f(CW$height\fR[, \f(CW$rstyle\fR[, \f(CW$border]])" 4 +.el .IP "$term\->overlay ($x, \f(CW$y\fR, \f(CW$width\fR, \f(CW$height\fR[, \f(CW$rstyle\fR[, \f(CW$border\fR]])" 4 +.IX Item "$term->overlay ($x, $y, $width, $height[, $rstyle[, $border]])" Create a new (empty) overlay at the given position with the given -width/height. A border will be put around the box. If either \f(CW$x\fR or -\&\f(CW$y\fR is negative, then this is counted from the right/bottom side, -respectively. -.IP "$term\->scr_overlay_off" 4 -.IX Item "$term->scr_overlay_off" -Switch the overlay off again. -.ie n .IP "$term\->scr_overlay_set_char ($x, $y\fR, \f(CW$char\fR, \f(CW$rend = \s-1OVERLAY_RSTYLE\s0)" 4 -.el .IP "$term\->scr_overlay_set_char ($x, \f(CW$y\fR, \f(CW$char\fR, \f(CW$rend\fR = \s-1OVERLAY_RSTYLE\s0)" 4 -.IX Item "$term->scr_overlay_set_char ($x, $y, $char, $rend = OVERLAY_RSTYLE)" -Put a single character (specified numerically) at the given overlay -position. -.ie n .IP "$term\->scr_overlay_set ($x, $y\fR, \f(CW$text)" 4 -.el .IP "$term\->scr_overlay_set ($x, \f(CW$y\fR, \f(CW$text\fR)" 4 -.IX Item "$term->scr_overlay_set ($x, $y, $text)" -Write a string at the given position into the overlay. +width/height. \f(CW$rstyle\fR defines the initial rendition style +(default: \f(CW\*(C`OVERLAY_RSTYLE\*(C'\fR). +.Sp +If \f(CW$border\fR is \f(CW2\fR (default), then a decorative border will be put +around the box. +.Sp +If either \f(CW$x\fR or \f(CW$y\fR is negative, then this is counted from the +right/bottom side, respectively. +.Sp +This method returns an urxvt::overlay object. The overlay will be visible +as long as the perl object is referenced. +.Sp +Currently, the only method on the \f(CW\*(C`urxvt::overlay\*(C'\fR object is \f(CW\*(C`set\*(C'\fR: +.ie n .IP "$overlay\->set ($x, $y\fR, \f(CW$text\fR, \f(CW$rend)" 4 +.el .IP "$overlay\->set ($x, \f(CW$y\fR, \f(CW$text\fR, \f(CW$rend\fR)" 4 +.IX Item "$overlay->set ($x, $y, $text, $rend)" +Similar to \f(CW\*(C`$term\->ROW_t\*(C'\fR and \f(CW\*(C`$term\->ROW_r\*(C'\fR in that it puts +text in rxvt\-unicode's special encoding and an array of rendition values +at a specific position inside the overlay. .ie n .IP "$cellwidth = $term\fR\->strwidth \f(CW$string" 4 .el .IP "$cellwidth = \f(CW$term\fR\->strwidth \f(CW$string\fR" 4 .IX Item "$cellwidth = $term->strwidth $string" @@ -456,7 +532,7 @@ line \f(CW\*(C`\-$term\->nsaved\*(C'\fR. .Sp If \f(CW$new_text\fR is specified, it will replace characters in the current line, starting at column \f(CW$start_col\fR (default \f(CW0\fR), which is useful -to replace only parts of a line. The font iindex in the rendition will +to replace only parts of a line. The font index in the rendition will automatically be updated. .Sp \&\f(CW$text\fR is in a special encoding: tabs and wide characters that use more @@ -480,7 +556,7 @@ styles and similar information. See also \f(CW\*(C`$term\->ROW_t\*(C'\fR. .Sp When setting rendition, the font mask will be ignored. .Sp -See the section on \s-1RENDITION\s0, below. +See the section on \s-1RENDITION\s0, above. .ie n .IP "$length = $term\fR\->ROW_l ($row_number[, \f(CW$new_length])" 4 .el .IP "$length = \f(CW$term\fR\->ROW_l ($row_number[, \f(CW$new_length\fR])" 4 .IX Item "$length = $term->ROW_l ($row_number[, $new_length])" @@ -498,41 +574,26 @@ where one character corresponds to one screen cell. See .IX Item "$string = $term->special_decode $text" Converts rxvt-unicodes text reprsentation into a perl string. See \&\f(CW\*(C`$term\->ROW_t\*(C'\fR for details. -.Sh "\s-1RENDITION\s0" -.IX Subsection "RENDITION" -Rendition bitsets contain information about colour, font, font styles and -similar information for each screen cell. -.PP -The following \*(L"macros\*(R" deal with changes in rendition sets. You should -never just create a bitset, you should always modify an existing one, -as they contain important information required for correct operation of -rxvt\-unicode. -.IP "$rend = urxvt::DEFAULT_RSTYLE" 4 -.IX Item "$rend = urxvt::DEFAULT_RSTYLE" -Returns the default rendition, as used when the terminal is starting up or -being reset. Useful as a base .ie n .Sh "The ""urxvt::timer"" Class" .el .Sh "The \f(CWurxvt::timer\fP Class" .IX Subsection "The urxvt::timer Class" This class implements timer watchers/events. Time is represented as a fractional number of seconds since the epoch. Example: .PP -.Vb 11 -\& # create a digital clock display in upper right corner +.Vb 8 +\& $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); \& $term->{timer} = urxvt::timer \& ->new -\& ->start (urxvt::NOW) +\& ->interval (1) \& ->cb (sub { -\& my ($timer) = @_; -\& my $time = $timer->at; -\& $timer->start ($time + 1); -\& $self->scr_overlay (-1, 0, -\& POSIX::strftime "%H:%M:%S", localtime $time); +\& $term->{overlay}->set (0, 0, +\& sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); \& }); .Ve .IP "$timer = new urxvt::timer" 4 .IX Item "$timer = new urxvt::timer" -Create a new timer object in stopped state. +Create a new timer object in started state. It is scheduled to fire +immediately. .ie n .IP "$timer = $timer\fR\->cb (sub { my ($timer) = \f(CW@_; ... })" 4 .el .IP "$timer = \f(CW$timer\fR\->cb (sub { my ($timer) = \f(CW@_\fR; ... })" 4 .IX Item "$timer = $timer->cb (sub { my ($timer) = @_; ... })" @@ -545,6 +606,12 @@ Return the time this watcher will fire next. .el .IP "$timer = \f(CW$timer\fR\->set ($tstamp)" 4 .IX Item "$timer = $timer->set ($tstamp)" Set the time the event is generated to \f(CW$tstamp\fR. +.ie n .IP "$timer = $timer\->interval ($interval)" 4 +.el .IP "$timer = \f(CW$timer\fR\->interval ($interval)" 4 +.IX Item "$timer = $timer->interval ($interval)" +Normally (and when \f(CW$interval\fR is \f(CW0\fR), the timer will automatically +stop after it has fired once. If \f(CW$interval\fR is non\-zero, then the timer +is automatically rescheduled at the given intervals. .ie n .IP "$timer = $timer\->start" 4 .el .IP "$timer = \f(CW$timer\fR\->start" 4 .IX Item "$timer = $timer->start" diff --git a/doc/rxvtperl.3.txt b/doc/rxvtperl.3.txt index ff9b9538..1233fab6 100644 --- a/doc/rxvtperl.3.txt +++ b/doc/rxvtperl.3.txt @@ -40,14 +40,13 @@ DESCRIPTION URxvt.keysym.C-M-r: perl:selection:rot13 digital-clock + Displays a digital clock using the built-in overlay. + + example-refresh-hooks Displays a very simple digital clock in the upper right corner of the window. Illustrates overwriting the refresh callbacks to create your own overlays or changes. - simple-overlay-clock - Displays a digital clock using the built-in overlay (colorful, - useless). - General API Considerations All objects (such as terminals, time watchers etc.) are typical reference-to-hash objects. The hash can be used to store anything you @@ -158,6 +157,45 @@ DESCRIPTION $time = urxvt::NOW Returns the "current time" (as per the event loop). + RENDITION + Rendition bitsets contain information about colour, font, font styles + and similar information for each screen cell. + + The following "macros" deal with changes in rendition sets. You should + never just create a bitset, you should always modify an existing one, as + they contain important information required for correct operation of + rxvt-unicode. + + $rend = urxvt::DEFAULT_RSTYLE + Returns the default rendition, as used when the terminal is starting + up or being reset. Useful as a base to start when creating + renditions. + + $rend = urxvt::OVERLAY_RSTYLE + Return the rendition mask used for overlays by default. + + $rendbit = urxvt::RS_Bold, RS_Italic, RS_Blink, RS_RVid, RS_Uline + Return the bit that enabled bold, italic, blink, reverse-video and + underline, respectively. To enable such a style, just logically OR + it into the bitset. + + $foreground = urxvt::GET_BASEFG $rend + $background = urxvt::GET_BASEBG $rend + Return the foreground/background colour index, respectively. + + $rend = urxvt::SET_FGCOLOR ($rend, $new_colour) + $rend = urxvt::SET_BGCOLOR ($rend, $new_colour) + Replace the foreground/background colour in the rendition mask with + the specified one. + + $value = urxvt::GET_CUSTOM ($rend) + Return the "custom" value: Every rendition has 5 bits for use by + extensions. They can be set and changed as you like and are + initially zero. + + $rend = urxvt::SET_CUSTOM ($rend, $new_value) + Change the custom value. + The "urxvt::term" Class $value = $term->resource ($name[, $newval]) Returns the current resource value associated with a given name and @@ -207,25 +245,42 @@ DESCRIPTION Return the current selection text and optionally replace it by $newtext. - $term->scr_overlay ($x, $y, $text) - Create a simple multi-line overlay box. See the next method for - details. + #=item $term->overlay ($x, $y, $text) # #Create a simple multi-line + overlay box. See the next method for details. # #=cut - $term->scr_overlay_new ($x, $y, $width, $height) + sub urxvt::term::scr_overlay { die; my ($self, $x, $y, $text) = @_; + + my @lines = split /\n/, $text; + + my $w = 0; + for (map $self->strwidth ($_), @lines) { + $w = $_ if $w < $_; + } + + $self->scr_overlay_new ($x, $y, $w, scalar @lines); + $self->scr_overlay_set (0, $_, $lines[$_]) for 0.. $#lines; + } + + $term->overlay ($x, $y, $width, $height[, $rstyle[, $border]]) Create a new (empty) overlay at the given position with the given - width/height. A border will be put around the box. If either $x or - $y is negative, then this is counted from the right/bottom side, - respectively. + width/height. $rstyle defines the initial rendition style (default: + "OVERLAY_RSTYLE"). + + If $border is 2 (default), then a decorative border will be put + around the box. - $term->scr_overlay_off - Switch the overlay off again. + If either $x or $y is negative, then this is counted from the + right/bottom side, respectively. - $term->scr_overlay_set_char ($x, $y, $char, $rend = OVERLAY_RSTYLE) - Put a single character (specified numerically) at the given overlay - position. + This method returns an urxvt::overlay object. The overlay will be + visible as long as the perl object is referenced. - $term->scr_overlay_set ($x, $y, $text) - Write a string at the given position into the overlay. + Currently, the only method on the "urxvt::overlay" object is "set": + + $overlay->set ($x, $y, $text, $rend) + Similar to "$term->ROW_t" and "$term->ROW_r" in that it puts text in + rxvt-unicode's special encoding and an array of rendition values at + a specific position inside the overlay. $cellwidth = $term->strwidth $string Returns the number of screen-cells this string would need. Correctly @@ -272,7 +327,7 @@ DESCRIPTION If $new_text is specified, it will replace characters in the current line, starting at column $start_col (default 0), which is useful to - replace only parts of a line. The font iindex in the rendition will + replace only parts of a line. The font index in the rendition will automatically be updated. $text is in a special encoding: tabs and wide characters that use @@ -295,7 +350,7 @@ DESCRIPTION When setting rendition, the font mask will be ignored. - See the section on RENDITION, below. + See the section on RENDITION, above. $length = $term->ROW_l ($row_number[, $new_length]) Returns the number of screen cells that are in use ("the line @@ -312,37 +367,22 @@ DESCRIPTION Converts rxvt-unicodes text reprsentation into a perl string. See "$term->ROW_t" for details. - RENDITION - Rendition bitsets contain information about colour, font, font styles - and similar information for each screen cell. - - The following "macros" deal with changes in rendition sets. You should - never just create a bitset, you should always modify an existing one, as - they contain important information required for correct operation of - rxvt-unicode. - - $rend = urxvt::DEFAULT_RSTYLE - Returns the default rendition, as used when the terminal is starting - up or being reset. Useful as a base - The "urxvt::timer" Class This class implements timer watchers/events. Time is represented as a fractional number of seconds since the epoch. Example: - # create a digital clock display in upper right corner + $term->{overlay} = $term->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); $term->{timer} = urxvt::timer ->new - ->start (urxvt::NOW) + ->interval (1) ->cb (sub { - my ($timer) = @_; - my $time = $timer->at; - $timer->start ($time + 1); - $self->scr_overlay (-1, 0, - POSIX::strftime "%H:%M:%S", localtime $time); - }); + $term->{overlay}->set (0, 0, + sprintf "%2d:%02d:%02d", (localtime urxvt::NOW)[2,1,0]); + }); $timer = new urxvt::timer - Create a new timer object in stopped state. + Create a new timer object in started state. It is scheduled to fire + immediately. $timer = $timer->cb (sub { my ($timer) = @_; ... }) Set the callback to be called when the timer triggers. @@ -353,6 +393,11 @@ DESCRIPTION $timer = $timer->set ($tstamp) Set the time the event is generated to $tstamp. + $timer = $timer->interval ($interval) + Normally (and when $interval is 0), the timer will automatically + stop after it has fired once. If $interval is non-zero, then the + timer is automatically rescheduled at the given intervals. + $timer = $timer->start Start the timer. diff --git a/src/perl/digital-clock b/src/perl/digital-clock index 413951ee..ef4e2a50 100644 --- a/src/perl/digital-clock +++ b/src/perl/digital-clock @@ -1,49 +1,20 @@ #! 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->{digital_clock_overlay} = $self->overlay (-1, 0, 8, 1, urxvt::OVERLAY_RSTYLE, 0); + $self->{digital_clock_timer} = urxvt::timer ->new - ->start (urxvt::NOW) + ->interval (1) ->cb (sub { - $self->{digital_clock_refresh}->start ($self->{digital_clock_refresh}->at + 1); - $self->want_refresh; + $self->{digital_clock_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}); - - () -} - diff --git a/src/perl/example-refresh-hooks b/src/perl/example-refresh-hooks new file mode 100644 index 00000000..413951ee --- /dev/null +++ b/src/perl/example-refresh-hooks @@ -0,0 +1,49 @@ +#! perl + +# this creates a simple digital clock by overwriting the refresh hooks + +sub on_init { + my ($self) = @_; + + # force a refresh every second + $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; + }); + + () +} + +# 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}); + + () +} + + diff --git a/src/perl/simple-overlay-clock b/src/perl/simple-overlay-clock deleted file mode 100644 index 5c98ff4a..00000000 --- a/src/perl/simple-overlay-clock +++ /dev/null @@ -1,23 +0,0 @@ -#! perl - -# this creates a simple clock using the overlay box. it is not very useful, because -# it makes the iso14755 mode almost useles as its box gets destroyed every second. - -use POSIX (); - -sub on_init { - my ($self) = @_; - - $self->{timer} = urxvt::timer - ->new - ->start (urxvt::NOW) - ->cb (sub { - my ($timer) = @_; - my $time = $timer->at; - $timer->start ($time + 1); - $self->scr_overlay (-1, 0, POSIX::strftime "%H:%M:%S", localtime $time); - }); - - () -} - diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs index a4129f7b..e801dc14 100644 --- a/src/rxvtperl.xs +++ b/src/rxvtperl.xs @@ -141,6 +141,8 @@ perl_watcher::invoke (const char *type, SV *self, int arg) struct timer : time_watcher, perl_watcher { + tstamp interval; + timer () : time_watcher (this, &timer::execute) { @@ -148,6 +150,9 @@ struct timer : time_watcher, perl_watcher void execute (time_watcher &w) { + if (interval) + start (at + interval); + invoke ("urxvt::timer", newSVtimer (this)); } }; @@ -168,6 +173,136 @@ struct iow : io_watcher, perl_watcher } }; +///////////////////////////////////////////////////////////////////////////// + +#define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") + +struct overlay { + HV *self; + rxvt_term *THIS; + int x, y, w, h; + int border; + text_t **text; + rend_t **rend; + + overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border); + ~overlay (); + + void swap (); + + void set (int x, int y, SV *str, SV *rend); +}; + +overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) +: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2) +{ + if (border == 2) + { + w += 2; + h += 2; + } + + text = new text_t *[h]; + rend = new rend_t *[h]; + + for (int y = 0; y < h; y++) + { + text_t *tp = text[y] = new text_t[w]; + rend_t *rp = rend[y] = new rend_t[w]; + + text_t t0, t1, t2; + rend_t r = rstyle; + + if (border == 2) + { + if (y == 0) + t0 = 0x2554, t1 = 0x2550, t2 = 0x2557; + else if (y < h - 1) + t0 = 0x2551, t1 = 0x0020, t2 = 0x2551; + else + t0 = 0x255a, t1 = 0x2550, t2 = 0x255d; + + *tp++ = t0; + *rp++ = r; + + for (int x = w - 2; x-- > 0; ) + { + *tp++ = t1; + *rp++ = r; + } + + *tp = t2; + *rp = r; + } + else + for (int x = w; x-- > 0; ) + { + *tp++ = 0x0020; + *rp++ = r; + } + } + + THIS->want_refresh = 1; +} + +overlay::~overlay () +{ + for (int y = h; y--; ) + { + delete [] text[y]; + delete [] rend[y]; + } + + delete [] text; + delete [] rend; + + THIS->want_refresh = 1; +} + +void overlay::swap () +{ + int ov_x = max (0, min (MOD (x, THIS->ncol), THIS->ncol - w)); + int ov_y = max (0, min (MOD (y, THIS->nrow), THIS->nrow - h)); + + int ov_w = min (w, THIS->ncol - ov_x); + int ov_h = min (h, THIS->nrow - ov_y); + + for (int y = ov_h; y--; ) + { + text_t *t1 = text [y]; + rend_t *r1 = rend [y]; + + text_t *t2 = ROW(y + ov_y - THIS->view_start).t + ov_x; + rend_t *r2 = ROW(y + ov_y - THIS->view_start).r + ov_x; + + for (int x = ov_w; x--; ) + { + text_t t = *t1; *t1++ = *t2; *t2++ = t; + rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, THIS->fontset [GET_STYLE (r)]->find_font (t)); + } + } + +} + +void overlay::set (int x, int y, SV *str, SV *rend) +{ + x += border; + y += border; + + if (!IN_RANGE_EXC (y, 0, h - border)) + return; + + wchar_t *wstr = sv2wcs (str); + + for (int col = min (wcslen (wstr), w - x - border); col--; ) + text [y][x + col] = wstr [col]; + + free (wstr); + + THIS->want_refresh = 1; +} + + ///////////////////////////////////////////////////////////////////////////// struct rxvt_perl_interp rxvt_perl; @@ -215,12 +350,32 @@ rxvt_perl_interp::init () bool rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) { - if (!perl - || (!should_invoke [htype] && htype != HOOK_INIT && htype != HOOK_DESTROY)) + if (!perl) return false; if (htype == HOOK_INIT) // first hook ever called - term->self = (void *)newSVptr ((void *)term, "urxvt::term"); + { + term->self = (void *)newSVptr ((void *)term, "urxvt::term"); + hv_store ((HV *)SvRV ((SV *)term->self), "_overlay", 8, newRV_noinc ((SV *)newHV ()), 0); + } + else if (htype == HOOK_DESTROY) + { + // handled later + } + else if (htype == HOOK_REFRESH_BEGIN || htype == HOOK_REFRESH_END) + { + HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)term->self), "_overlay", 8, 0)); + + if (HvKEYS (hv)) + { + hv_iterinit (hv); + + while (HE *he = hv_iternext (hv)) + ((overlay *)SvIV (hv_iterval (hv, he)))->swap (); + } + } + else if (!should_invoke [htype]) + return false; dSP; va_list ap; @@ -522,9 +677,7 @@ rxvt_term::ROW_t (int row_number, SV *new_text = 0, int start_col = 0) if (new_text) { - STRLEN slen; - char *str = SvPVutf8 (new_text, slen); - wchar_t *wstr = rxvt_utf8towcs (str, slen); + wchar_t *wstr = sv2wcs (new_text); int len = wcslen (wstr); @@ -705,32 +858,47 @@ rxvt_term::selection (SV *newtext = 0) } void -rxvt_term::scr_overlay_new (int x, int y, int w, int h) +rxvt_term::tt_write (SV *octets) + INIT: + STRLEN len; + char *str = SvPVbyte (octets, len); + C_ARGS: + (unsigned char *)str, len -void -rxvt_term::scr_overlay_off () +SV * +rxvt_term::overlay (int x, int y, int w, int h, int rstyle = OVERLAY_RSTYLE, int border = 2) + CODE: +{ + overlay *o = new overlay (THIS, x, y, w, h, rstyle, border); + RETVAL = newSVptr ((void *)o, "urxvt::overlay"); + o->self = (HV *)SvRV (RETVAL); + + HV *hv = (HV *)SvRV (*hv_fetch ((HV *)SvRV ((SV *)THIS->self), "_overlay", 8, 0)); + char key[33]; sprintf (key, "%32lx", (long)o); + hv_store (hv, key, 32, newSViv ((long)o), 0); +} + OUTPUT: + RETVAL + +MODULE = urxvt PACKAGE = urxvt::overlay void -rxvt_term::scr_overlay_set_char (int x, int y, U32 text, U32 rend = OVERLAY_RSTYLE) - CODE: - THIS->scr_overlay_set (x, y, text, rend); +overlay::set (int x, int y, SV *text, SV *rend = 0) void -rxvt_term::scr_overlay_set (int x, int y, SV *text) +overlay::DESTROY () CODE: { - wchar_t *wtext = sv2wcs (text); - THIS->scr_overlay_set (x, y, wtext); - free (wtext); -} + SV **ovs = hv_fetch ((HV *)SvRV ((SV *)THIS->THIS->self), "_overlay", 8, 0); + if (ovs) + { + HV *hv = (HV *)SvRV (*ovs); + char key[33]; sprintf (key, "%32lx", (long)THIS); + hv_delete (hv, key, 32, G_DISCARD); + } -void -rxvt_term::tt_write (SV *octets) - INIT: - STRLEN len; - char *str = SvPVbyte (octets, len); - C_ARGS: - (unsigned char *)str, len + delete THIS; +} MODULE = urxvt PACKAGE = urxvt::timer @@ -738,6 +906,7 @@ SV * timer::new () CODE: timer *w = new timer; + w->start (NOW); RETVAL = newSVptr ((void *)w, "urxvt::timer"); w->self = (HV *)SvRV (RETVAL); OUTPUT: @@ -758,6 +927,14 @@ timer::at () OUTPUT: RETVAL +timer * +timer::interval (NV interval) + CODE: + THIS->interval = interval; + RETVAL = THIS; + OUTPUT: + RETVAL + timer * timer::set (NV tstamp) CODE: diff --git a/src/screen.C b/src/screen.C index 700c211b..e4374b46 100644 --- a/src/screen.C +++ b/src/screen.C @@ -1959,7 +1959,6 @@ rxvt_term::scr_refresh (unsigned char refresh_type) /* * B: reverse any characters which are selected */ - PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); scr_reverse_selection (); /* @@ -2050,6 +2049,7 @@ rxvt_term::scr_refresh (unsigned char refresh_type) } } + PERL_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); #if ENABLE_OVERLAY scr_swap_overlay (); #endif @@ -2322,6 +2322,7 @@ rxvt_term::scr_refresh (unsigned char refresh_type) #if ENABLE_OVERLAY scr_swap_overlay (); #endif + PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END)); /* * G: cleanup cursor and display outline cursor if necessary @@ -2369,7 +2370,6 @@ rxvt_term::scr_refresh (unsigned char refresh_type) * H: cleanup selection */ scr_reverse_selection (); - PERL_INVOKE ((this, HOOK_REFRESH_END, DT_END)); if (refresh_type & SMOOTH_REFRESH) XFlush (display->display); diff --git a/src/typemap b/src/typemap index d670fdde..23799ae8 100644 --- a/src/typemap +++ b/src/typemap @@ -1,6 +1,7 @@ rxvt_term * T_TERM timer * T_TIMER iow * T_IOW +overlay * T_OVERLAY INPUT T_TERM @@ -9,6 +10,8 @@ T_TIMER $var = SvTIMER ($arg); T_IOW $var = SvIOW ($arg); +T_OVERLAY + $var = SvOVERLAY ($arg); OUTPUT T_TERM diff --git a/src/urxvt.pm b/src/urxvt.pm index a2730dff..b53af1f3 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -196,6 +196,8 @@ correct place, e.g. on stderr of the connecting urxvtc client. Returns the "current time" (as per the event loop). +=back + =head2 RENDITION Rendition bitsets contain information about colour, font, font styles and @@ -361,8 +363,6 @@ sub invoke { 0 } -=back - =head2 The C Class =over 4