1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # this extension implements popup-menu functionality for urxvt. it works |
3 | # this extension implements popup-menu functionality for urxvt. it works |
4 | # together with the urxvt::popup class. |
4 | # together with the urxvt::popup class - "no user servicable parts inside". |
5 | |
5 | |
6 | sub refresh { |
6 | sub refresh { |
7 | my ($self) = @_; |
7 | my ($self) = @_; |
8 | |
8 | |
9 | my $cmd = "\x1b[H"; |
9 | my $cmd = "\x1b[H"; |
… | |
… | |
51 | } |
51 | } |
52 | |
52 | |
53 | sub on_button_release { |
53 | sub on_button_release { |
54 | my ($self, $event) = @_; |
54 | my ($self, $event) = @_; |
55 | |
55 | |
56 | if ($event->{button} == $self->{data}{event}{button}) { |
|
|
57 | $self->ungrab; |
|
|
58 | $self->destroy; |
|
|
59 | } |
|
|
60 | |
|
|
61 | $self->{press}[$event->{button}] = 0; |
56 | $self->{press}[$event->{button}] = 0; |
62 | |
57 | |
63 | my ($row, $col) = ($event->{row}, $event->{col}); |
58 | my ($row, $col) = ($event->{row}, $event->{col}); |
64 | if ($col >= 0 && $col < $self->ncol |
59 | if ($col >= 0 && $col < $self->ncol |
65 | && $row >= 0 && $row < @{ $self->{data}{item} }) { |
60 | && $row >= 0 && $row < @{ $self->{data}{item} }) { |
66 | $self->{data}{item}[$row]{activate}->($event); |
61 | my $item = $self->{data}{item}[$row]; |
|
|
62 | $item->{activate}->($event, $item); |
67 | } |
63 | } |
68 | |
64 | |
69 | $self->refresh; |
65 | $self->refresh; |
|
|
66 | |
|
|
67 | if ($event->{button} == $self->{data}{event}{button}) { |
|
|
68 | $self->ungrab; |
|
|
69 | $self->destroy; |
|
|
70 | } |
70 | |
71 | |
71 | 1 |
72 | 1 |
72 | } |
73 | } |
73 | |
74 | |
74 | sub on_focus_out { |
75 | sub on_focus_out { |
… | |
… | |
86 | my $data = $self->{data} = $urxvt::popup::self; |
87 | my $data = $self->{data} = $urxvt::popup::self; |
87 | |
88 | |
88 | $_->{width} = $self->strwidth ($_->{text}) |
89 | $_->{width} = $self->strwidth ($_->{text}) |
89 | for @{ $data->{item} }; |
90 | for @{ $data->{item} }; |
90 | |
91 | |
|
|
92 | $self->resource (title => "URxvt Popup Menu"); |
|
|
93 | $self->resource (name => "URxvt.popup"); |
|
|
94 | |
91 | $self->resource ($_ => $data->{term}->resource ($_)) |
95 | $self->resource ($_ => $data->{term}->resource ($_)) |
92 | for qw(font boldFont italicFont boldItalicFont color+0 color+1); |
96 | for qw(font boldFont italicFont boldItalicFont color+0 color+1); |
93 | |
97 | |
94 | my $width = List::Util::max map $_->{width}, @{ $data->{item} }; |
98 | my $width = List::Util::max map $_->{width}, @{ $data->{item} }; |
95 | my $height = @{ $data->{item} }; |
99 | my $height = @{ $data->{item} }; |
… | |
… | |
97 | my $pos = ""; |
101 | my $pos = ""; |
98 | |
102 | |
99 | if ($data->{event}) { |
103 | if ($data->{event}) { |
100 | my $x = int List::Util::max 0, $data->{event}{x_root} - $width * $data->{term}->fwidth * 0.5; |
104 | my $x = int List::Util::max 0, $data->{event}{x_root} - $width * $data->{term}->fwidth * 0.5; |
101 | my $y = int List::Util::max 0, $data->{event}{y_root} - $data->{term}->fheight * 0.5; |
105 | my $y = int List::Util::max 0, $data->{event}{y_root} - $data->{term}->fheight * 0.5; |
102 | |
|
|
103 | $pos = "+$x+$y"; |
106 | $pos = "+$x+$y"; |
104 | } |
107 | } |
105 | |
108 | |
106 | $self->resource (geometry => "${width}x${height}$pos"); |
109 | $self->resource (geometry => "${width}x${height}$pos"); |
|
|
110 | |
|
|
111 | $self->{term}{urxvt_popup_init_done} = 1; |
107 | |
112 | |
108 | () |
113 | () |
109 | } |
114 | } |
110 | |
115 | |
111 | sub on_start { |
116 | sub on_start { |
… | |
… | |
130 | $self->grab ($self->{data}{event}{time}, 1) |
135 | $self->grab ($self->{data}{event}{time}, 1) |
131 | and $self->allow_events_async; |
136 | and $self->allow_events_async; |
132 | } |
137 | } |
133 | |
138 | |
134 | |
139 | |
135 | |
|
|
136 | |
|
|
137 | |
|
|
138 | |
|
|