--- rxvt-unicode/src/perl/tabbed 2006/01/20 12:18:05 1.3 +++ rxvt-unicode/src/perl/tabbed 2006/01/20 15:24:24 1.6 @@ -3,24 +3,38 @@ sub refresh { my ($self) = @_; - my $cmd = "\x1b[H\x1b[7m\x1b[K"; + my $ncol = $self->ncol; + + my $text = " " x $ncol; + my $rend = [(urxvt::DEFAULT_RSTYLE | urxvt::RS_RVid) x $ncol]; + my $txt; - my @ofs = (0); + my $ofs = 0; + my @ofs; for my $tab (@{ $self->{tabs} }) { - if ($tab == $self->{cur}) { - $txt = " [$tab->{name}] "; - } else { - $txt = " $tab->{name} "; - } + my $txt = " $tab->{name} "; + my $len = length $txt; + + substr $text, $ofs, $len + 1, "$txt|"; + @$rend[$ofs .. $ofs + $len - 1] = (urxvt::OVERLAY_RSTYLE) x $len; + + push @ofs, [ + $ofs, + $ofs + $len, + sub { + my ($self, $event) = @_; + $self->make_current ($tab); + }, + ]; - $cmd .= $txt; - push @ofs, $ofs[-1] + length $txt; + $ofs += $len + 1; } $self->{tabofs} = \@ofs; - $self->cmd_parse ($self->locale_encode ($cmd)); + $self->ROW_t (0, $text); + $self->ROW_r (0, $rend); } sub new_tab { @@ -51,13 +65,30 @@ sub configure { my ($self) = @_; - my $tabheight = $self->int_bwidth + $self->fheight + $self->lineSpace; + my $tab = $self->{cur}; - $self->{cur}->XMoveResizeWindow ( - $self->{cur}->parent, - 0, $tabheight, - $self->width, $self->height - $tabheight + $tab->XMoveResizeWindow ( + $tab->parent, + 0, $self->{tabheight}, + $self->width, $self->height - $self->{tabheight} ); + + my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); + + for my $atom ($tab->XListProperties ($tab->parent)) { + my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); + + if ($atom == $wm_normal_hints) { + my (@hints) = unpack "l!*", $items; + + $hints[$_] += $self->{tabheight} for (4, 6, 16); + + $items = pack "l!*", @hints; + } + $self->XChangeWindowProperty ($self->parent, $atom, $type, $format, $items); + } + + $self->refresh; } sub make_current { @@ -72,10 +103,6 @@ $self->configure; - for my $atom ($tab->XListProperties ($tab->parent)) { - warn "$atom\n"; - } - $tab->XMapWindow ($tab->parent); $self->refresh; @@ -90,14 +117,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]; } } @@ -130,6 +154,8 @@ sub on_start { my ($self) = @_; + $self->{tabheight} = $self->int_bwidth + $self->fheight + $self->lineSpace; + $self->cmd_parse ("\x1b[?25l\x1b[?7l"); $self->new_tab; $self->new_tab;