--- rxvt-unicode/src/perl/tabbed 2006/01/20 14:02:41 1.5 +++ rxvt-unicode/src/perl/tabbed 2006/02/03 05:47:05 1.13 @@ -3,24 +3,44 @@ sub refresh { my ($self) = @_; - my $cmd = "\x1b[H\x1b[7m\x1b[K"; - my $txt; - my @ofs = (0); + my $ncol = $self->ncol; + + my $text = " " x $ncol; + my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; + + 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} }) { - if ($tab == $self->{cur}) { - $txt = " [$tab->{name}] "; - } else { - $txt = " $tab->{name} "; - } + $idx++; + + my $act = $tab->{activity} && $tab != $self->{cur} + ? "*" : " "; - $cmd .= $txt; - push @ofs, $ofs[-1] + length $txt; + 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 + if $tab == $self->{cur}; + + push @ofs, [ $ofs, $ofs + $len, sub { $_[0]->make_current ($tab) } ]; + + $ofs += $len + 1; } $self->{tabofs} = \@ofs; - $self->cmd_parse ($self->locale_encode ($cmd)); + $self->ROW_t (0, $text, 0, 0, $ncol); + $self->ROW_r (0, $rend, 0, 0, $ncol); + + $self->want_refresh; } sub new_tab { @@ -55,39 +75,58 @@ $tab->XMoveResizeWindow ( $tab->parent, + 0, $self->{tabheight} - 1, + $self->width, $self->height - $self->{tabheight} + ); + $tab->XMoveResizeWindow ( + $tab->parent, 0, $self->{tabheight}, $self->width, $self->height - $self->{tabheight} ); +} + +sub copy_properties { + my ($self) = @_; + my $tab = $self->{cur}; my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); + my %our_props = map +($_ => undef), $self->XListProperties ($self->parent); + for my $atom ($tab->XListProperties ($tab->parent)) { my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); + + delete $our_props{$atom}; if ($atom == $wm_normal_hints) { my (@hints) = unpack "l!*", $items; - $hints[ 4] += $self->{tabheight}; - $hints[16] += $self->{tabheight}; + $hints[$_] += $self->{tabheight} for (4, 6, 16); + + $items = pack "l!*", @hints; } $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); } + + $self->XDeleteProperty ($self->parent, $_) for keys %our_props; } sub make_current { 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; - + $self->copy_properties; + $tab->focus_in; $tab->XMapWindow ($tab->parent); - + delete $tab->{activity}; $self->refresh; () @@ -100,14 +139,11 @@ sub on_button_release { my ($self, $event) = @_; - my $ofs = $self->{tabofs}; - if ($event->{row} == 0) { - for my $i (0 .. @$ofs - 2) { - if ($event->{col} >= $ofs->[$i] - && $event->{col} < $ofs->[$i+1]) { - $self->make_current ($self->{tabs}[$i]); - } + for my $button (@{ $self->{tabofs} }) { + $button->[2]->($self, $event) + if $event->{col} >= $button->[0] + && $event->{col} < $button->[1]; } } @@ -142,9 +178,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; () @@ -154,6 +187,7 @@ my ($self, $event) = @_; $self->configure; + $self->refresh; () } @@ -169,9 +203,11 @@ sub tab_start { my ($self, $tab) = @_; + $tab->XChangeInput ($tab->parent, urxvt::PropertyChangeMask); + push @{ $self->{tabs} }, $tab; - $tab->{name} ||= scalar @{ $self->{tabs} }; +# $tab->{name} ||= scalar @{ $self->{tabs} }; $self->make_current ($tab); () @@ -186,6 +222,8 @@ if ($self->{cur} == $tab) { delete $self->{cur}; $self->make_current ($self->{tabs}[-1]); + } else { + $self->refresh; } } else { # delay destruction a tiny bit @@ -195,13 +233,51 @@ () } +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_property_notify { + my ($self, $tab, $event) = @_; + + $self->copy_properties + if $event->{window} == $tab->parent; + + () +} + +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 property_notify) { eval qq{ sub on_$hook { my \$parent = \$_[0]{term}{parent} @@ -213,5 +289,10 @@ } } +sub on_add_lines { + $_[0]->{activity}++ + or $_[0]{term}{parent}->tab_activity ($_[0]); + () +}