--- rxvt-unicode/src/urxvt.pm 2006/01/07 19:29:17 1.44 +++ rxvt-unicode/src/urxvt.pm 2006/01/07 20:29:28 1.46 @@ -181,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 @@ -263,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 @@ -273,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. @@ -536,6 +540,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 @@ -583,7 +595,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]) @@ -669,6 +681,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 @@ -929,6 +968,43 @@ =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 }); +} + +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