1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | =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 |
2 | |
30 | |
3 | sub on_start { |
31 | sub on_start { |
4 | my ($self) = @_; |
32 | my ($self) = @_; |
5 | |
33 | |
6 | $self->grab_button (3, urxvt::ControlMask); |
34 | $self->grab_button (2, urxvt::ControlMask); |
|
|
35 | |
|
|
36 | () |
7 | } |
37 | } |
8 | |
38 | |
9 | sub on_button_press { |
39 | sub on_button_press { |
10 | my ($self, $event) = @_; |
40 | my ($self, $event) = @_; |
11 | |
41 | |
12 | if ($event->{button} == 3 && $event->{state} & urxvt::ControlMask) { |
42 | if ($event->{button} == 2 && $event->{state} & urxvt::ControlMask) { |
13 | my $popup = $self->popup ($event) |
43 | my $popup = $self->popup ($event) |
14 | or return; |
44 | or return 1; |
15 | |
45 | |
16 | $popup->add_title ("Options"); |
46 | $popup->add_title ("Options"); |
17 | $popup->add_separator; |
47 | $popup->add_separator; |
18 | |
48 | |
19 | my %unsafe = map +($_ => 1), |
49 | my %unsafe = map +($_ => 1), |
20 | qw(borderLess console iconic loginShell reverseVideo |
50 | qw(borderLess console iconic loginShell reverseVideo |
21 | scrollBar scrollBar_floating scrollBar_right |
51 | scrollBar scrollBar_floating scrollBar_right |
22 | secondaryScreen transparent utmpInhibit meta8); |
52 | secondaryScreen transparent utmpInhibit meta8 |
|
|
53 | override_redirect); |
23 | |
54 | |
24 | for my $name (sort keys %urxvt::OPTION) { |
55 | for my $name (sort keys %urxvt::OPTION) { |
25 | next if $unsafe{$name}; |
56 | next if $unsafe{$name}; |
26 | |
57 | |
27 | my $optval = $urxvt::OPTION{$name}; |
58 | my $optval = $urxvt::OPTION{$name}; |
28 | |
59 | |
29 | $popup->add_toggle ($name => sub { $self->option ($optval, $_[0]) }, |
60 | $popup->add_toggle ($name => $self->option ($optval), |
30 | $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 | } |
|
|
69 | |
|
|
70 | { |
|
|
71 | $popup->add_separator; |
|
|
72 | my $locale = $self->locale; |
|
|
73 | $locale =~ y/\x20-\x7e//cd; |
|
|
74 | $popup->add_title ("Locale: $locale"); |
31 | } |
75 | } |
32 | |
76 | |
33 | $popup->show; |
77 | $popup->show; |
34 | |
78 | |
35 | return 1; |
79 | return 1; |