… | |
… | |
6 | my $ncol = $self->ncol; |
6 | my $ncol = $self->ncol; |
7 | |
7 | |
8 | my $text = " " x $ncol; |
8 | my $text = " " x $ncol; |
9 | my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; |
9 | my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; |
10 | |
10 | |
11 | my $txt; |
|
|
12 | my $ofs = 0; |
|
|
13 | my @ofs; |
11 | my @ofs; |
14 | |
12 | |
|
|
13 | substr $text, 0, 7, "[NEW] |"; |
|
|
14 | @$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6; |
|
|
15 | push @ofs, [0, 6, sub { $_[0]->new_tab }]; |
|
|
16 | |
|
|
17 | my $ofs = 7; |
|
|
18 | my $idx = 0; |
|
|
19 | |
15 | for my $tab (@{ $self->{tabs} }) { |
20 | for my $tab (@{ $self->{tabs} }) { |
|
|
21 | $idx++; |
|
|
22 | |
16 | my $txt = " $tab->{name} "; |
23 | my $txt = " $idx "; |
17 | my $len = length $txt; |
24 | my $len = length $txt; |
18 | |
25 | |
19 | substr $text, $ofs, $len + 1, "$txt|"; |
26 | substr $text, $ofs, $len + 1, "$txt|"; |
20 | @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len; |
27 | @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len |
|
|
28 | if $tab == $self->{cur}; |
21 | |
29 | |
22 | push @ofs, [ |
30 | push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; |
23 | $ofs, |
|
|
24 | $ofs + $len, |
|
|
25 | sub { |
|
|
26 | my ($self, $event) = @_; |
|
|
27 | $self->make_current ($tab); |
|
|
28 | }, |
|
|
29 | ]; |
|
|
30 | |
31 | |
31 | $ofs += $len + 1; |
32 | $ofs += $len + 1; |
32 | } |
33 | } |
33 | |
34 | |
34 | $self->{tabofs} = \@ofs; |
35 | $self->{tabofs} = \@ofs; |
35 | |
36 | |
36 | $self->ROW_t (0, $text); |
37 | $self->ROW_t (0, $text, 0, 0, $ncol); |
37 | $self->ROW_r (0, $rend); |
38 | $self->ROW_r (0, $rend, 0, 0, $ncol); |
|
|
39 | |
|
|
40 | $self->want_refresh; |
38 | } |
41 | } |
39 | |
42 | |
40 | sub new_tab { |
43 | sub new_tab { |
41 | my ($self) = @_; |
44 | my ($self) = @_; |
42 | |
45 | |
… | |
… | |
93 | |
96 | |
94 | sub make_current { |
97 | sub make_current { |
95 | my ($self, $tab) = @_; |
98 | my ($self, $tab) = @_; |
96 | |
99 | |
97 | if (my $cur = $self->{cur}) { |
100 | if (my $cur = $self->{cur}) { |
98 | $cur->XUnmapWindow ($cur->parent) |
101 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
99 | if $cur->mapped; |
102 | $cur->focus_out; |
100 | } |
103 | } |
101 | |
104 | |
102 | $self->{cur} = $tab; |
105 | $self->{cur} = $tab; |
103 | |
106 | |
104 | $self->configure; |
107 | $self->configure; |
105 | |
108 | $tab->focus_in; |
106 | $tab->XMapWindow ($tab->parent); |
109 | $tab->XMapWindow ($tab->parent); |
107 | |
|
|
108 | $self->refresh; |
110 | $self->refresh; |
109 | |
111 | |
110 | () |
112 | () |
111 | } |
113 | } |
112 | |
114 | |
… | |
… | |
154 | sub on_start { |
156 | sub on_start { |
155 | my ($self) = @_; |
157 | my ($self) = @_; |
156 | |
158 | |
157 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
159 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
158 | |
160 | |
159 | $self->cmd_parse ("\x1b[?25l\x1b[?7l"); |
|
|
160 | $self->new_tab; |
|
|
161 | $self->new_tab; |
|
|
162 | $self->new_tab; |
161 | $self->new_tab; |
163 | |
162 | |
164 | () |
163 | () |
165 | } |
164 | } |
166 | |
165 | |
… | |
… | |
183 | sub tab_start { |
182 | sub tab_start { |
184 | my ($self, $tab) = @_; |
183 | my ($self, $tab) = @_; |
185 | |
184 | |
186 | push @{ $self->{tabs} }, $tab; |
185 | push @{ $self->{tabs} }, $tab; |
187 | |
186 | |
188 | $tab->{name} ||= scalar @{ $self->{tabs} }; |
187 | # $tab->{name} ||= scalar @{ $self->{tabs} }; |
189 | $self->make_current ($tab); |
188 | $self->make_current ($tab); |
190 | |
189 | |
191 | () |
190 | () |
192 | } |
191 | } |
193 | |
192 | |
… | |
… | |
198 | |
197 | |
199 | if (@{ $self->{tabs} }) { |
198 | if (@{ $self->{tabs} }) { |
200 | if ($self->{cur} == $tab) { |
199 | if ($self->{cur} == $tab) { |
201 | delete $self->{cur}; |
200 | delete $self->{cur}; |
202 | $self->make_current ($self->{tabs}[-1]); |
201 | $self->make_current ($self->{tabs}[-1]); |
|
|
202 | } else { |
|
|
203 | $self->refresh; |
203 | } |
204 | } |
204 | } else { |
205 | } else { |
205 | # delay destruction a tiny bit |
206 | # delay destruction a tiny bit |
206 | $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); |
207 | $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); |
207 | } |
208 | } |
208 | |
209 | |
209 | () |
210 | () |
210 | } |
211 | } |
211 | |
212 | |
|
|
213 | sub tab_key_press { |
|
|
214 | my ($self, $tab, $event, $keysym, $str) = @_; |
|
|
215 | |
|
|
216 | if ($event->{state} & urxvt::ShiftMask |
|
|
217 | && ($keysym == 0xff51 || $keysym == 0xff53)) { |
|
|
218 | my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; |
|
|
219 | |
|
|
220 | --$idx if $keysym == 0xff51; |
|
|
221 | ++$idx if $keysym == 0xff53; |
|
|
222 | |
|
|
223 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
|
|
224 | $self->refresh; |
|
|
225 | |
|
|
226 | return 1; |
|
|
227 | } |
|
|
228 | |
|
|
229 | () |
|
|
230 | } |
|
|
231 | |
212 | package urxvt::ext::tabbed::tab; |
232 | package urxvt::ext::tabbed::tab; |
213 | |
233 | |
214 | # helper extension implementing the subwindows of a tabbed terminal. |
234 | # helper extension implementing the subwindows of a tabbed terminal. |
215 | # simply proxies all interesting calls back to the tabbed class. |
235 | # simply proxies all interesting calls back to the tabbed class. |
216 | |
236 | |
217 | { |
237 | { |
218 | for my $hook qw(start destroy) { |
238 | for my $hook qw(start destroy key_press) { |
219 | eval qq{ |
239 | eval qq{ |
220 | sub on_$hook { |
240 | sub on_$hook { |
221 | my \$parent = \$_[0]{term}{parent} |
241 | my \$parent = \$_[0]{term}{parent} |
222 | or return; |
242 | or return; |
223 | \$parent->tab_$hook (\@_) |
243 | \$parent->tab_$hook (\@_) |