… | |
… | |
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} }) { |
16 | my $txt = " $tab->{name} "; |
21 | $idx++; |
|
|
22 | |
|
|
23 | my $act = $tab->{activity} && $tab != $self->{cur} |
|
|
24 | ? "*" : " "; |
|
|
25 | |
|
|
26 | my $txt = "$act$idx$act"; |
17 | my $len = length $txt; |
27 | my $len = length $txt; |
18 | |
28 | |
19 | substr $text, $ofs, $len + 1, "$txt|"; |
29 | substr $text, $ofs, $len + 1, "$txt|"; |
20 | @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len; |
30 | @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len |
|
|
31 | if $tab == $self->{cur}; |
21 | |
32 | |
22 | push @ofs, [ |
33 | 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 | |
34 | |
31 | $ofs += $len + 1; |
35 | $ofs += $len + 1; |
32 | } |
36 | } |
33 | |
37 | |
34 | $self->{tabofs} = \@ofs; |
38 | $self->{tabofs} = \@ofs; |
35 | |
39 | |
36 | $self->ROW_t (0, $text); |
40 | $self->ROW_t (0, $text, 0, 0, $ncol); |
37 | $self->ROW_r (0, $rend); |
41 | $self->ROW_r (0, $rend, 0, 0, $ncol); |
|
|
42 | |
|
|
43 | $self->want_refresh; |
38 | } |
44 | } |
39 | |
45 | |
40 | sub new_tab { |
46 | sub new_tab { |
41 | my ($self) = @_; |
47 | my ($self) = @_; |
42 | |
48 | |
… | |
… | |
65 | sub configure { |
71 | sub configure { |
66 | my ($self) = @_; |
72 | my ($self) = @_; |
67 | |
73 | |
68 | my $tab = $self->{cur}; |
74 | my $tab = $self->{cur}; |
69 | |
75 | |
|
|
76 | $tab->XMoveResizeWindow ( |
|
|
77 | $tab->parent, |
|
|
78 | 0, $self->{tabheight} - 1, |
|
|
79 | $self->width, $self->height - $self->{tabheight} |
|
|
80 | ); |
70 | $tab->XMoveResizeWindow ( |
81 | $tab->XMoveResizeWindow ( |
71 | $tab->parent, |
82 | $tab->parent, |
72 | 0, $self->{tabheight}, |
83 | 0, $self->{tabheight}, |
73 | $self->width, $self->height - $self->{tabheight} |
84 | $self->width, $self->height - $self->{tabheight} |
74 | ); |
85 | ); |
|
|
86 | } |
|
|
87 | |
|
|
88 | sub copy_properties { |
|
|
89 | my ($self) = @_; |
|
|
90 | my $tab = $self->{cur}; |
75 | |
91 | |
76 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
92 | my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); |
|
|
93 | |
|
|
94 | my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); |
77 | |
95 | |
78 | for my $atom ($tab->XListProperties ($tab->parent)) { |
96 | for my $atom ($tab->XListProperties ($tab->parent)) { |
79 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
97 | my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); |
|
|
98 | |
|
|
99 | delete $our_props{$atom}; |
80 | |
100 | |
81 | if ($atom == $wm_normal_hints) { |
101 | if ($atom == $wm_normal_hints) { |
82 | my (@hints) = unpack "l!*", $items; |
102 | my (@hints) = unpack "l!*", $items; |
83 | |
103 | |
84 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
104 | $hints[$_] += $self->{tabheight} for (4, 6, 16); |
… | |
… | |
86 | $items = pack "l!*", @hints; |
106 | $items = pack "l!*", @hints; |
87 | } |
107 | } |
88 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
108 | $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); |
89 | } |
109 | } |
90 | |
110 | |
91 | $self->refresh; |
111 | $self->XDeleteProperty ($self->parent, $_) for keys %our_props; |
92 | } |
112 | } |
93 | |
113 | |
94 | sub make_current { |
114 | sub make_current { |
95 | my ($self, $tab) = @_; |
115 | my ($self, $tab) = @_; |
96 | |
116 | |
97 | if (my $cur = $self->{cur}) { |
117 | if (my $cur = $self->{cur}) { |
|
|
118 | delete $cur->{activity}; |
98 | $cur->XUnmapWindow ($cur->parent) |
119 | $cur->XUnmapWindow ($cur->parent) if $cur->mapped; |
99 | if $cur->mapped; |
120 | $cur->focus_out; |
100 | } |
121 | } |
101 | |
122 | |
102 | $self->{cur} = $tab; |
123 | $self->{cur} = $tab; |
103 | |
124 | |
104 | $self->configure; |
125 | $self->configure; |
105 | |
126 | $self->copy_properties; |
|
|
127 | $tab->focus_in; |
106 | $tab->XMapWindow ($tab->parent); |
128 | $tab->XMapWindow ($tab->parent); |
107 | |
129 | delete $tab->{activity}; |
108 | $self->refresh; |
130 | $self->refresh; |
109 | |
131 | |
110 | () |
132 | () |
111 | } |
133 | } |
112 | |
134 | |
… | |
… | |
154 | sub on_start { |
176 | sub on_start { |
155 | my ($self) = @_; |
177 | my ($self) = @_; |
156 | |
178 | |
157 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
179 | $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; |
158 | |
180 | |
159 | $self->cmd_parse ("\x1b[?25l\x1b[?7l"); |
|
|
160 | $self->new_tab; |
|
|
161 | $self->new_tab; |
|
|
162 | $self->new_tab; |
181 | $self->new_tab; |
163 | |
182 | |
164 | () |
183 | () |
165 | } |
184 | } |
166 | |
185 | |
167 | sub on_configure_notify { |
186 | sub on_configure_notify { |
168 | my ($self, $event) = @_; |
187 | my ($self, $event) = @_; |
169 | |
188 | |
170 | $self->configure; |
189 | $self->configure; |
|
|
190 | $self->refresh; |
171 | |
191 | |
172 | () |
192 | () |
173 | } |
193 | } |
174 | |
194 | |
175 | sub on_wm_delete_window { |
195 | sub on_wm_delete_window { |
… | |
… | |
181 | } |
201 | } |
182 | |
202 | |
183 | sub tab_start { |
203 | sub tab_start { |
184 | my ($self, $tab) = @_; |
204 | my ($self, $tab) = @_; |
185 | |
205 | |
|
|
206 | $tab->XChangeInput ($tab->parent, urxvt::PropertyChangeMask); |
|
|
207 | |
186 | push @{ $self->{tabs} }, $tab; |
208 | push @{ $self->{tabs} }, $tab; |
187 | |
209 | |
188 | $tab->{name} ||= scalar @{ $self->{tabs} }; |
210 | # $tab->{name} ||= scalar @{ $self->{tabs} }; |
189 | $self->make_current ($tab); |
211 | $self->make_current ($tab); |
190 | |
212 | |
191 | () |
213 | () |
192 | } |
214 | } |
193 | |
215 | |
… | |
… | |
198 | |
220 | |
199 | if (@{ $self->{tabs} }) { |
221 | if (@{ $self->{tabs} }) { |
200 | if ($self->{cur} == $tab) { |
222 | if ($self->{cur} == $tab) { |
201 | delete $self->{cur}; |
223 | delete $self->{cur}; |
202 | $self->make_current ($self->{tabs}[-1]); |
224 | $self->make_current ($self->{tabs}[-1]); |
|
|
225 | } else { |
|
|
226 | $self->refresh; |
203 | } |
227 | } |
204 | } else { |
228 | } else { |
205 | # delay destruction a tiny bit |
229 | # delay destruction a tiny bit |
206 | $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); |
230 | $self->{destroy} = urxvt::iw->new->start->cb (sub { $self->destroy }); |
207 | } |
231 | } |
208 | |
232 | |
209 | () |
233 | () |
210 | } |
234 | } |
211 | |
235 | |
|
|
236 | sub tab_key_press { |
|
|
237 | my ($self, $tab, $event, $keysym, $str) = @_; |
|
|
238 | |
|
|
239 | if ($event->{state} & urxvt::ShiftMask) { |
|
|
240 | if ($keysym == 0xff51 || $keysym == 0xff53) { |
|
|
241 | my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; |
|
|
242 | |
|
|
243 | --$idx if $keysym == 0xff51; |
|
|
244 | ++$idx if $keysym == 0xff53; |
|
|
245 | |
|
|
246 | $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); |
|
|
247 | |
|
|
248 | return 1; |
|
|
249 | } elsif ($keysym == 0xff54) { |
|
|
250 | $self->new_tab; |
|
|
251 | |
|
|
252 | return 1; |
|
|
253 | } |
|
|
254 | } |
|
|
255 | |
|
|
256 | () |
|
|
257 | } |
|
|
258 | |
|
|
259 | sub tab_property_notify { |
|
|
260 | my ($self, $tab, $event) = @_; |
|
|
261 | |
|
|
262 | $self->copy_properties |
|
|
263 | if $event->{window} == $tab->parent; |
|
|
264 | |
|
|
265 | () |
|
|
266 | } |
|
|
267 | |
|
|
268 | sub tab_activity { |
|
|
269 | my ($self, $tab) = @_; |
|
|
270 | |
|
|
271 | $self->refresh; |
|
|
272 | } |
|
|
273 | |
212 | package urxvt::ext::tabbed::tab; |
274 | package urxvt::ext::tabbed::tab; |
213 | |
275 | |
214 | # helper extension implementing the subwindows of a tabbed terminal. |
276 | # helper extension implementing the subwindows of a tabbed terminal. |
215 | # simply proxies all interesting calls back to the tabbed class. |
277 | # simply proxies all interesting calls back to the tabbed class. |
216 | |
278 | |
217 | { |
279 | { |
218 | for my $hook qw(start destroy) { |
280 | for my $hook qw(start destroy key_press property_notify) { |
219 | eval qq{ |
281 | eval qq{ |
220 | sub on_$hook { |
282 | sub on_$hook { |
221 | my \$parent = \$_[0]{term}{parent} |
283 | my \$parent = \$_[0]{term}{parent} |
222 | or return; |
284 | or return; |
223 | \$parent->tab_$hook (\@_) |
285 | \$parent->tab_$hook (\@_) |
… | |
… | |
225 | }; |
287 | }; |
226 | die if $@; |
288 | die if $@; |
227 | } |
289 | } |
228 | } |
290 | } |
229 | |
291 | |
|
|
292 | sub on_add_lines { |
|
|
293 | $_[0]->{activity}++ |
|
|
294 | or $_[0]{term}{parent}->tab_activity ($_[0]); |
|
|
295 | () |
|
|
296 | } |
230 | |
297 | |
231 | |
298 | |