ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/option-popup
Revision: 1.12
Committed: Sun Jun 10 17:31:53 2012 UTC (11 years, 11 months ago) by root
Branch: MAIN
Changes since 1.11: +28 -0 lines
Log Message:
move perl docs to extensions

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3 root 1.12 =head1 NAME
4    
5     option-popup - option menu (enabled by default)
6    
7     =head1 DESCRIPTION
8    
9     Binds a popup menu to Ctrl-Button2 that lets you toggle (some) options at
10     runtime.
11    
12     Other extensions can extend this popup menu by pushing a code reference
13     onto C<@{ $term->{option_popup_hook} }>, which gets called whenever the
14     popup is being displayed.
15    
16     Its sole argument is the popup menu, which can be modified. It should
17     either return nothing or a string, the initial boolean value and a code
18     reference. The string will be used as button text and the code reference
19     will be called when the toggle changes, with the new boolean value as
20     first argument.
21    
22     The following will add an entry C<myoption> that changes
23     C<< $self->{myoption} >>:
24    
25     push @{ $self->{term}{option_popup_hook} }, sub {
26     ("my option" => $myoption, sub { $self->{myoption} = $_[0] })
27     };
28    
29     =cut
30    
31 root 1.4 sub on_start {
32     my ($self) = @_;
33    
34 root 1.7 $self->grab_button (2, urxvt::ControlMask);
35 root 1.8
36     ()
37 root 1.4 }
38    
39 root 1.1 sub on_button_press {
40     my ($self, $event) = @_;
41    
42 root 1.7 if ($event->{button} == 2 && $event->{state} & urxvt::ControlMask) {
43 root 1.6 my $popup = $self->popup ($event)
44 root 1.7 or return 1;
45 root 1.1
46 root 1.5 $popup->add_title ("Options");
47     $popup->add_separator;
48    
49 root 1.1 my %unsafe = map +($_ => 1),
50     qw(borderLess console iconic loginShell reverseVideo
51     scrollBar scrollBar_floating scrollBar_right
52 root 1.9 secondaryScreen transparent utmpInhibit meta8
53     override_redirect);
54 root 1.1
55     for my $name (sort keys %urxvt::OPTION) {
56     next if $unsafe{$name};
57    
58     my $optval = $urxvt::OPTION{$name};
59    
60 root 1.10 $popup->add_toggle ($name => $self->option ($optval),
61     sub { $self->option ($optval, $_[0]) });
62     }
63    
64     for my $hook (@{ $self->{term}{option_popup_hook} || [] }) {
65     if (my ($name, $value, $cb) = $hook->($popup)) {
66     $popup->add_toggle ($name => $value, sub { $cb->($_[0]) });
67     }
68 root 1.1 }
69    
70 root 1.11 {
71     $popup->add_separator;
72     my $locale = $self->locale;
73     $locale =~ y/\x20-\x7e//cd;
74     $popup->add_title ("Locale: $locale");
75     }
76    
77 root 1.1 $popup->show;
78    
79     return 1;
80     }
81    
82     ()
83     }
84