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