diff options
author | root <root> | 2012-09-04 22:41:11 +0000 |
---|---|---|
committer | root <root> | 2012-09-04 22:41:11 +0000 |
commit | d50a22a63f36f3d4fb5bd2f4d7d0f89f36d84e8f (patch) | |
tree | 64566414b54ff274345437c2b02a4f1e73b80e72 /src/perl/option-popup | |
parent | 5ee396e7ac453f939e8ec74546756dba45906827 (diff) |
*** empty log message ***
Diffstat (limited to 'src/perl/option-popup')
-rw-r--r-- | src/perl/option-popup | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/perl/option-popup b/src/perl/option-popup new file mode 100644 index 0000000..d15aa1e --- /dev/null +++ b/src/perl/option-popup @@ -0,0 +1,84 @@ +#! perl + +=head1 NAME + +option-popup - option menu (enabled by default) + +=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<myoption> 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) = @_; + + $self->grab_button (2, urxvt::ControlMask); + + () +} + +sub on_button_press { + my ($self, $event) = @_; + + if ($event->{button} == 2 && $event->{state} & urxvt::ControlMask) { + my $popup = $self->popup ($event) + or return 1; + + $popup->add_title ("Options"); + $popup->add_separator; + + my %unsafe = map +($_ => 1), + qw(borderLess console iconic loginShell reverseVideo + scrollBar scrollBar_floating scrollBar_right + secondaryScreen transparent utmpInhibit meta8 + override_redirect); + + for my $name (sort keys %urxvt::OPTION) { + next if $unsafe{$name}; + + my $optval = $urxvt::OPTION{$name}; + + $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; + + return 1; + } + + () +} + |