1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | # this extension implements popup-menu functionality for urxvt. it works |
|
|
4 | # together with the urxvt::popup class. |
2 | |
5 | |
3 | use List::Util; |
6 | use List::Util; |
4 | |
7 | |
5 | sub refresh { |
8 | sub refresh { |
6 | my ($self) = @_; |
9 | my ($self) = @_; |
… | |
… | |
13 | |
16 | |
14 | if ($row == $self->{hover}) { |
17 | if ($row == $self->{hover}) { |
15 | $rend = $self->{press} ? "\x1b[m" : "\x1b[30;46m"; |
18 | $rend = $self->{press} ? "\x1b[m" : "\x1b[30;46m"; |
16 | } |
19 | } |
17 | |
20 | |
18 | $cmd .= "$rend\x1b[K" . $self->locale_encode ($item->{text}) . "\015\012"; |
21 | $cmd .= "$rend\x1b[K"; |
|
|
22 | $cmd .= $self->locale_encode ($item->{render}->($item)); |
|
|
23 | $cmd .= "\015\012"; |
19 | |
24 | |
20 | $row++; |
25 | $row++; |
21 | } |
26 | } |
22 | |
27 | |
23 | $self->cmd_parse (substr $cmd, 0, -2); |
28 | $self->cmd_parse (substr $cmd, 0, -2); |
… | |
… | |
50 | if ($event->{button} == $self->{data}{event}{button}) { |
55 | if ($event->{button} == $self->{data}{event}{button}) { |
51 | $self->ungrab; |
56 | $self->ungrab; |
52 | $self->destroy; |
57 | $self->destroy; |
53 | } |
58 | } |
54 | |
59 | |
|
|
60 | $self->{press}[$event->{button}] = 0; |
|
|
61 | |
55 | if ($event->{button} == 1) { |
62 | if ($event->{button} == 1) { |
56 | $self->{press}[$event->{button}] = 0; |
|
|
57 | refresh $self; |
63 | refresh $self; |
58 | |
64 | |
59 | warn "$event->{row} $event->{col}\n";#d# |
65 | warn "$event->{row} $event->{col}\n";#d# |
60 | |
66 | |
61 | if ($col >= 0 && $col < $self->ncol |
67 | if ($col >= 0 && $col < $self->ncol |
… | |
… | |
108 | sub on_start { |
114 | sub on_start { |
109 | my ($self) = @_; |
115 | my ($self) = @_; |
110 | |
116 | |
111 | # might fail, but try anyways |
117 | # might fail, but try anyways |
112 | $self->grab ($self->{data}{event}{time}, 1) |
118 | $self->grab ($self->{data}{event}{time}, 1) |
113 | and $self->allow_events_sync; |
119 | and $self->allow_events_async; |
114 | |
120 | |
115 | on_button_press $self, $self->{data}{event} if $self->{data}{event}{button}; |
121 | on_button_press $self, $self->{data}{event} if $self->{data}{event}{button}; |
116 | |
122 | |
117 | $self->cmd_parse ("\x1b[?25l\x1b[?7l"); |
123 | $self->cmd_parse ("\x1b[?25l\x1b[?7l"); |
118 | refresh $self; |
124 | refresh $self; |
… | |
… | |
123 | sub on_map_notify { |
129 | sub on_map_notify { |
124 | my ($self, $event) = @_; |
130 | my ($self, $event) = @_; |
125 | |
131 | |
126 | # should definitely not fail |
132 | # should definitely not fail |
127 | $self->grab ($self->{data}{event}{time}, 1) |
133 | $self->grab ($self->{data}{event}{time}, 1) |
128 | and $self->allow_events_sync; |
134 | and $self->allow_events_async; |
129 | } |
|
|
130 | |
|
|
131 | sub on_destroy { |
|
|
132 | } |
135 | } |
133 | |
136 | |
134 | |
137 | |
135 | |
138 | |
136 | |
139 | |
137 | |
140 | |
|
|
141 | |