--- rxvt-unicode/src/perl/tabbed 2006/01/20 15:24:24 1.6 +++ rxvt-unicode/src/perl/tabbed 2006/01/20 16:18:07 1.10 @@ -8,33 +8,39 @@ my $text = " " x $ncol; my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; - my $txt; - my $ofs = 0; my @ofs; + substr $text, 0, 7, "[NEW] |"; + @$rend[0 .. 5] = (urxvt::OVERLAY_RSTYLE) x 6; + push @ofs, [0, 6, sub { $_[0]->new_tab }]; + + my $ofs = 7; + my $idx = 0; + for my $tab (@{ $self->{tabs} }) { - my $txt = " $tab->{name} "; + $idx++; + + my $act = $tab->{activity} && $tab != $self->{cur} + ? "*" : " "; + + my $txt = "$act$idx$act"; my $len = length $txt; substr $text, $ofs, $len + 1, "$txt|"; - @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len; + @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len + if $tab == $self->{cur}; - push @ofs, [ - $ofs, - $ofs + $len, - sub { - my ($self, $event) = @_; - $self->make_current ($tab); - }, - ]; + push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; $ofs += $len + 1; } $self->{tabofs} = \@ofs; - $self->ROW_t (0, $text); - $self->ROW_r (0, $rend); + $self->ROW_t (0, $text, 0, 0, $ncol); + $self->ROW_r (0, $rend, 0, 0, $ncol); + + $self->want_refresh; } sub new_tab { @@ -95,16 +101,17 @@ my ($self, $tab) = @_; if (my $cur = $self->{cur}) { - $cur->XUnmapWindow ($cur->parent) - if $cur->mapped; + delete $cur->{activity}; + $cur->XUnmapWindow ($cur->parent) if $cur->mapped; + $cur->focus_out; } $self->{cur} = $tab; $self->configure; - + $tab->focus_in; $tab->XMapWindow ($tab->parent); - + delete $tab->{activity}; $self->refresh; () @@ -156,9 +163,6 @@ $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; - $self->cmd_parse ("\x1b[?25l\x1b[?7l"); - $self->new_tab; - $self->new_tab; $self->new_tab; () @@ -185,7 +189,7 @@ push @{ $self->{tabs} }, $tab; - $tab->{name} ||= scalar @{ $self->{tabs} }; +# $tab->{name} ||= scalar @{ $self->{tabs} }; $self->make_current ($tab); () @@ -200,6 +204,8 @@ if ($self->{cur} == $tab) { delete $self->{cur}; $self->make_current ($self->{tabs}[-1]); + } else { + $self->refresh; } } else { # delay destruction a tiny bit @@ -209,13 +215,42 @@ () } +sub tab_key_press { + my ($self, $tab, $event, $keysym, $str) = @_; + + if ($event->{state} & urxvt::ShiftMask) { + if ($keysym == 0xff51 || $keysym == 0xff53) { + my ($idx) = grep $self->{tabs}[$_] == $tab, 0 .. $#{ $self->{tabs} }; + + --$idx if $keysym == 0xff51; + ++$idx if $keysym == 0xff53; + + $self->make_current ($self->{tabs}[$idx % @{ $self->{tabs}}]); + + return 1; + } elsif ($keysym == 0xff54) { + $self->new_tab; + + return 1; + } + } + + () +} + +sub tab_activity { + my ($self, $tab) = @_; + + $self->refresh; +} + package urxvt::ext::tabbed::tab; # helper extension implementing the subwindows of a tabbed terminal. # simply proxies all interesting calls back to the tabbed class. { - for my $hook qw(start destroy) { + for my $hook qw(start destroy key_press) { eval qq{ sub on_$hook { my \$parent = \$_[0]{term}{parent} @@ -227,5 +262,10 @@ } } +sub on_add_lines { + $_[0]->{activity}++ + or $_[0]{term}{parent}->tab_activity ($_[0]); + () +}