--- rxvt-unicode/src/urxvt.pm 2006/01/07 04:19:43 1.43 +++ rxvt-unicode/src/urxvt.pm 2006/01/08 00:11:38 1.50 @@ -19,8 +19,8 @@ =head1 DESCRIPTION -Everytime a terminal object gets created, scripts specified via the -C resource are loaded and associated with it. +Everytime a terminal object gets created, extension scripts specified via +the C resource are loaded and associated with it. Scripts are compiled in a 'use strict' and 'use utf8' environment, and thus must be encoded as UTF-8. @@ -122,10 +122,11 @@ called whenever the relevant event happens. The first argument passed to them is an object private to each terminal -and extension package. You can call all C methods on it, but +and extension package. You can call all C methods on it, but its not a real C object. Instead, the real C object that is shared between all packages is stored in the C -member. +member. It is, however, blessed intot he package of the extension script, +so for all practical purposes you can treat an extension script as a class. All of them must return a boolean value. If it is true, then the event counts as being I, and the invocation of other hooks is skipped, @@ -180,16 +181,6 @@ See the F example extension. -=item on_focus_in $term - -Called whenever the window gets the keyboard focus, before urxvt does -focus in processing. - -=item on_focus_out $term - -Called wheneever the window loses keyboard focus, before urxvt does focus -out processing. - =item on_view_change $term, $offset Called whenever the view offset changes, i..e the user or program @@ -262,6 +253,16 @@ C action bound to it (see description of the B resource in the @@RXVT_NAME@@(1) manpage). +=item on_focus_in $term + +Called whenever the window gets the keyboard focus, before rxvt-unicode +does focus in processing. + +=item on_focus_out $term + +Called wheneever the window loses keyboard focus, before rxvt-unicode does +focus out processing. + =item on_key_press $term, $event, $octets =item on_key_release $term, $event @@ -272,6 +273,10 @@ =item on_motion_notify $term, $event +=item on_map_notify $term, $event + +=item on_unmap_notify $term, $event + Called whenever the corresponding X event is received for the terminal If the hook returns true, then the even will be ignored by rxvt-unicode. @@ -328,6 +333,14 @@ Returns the "current time" (as per the event loop). +=item urxvt::CurrentTime + +=item urxvt::ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, +Mod3Mask, Mod4Mask, Mod5Mask, Button1Mask, Button2Mask, Button3Mask, +Button4Mask, Button5Mask, AnyModifier + +Various constants for use in X events. + =back =head2 RENDITION @@ -386,11 +399,14 @@ package urxvt; +use utf8; use strict; use Scalar::Util (); +use List::Util (); our $TERM; our @HOOKNAME; +our %OPTION; our $LIBDIR; BEGIN { @@ -430,22 +446,23 @@ } } -my $script_pkg = "script0000"; -my %script_pkg; +my $extension_pkg = "extension0000"; +my %extension_pkg; # load a single script into its own package, once only -sub script_package($) { +sub extension_package($) { my ($path) = @_; - $script_pkg{$path} ||= do { - my $pkg = "urxvt::" . ($script_pkg++); + $extension_pkg{$path} ||= do { + my $pkg = "urxvt::" . ($extension_pkg++); - verbose 3, "loading script '$path' into package '$pkg'"; + verbose 3, "loading extension '$path' into package '$pkg'"; open my $fh, "<:raw", $path or die "$path: $!"; my $source = "package $pkg; use strict; use utf8;\n" + . "use base urxvt::term::proxy::;\n" . "#line 1 \"$path\"\n{\n" . (do { local $/; <$fh> }) . "\n};\n1"; @@ -465,12 +482,24 @@ if ($htype == 0) { # INIT my @dirs = ((split /:/, $TERM->resource ("perl_lib")), "$LIBDIR/perl"); + + my %want_ext; - for my $ext (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { + for (map { split /,/, $TERM->resource ("perl_ext_$_") } 1, 2) { + if ($_ eq "default") { + $want_ext{$_}++ for qw(selection); + } elsif (/-(.*)/) { + delete $want_ext{$1}; + } else { + $want_ext{$_}++; + } + } + + for my $ext (keys %want_ext) { my @files = grep -f $_, map "$_/$ext", @dirs; if (@files) { - register_package script_package $files[0]; + register_package extension_package $files[0]; } else { warn "perl extension '$ext' not found in perl library search path\n"; } @@ -486,14 +515,17 @@ keys %$cb; while (my ($pkg, $cb) = each %$cb) { - $retval = $cb->( - $TERM->{_pkg}{$pkg} ||= do { - my $proxy = bless { }, urxvt::term::proxy::; - Scalar::Util::weaken ($proxy->{term} = $TERM); - $proxy - }, - @_, - ) and last; + eval { + $retval = $cb->( + $TERM->{_pkg}{$pkg} ||= do { + my $proxy = bless { }, $pkg; + Scalar::Util::weaken ($proxy->{term} = $TERM); + $proxy + }, + @_, + ) and last; + }; + warn $@ if $@;#d# } } @@ -531,6 +563,14 @@ goto &$urxvt::term::proxy::AUTOLOAD; } +sub urxvt::destroy_hook::DESTROY { + ${$_[0]}->(); +} + +sub urxvt::destroy_hook(&) { + bless \shift, urxvt::destroy_hook:: +} + =head2 The C Class =over 4 @@ -539,6 +579,22 @@ Destroy the terminal object (close the window, free resources etc.). +=item $isset = $term->option ($optval[, $set]) + +Returns true if the option specified by C<$optval> is enabled, and +optionally change it. All option values are stored by name in the hash +C<%urxvt::OPTION>. Options not enabled in this binary are not in the hash. + +Here is a a likely non-exhaustive list of option names, please see the +source file F to see the actual list: + + borderLess console cursorBlink cursorUnderline hold iconic insecure + intensityStyles jumpScroll loginShell mapAlert meta8 mouseWheelScrollPage + pastableTabs pointerBlank reverseVideo scrollBar scrollBar_floating + scrollBar_right scrollTtyKeypress scrollTtyOutput scrollWithBuffer + secondaryScreen secondaryScroll skipBuiltinGlyphs transparent + tripleclickwords utmpInhibit visualBell + =item $value = $term->resource ($name[, $newval]) Returns the current resource value associated with a given name and @@ -557,8 +613,8 @@ terminal is destroyed, so changing options frequently will eat memory. Here is a a likely non-exhaustive list of resource names, not all of which -are supported in every build, please see the source to see the actual -list: +are supported in every build, please see the source file F +to see the actual list: answerbackstring backgroundPixmap backspace_key boldFont boldItalicFont borderLess color cursorBlink cursorUnderline cutchars delete_key @@ -578,7 +634,7 @@ sub urxvt::term::resource($$;$) { my ($self, $name) = (shift, shift); unshift @_, $self, $name, ($name =~ s/\s*\+\s*(\d+)$// ? $1 : 0); - goto &urxvt::term::_resource; + &urxvt::term::_resource } =item $rend = $term->rstyle ([$new_rstyle]) @@ -664,6 +720,33 @@ =back +=item $popup = $term->popup ($event) + +Creates a new C object that implements a popup menu. The +C<$event> I be the event causing the menu to pop up (a button event, +currently). + +=cut + +sub urxvt::term::popup { + my ($self, $event) = @_; + + $self->grab ($event->{time}, 1) + or return; + + my $popup = bless { + term => $self, + event => $event, + }, urxvt::popup::; + + Scalar::Util::weaken $popup->{term}; + + $self->{_destroy}{$popup} = urxvt::destroy_hook { $popup->{popup}->destroy }; + Scalar::Util::weaken $self->{_destroy}{$popup}; + + $popup +} + =item $cellwidth = $term->strwidth ($string) Returns the number of screen-cells this string would need. Correctly @@ -734,6 +817,15 @@ Return various integers describing terminal characteristics. +=item $modifiermask = $term->ModLevel3Mask + +=item $modifiermask = $term->ModMetaMask + +=item $modifiermask = $term->ModNumLockMask + +Return the modifier masks corresponding to the "ISO Level 3 Shift" (often +AltGr), the meta key (often Alt) and the num lock key, if applicable. + =item $view_start = $term->view_start ([$newvalue]) Returns the negative row number of the topmost line. Minimum value is @@ -924,6 +1016,59 @@ =back +=head2 The C Class + +=over 4 + +=cut + +package urxvt::popup; + +sub add_item { + my ($self, $item) = @_; + + push @{ $self->{item} }, $item; +} + +sub add_button { + my ($self, $text, $cb) = @_; + + $self->add_item ({ type => "button", text => "[ $text ]", activate => $cb, + render => sub { $_[0]{text} }, + }); +} + +sub add_toggle { + my ($self, $text, $cb, $value) = @_; + + my $item; $item = { + type => "button", + text => " $text", + value => $value, + render => sub { ($item->{value} ? "✔" : " ") . $text }, + activate => sub { $cb->($item->{value} = !$item->{value}); }, + }; + + $self->add_item ($item); +} + +sub show { + my ($self) = @_; + + local $urxvt::popup::self = $self; + + urxvt->new ("--perl-lib" => "", "--perl-ext-common" => "", "-pty-fd" => -1, "-sl" => 0, "-b" => 0, + "--transient-for" => $self->{term}->parent, + "-pe" => "urxvt-popup") + or die "unable to create popup window\n"; +} + +sub DESTROY { + my ($self) = @_; + + $self->{term}->ungrab; +} + =head2 The C Class This class implements timer watchers/events. Time is represented as a