--- rxvt-unicode/src/perl/option-popup 2006/02/02 00:18:51 1.9 +++ rxvt-unicode/src/perl/option-popup 2021/06/23 12:45:29 1.15 @@ -1,5 +1,33 @@ #! perl +=head1 NAME + +option-popup - option menu + +=head1 DESCRIPTION + +Binds a popup menu to Ctrl-Button2 that lets you toggle (some) options at +runtime. + +Other extensions can extend this popup menu by pushing a code reference +onto C<< @{ $term->{option_popup_hook} } >>, which gets called whenever +the popup is being displayed. + +Its sole argument is the popup menu, which can be modified. It should +either return nothing or a string, the initial boolean value and a code +reference. The string will be used as button text and the code reference +will be called when the toggle changes, with the new boolean value as +first argument. + +The following will add an entry C that changes +C<< $self->{myoption} >>: + + push @{ $self->{term}{option_popup_hook} }, sub { + ("my option" => $myoption, sub { $self->{myoption} = $_[0] }) + }; + +=cut + sub on_start { my ($self) = @_; @@ -29,8 +57,21 @@ my $optval = $urxvt::OPTION{$name}; - $popup->add_toggle ($name => sub { $self->option ($optval, $_[0]) }, - $self->option ($optval)); + $popup->add_toggle ($name => $self->option ($optval), + sub { $self->option ($optval, $_[0]) }); + } + + for my $hook (@{ $self->{term}{option_popup_hook} || [] }) { + if (my ($name, $value, $cb) = $hook->($popup)) { + $popup->add_toggle ($name => $value, sub { $cb->($_[0]) }); + } + } + + { + $popup->add_separator; + my $locale = $self->locale; + $locale =~ y/\x20-\x7e//cd; + $popup->add_title ("Locale: $locale"); } $popup->show;